Skip to content

Unrestricted Open-source alternative to AI video platforms — Free AI image & video generation studio with 600+ models (Flux, Midjourney, Kling, Sora, Veo). No content filters. Self-hosted, MIT licensed.

feat(studio): expand generation model capabilities

antilya38b2d07e031b
diff --git a/packages/studio/src/components/ImageStudio.jsx b/packages/studio/src/components/ImageStudio.jsx
index a5ee2a08..0c8eeeaa 100644
--- a/packages/studio/src/components/ImageStudio.jsx
+++ b/packages/studio/src/components/ImageStudio.jsx
@@ -6,12 +6,12 @@ import { generateImage, generateI2I, uploadFile } from "../muapi.js";
import { formatErrorMessage } from "../utils/formatError.js";
import { scopedPersistKey, migrateLegacyPersistKey } from "../persistKey.js";
import DrawModal from "./DrawModal.jsx";
+import ModelParameterControls from "./ModelParameterControls.jsx";
import MobileGenerationActions, {
GenerationCopyButtons,
} from "./MobileGenerationActions.jsx";
import {
t2iModels,
- i2iModels,
getAspectRatiosForModel,
getResolutionsForModel,
getQualityFieldForModel,
@@ -24,10 +24,21 @@ import {
getI2IModelById,
} from "../models.js";
import {
+ getFamilyVariant,
+ getImageReferenceVariant,
imageModelCatalog,
imageModelPickerEntries,
imageModelPickerEntryByVariantId,
} from "../modelFamilies.js";
+import {
+ buildReferenceParams,
+ getModelMediaCapabilities,
+} from "../modelCapabilities.js";
+import {
+ buildSupplementalInputPayload,
+ createModelParameterValues,
+ getSupplementalModelInputs,
+} from "../modelParameters.js";
import {
PROMPT_CONTROL_LABEL_CLASS,
PROMPT_MEDIA_PREVIEW_CLASS,
@@ -73,6 +84,8 @@ function UploadButton({ apiKey, maxImages, onSelect, onClear, initialUrls = [],
const [uploading, setUploading] = useState(false);
const [selectedEntries, setSelectedEntries] = useState([]); // [{url, thumbnail}]
const [uploadHistory, setUploadHistory] = useState(persistedHistory || []); // [{id, name, url, thumbnail}]
+ const onSelectRef = useRef(onSelect);
+ onSelectRef.current = onSelect;
// Notify parent whenever uploadHistory changes (for localStorage persistence)
const onHistoryChangeRef = useRef(onHistoryChange);
@@ -117,24 +130,29 @@ function UploadButton({ apiKey, maxImages, onSelect, onClear, initialUrls = [],
// Sync initialUrls from parent (e.g. restored from localStorage)
useEffect(() => {
- if (initialUrls && initialUrls.length > 0) {
- // Avoid infinite loops by only updating if URLs actually changed
- const currentUrls = selectedEntries.map(e => e.url);
- const isSame = initialUrls.length === currentUrls.length && initialUrls.every(u => currentUrls.includes(u));
- if (isSame) return;
-
- const newEntries = initialUrls.map(url => ({ url }));
- setSelectedEntries(newEntries);
-
- // Also ensure they are in the history panel
- setUploadHistory(prev => {
- const existingUrls = prev.map(h => h.url);
- const missing = initialUrls
- .filter(u => !existingUrls.includes(u))
- .map(u => ({ id: `restored-${u}`, name: "Restored Image", url: u, progress: 100 }));
- return [...missing, ...prev];
- });
- }
+ const nextUrls = initialUrls || [];
+ const currentUrls = selectedEntries.map((entry) => entry.url);
+ const isSame =
+ nextUrls.length === currentUrls.length &&
+ nextUrls.every((url, index) => url === currentUrls[index]);
+ if (isSame) return;
+
+ setSelectedEntries(nextUrls.map((url) => ({ url })));
+ if (nextUrls.length === 0) return;
+
+ // Also ensure restored selections are available in the history panel.
+ setUploadHistory((history) => {
+ const existingUrls = new Set(history.map((entry) => entry.url));
+ const missing = nextUrls
+ .filter((url) => !existingUrls.has(url))
+ .map((url) => ({
+ id: `restored-${url}`,
+ name: "Restored Image",
+ url,
+ progress: 100,
+ }));
+ return missing.length > 0 ? [...missing, ...history] : history;
+ });
}, [initialUrls]); // eslint-disable-line react-hooks/exhaustive-deps
// When maxImages changes, trim excess selections
@@ -153,9 +171,9 @@ function UploadButton({ apiKey, maxImages, onSelect, onClear, initialUrls = [],
(entries) => {
if (!entries.length) return;
const urls = entries.map((e) => e.url);
- onSelect({ url: urls[0], urls, thumbnail: entries[0].url });
+ onSelectRef.current?.({ url: urls[0], urls, thumbnail: entries[0].url });
},
- [onSelect],
+ [],
);
const handleFileChange = async (e) => {
@@ -590,7 +608,6 @@ const invertLogos = ['openai', 'blackforest', 'runway', 'ideogram', 'lightricks'
function ModelDropdown({ selectedModel, onSelect, onClose }) {
const [search, setSearch] = useState("");
const selectedEntry = imageModelPickerEntryByVariantId.get(selectedModel);
- const selectedMode = imageModelCatalog.variantById.get(selectedModel)?.mode || "t2i";
const modelCategories = [
{
id: "all",
@@ -806,11 +823,7 @@ function ModelDropdown({ selectedModel, onSelect, onClose }) {
ref={isSelected ? activeItemRef : null}
onClick={(e) => {
e.stopPropagation();
- const variant = activeCategory.id === "all"
- ? entry.variantsByMode[selectedMode] || entry.defaultVariant
- : entry.variantsByMode[activeCategory.id];
- if (!variant) return;
- onSelect(variant.model, variant.mode);
+ onSelect(entry, activeCategory.id);
onClose();
}}
className={`flex items-center justify-between p-3 hover:bg-white/5 rounded-lg cursor-pointer transition-all border border-transparent hover:border-white/5 ${
@@ -918,12 +931,11 @@ export default function ImageStudio({
migrateLegacyPersistKey(LEGACY_PERSIST_KEY, PERSIST_KEY);
}, [PERSIST_KEY]);
- // ── Model / mode state ──────────────────────────────────────────────────
+ // ── Model state ─────────────────────────────────────────────────────────
+ const initialFamily = imageModelCatalog.familyByVariantId.get(t2iModels[0].id);
const [imageMode, setImageMode] = useState(false); // false=t2i, true=i2i
const [selectedModelId, setSelectedModelId] = useState(t2iModels[0].id);
- const [selectedModelName, setSelectedModelName] = useState(t2iModels[0].name);
- const selectedModelDisplayName =
- imageModelPickerEntryByVariantId.get(selectedModelId)?.name || selectedModelName;
+ const [selectedFamilyId, setSelectedFamilyId] = useState(initialFamily.id);
const [selectedAr, setSelectedAr] = useState(
t2iModels[0].inputs?.aspect_ratio?.default || "1:1",
);
@@ -932,7 +944,9 @@ export default function ImageStudio({
return resolutions[0] || null;
});
const [selectedEffect, setSelectedEffect] = useState("");
- const [maxImages, setMaxImages] = useState(1);
+ const [modelParameterValues, setModelParameterValues] = useState(() =>
+ createModelParameterValues(t2iModels[0]),
+ );
// ── Prompt / upload state ───────────────────────────────────────────────
const [prompt, setPrompt] = useState("");
@@ -973,6 +987,8 @@ export default function ImageStudio({
const textareaRef = useRef(null);
const dropdownRef = useRef(null);
const uploadPickerResetRef = useRef(null); // not used directly — managed via key
+ const selectionRef = useRef(null);
+ selectionRef.current = { imageMode, selectedFamilyId, selectedModelId };
// ── Close dropdown on outside click ─────────────────────────────────────
useEffect(() => {
@@ -993,12 +1009,23 @@ export default function ImageStudio({
if (stored) {
const data = JSON.parse(stored);
if (data.imageMode !== undefined) setImageMode(data.imageMode);
- if (data.selectedModelId) setSelectedModelId(data.selectedModelId);
- if (data.selectedModelName) setSelectedModelName(data.selectedModelName);
+ if (data.selectedModelId) {
+ const restoredFamily = imageModelCatalog.familyByVariantId.get(data.selectedModelId);
+ const restoredVariant = imageModelCatalog.variantById.get(data.selectedModelId);
+ if (restoredFamily) {
+ setSelectedModelId(data.selectedModelId);
+ setSelectedFamilyId(restoredFamily.id);
+ setModelParameterValues(
+ createModelParameterValues(
+ restoredVariant?.model,
+ data.modelParameterValues || {},
+ ),
+ );
+ }
+ }
if (data.selectedAr) setSelectedAr(data.selectedAr);
if (data.selectedQuality) setSelectedQuality(data.selectedQuality);
if (data.selectedEffect) setSelectedEffect(data.selectedEffect);
- if (data.maxImages) setMaxImages(data.maxImages);
if (data.prompt) setPrompt(data.prompt);
if (data.uploadedImageUrls) setUploadedImageUrls(data.uploadedImageUrls);
if (data.uploadHistory) setUploadHistory(data.uploadHistory);
@@ -1018,11 +1045,11 @@ export default function ImageStudio({
const state = {
imageMode,
selectedModelId,
- selectedModelName,
+ selectedFamilyId,
selectedAr,
selectedQuality,
selectedEffect,
- maxImages,
+ modelParameterValues,
prompt,
uploadedImageUrls,
uploadHistory,
@@ -1038,11 +1065,11 @@ export default function ImageStudio({
}, [
imageMode,
selectedModelId,
- selectedModelName,
+ selectedFamilyId,
selectedAr,
selectedQuality,
selectedEffect,
- maxImages,
+ modelParameterValues,
prompt,
uploadedImageUrls,
uploadHistory,
@@ -1060,10 +1087,25 @@ export default function ImageStudio({
return;
}
+ const family = imageModelCatalog.familyById.get(selectedFamilyId);
+ const editor = getFamilyVariant(
+ imageModelCatalog,
+ family,
+ "i2i",
+ selectedModelId,
+ );
+ if (!editor) {
+ toast.error(`${family.name} does not support image references.`);
+ return;
+ }
+
setGenerating(true); // Show as generating/busy
try {
+ const uploadLimit = getMaxImagesForI2IModel(editor.model.id);
const toUpload =
- maxImages === 1 ? files.slice(0, 1) : files.slice(0, maxImages);
+ uploadLimit === 1
+ ? files.slice(0, 1)
+ : files.slice(0, uploadLimit);
const urls = await Promise.all(
toUpload.map(async (file) => {
try {
@@ -1099,7 +1141,6 @@ export default function ImageStudio({
}, [droppedFiles, onFilesHandled, processDroppedImages]);
// ── Derived: current model lists & helpers ───────────────────────────────
- const currentModels = imageMode ? i2iModels : t2iModels;
const currentAspectRatios = imageMode
? getAspectRatiosForI2IModel(selectedModelId)
: getAspectRatiosForModel(selectedModelId);
@@ -1112,138 +1153,119 @@ export default function ImageStudio({
const showQualityBtn = currentResolutions.length > 0;
const currentEffects = imageMode ? getEffectsForI2IModel(selectedModelId) : [];
const showEffectBtn = currentEffects.length > 0;
+ const selectedFamily = imageModelCatalog.familyById.get(selectedFamilyId) || initialFamily;
+ const selectedPickerEntry = imageModelPickerEntryByVariantId.get(selectedModelId);
+ const selectedModelDisplayName = selectedPickerEntry?.name || selectedFamily.name;
+ const currentMode = imageMode ? "i2i" : "t2i";
+ const selectedVariant = imageModelCatalog.variantById.get(selectedModelId);
+ const supplementalInputs = getSupplementalModelInputs(selectedVariant?.model);
+ const referenceVariant = getImageReferenceVariant(
+ imageModelCatalog,
+ selectedFamily,
+ selectedModelId,
+ );
+ const referenceImageLimit = referenceVariant
+ ? getModelMediaCapabilities(referenceVariant.model).image.maxItems
+ : 1;
+
+ const applySelectedVariant = useCallback((variant, mode, family) => {
+ const model = variant.model;
+ const nextImageMode = mode === "i2i";
+ const ars = nextImageMode
+ ? getAspectRatiosForI2IModel(model.id)
+ : getAspectRatiosForModel(model.id);
+ const resolutions = nextImageMode
+ ? getResolutionsForI2IModel(model.id)
+ : getResolutionsForModel(model.id);
+
+ selectionRef.current = {
+ imageMode: nextImageMode,
+ selectedFamilyId: family.id,
+ selectedModelId: model.id,
+ };
+ setImageMode(nextImageMode);
+ setSelectedFamilyId(family.id);
+ setSelectedModelId(model.id);
+ setModelParameterValues((values) =>
+ createModelParameterValues(model, values),
+ );
+ setSelectedAr(ars[0] || "1:1");
+ setSelectedQuality(resolutions[0] || null);
+
+ if (nextImageMode) {
+ const effects = getEffectsForI2IModel(model.id);
+ setSelectedEffect(
+ effects.length > 0
+ ? (getDefaultEffectForI2IModel(model.id) || effects[0])
+ : "",
+ );
+ } else {
+ setSelectedEffect("");
+ }
+ }, []);
+
+ const applyUserSelectedVariant = useCallback((variant, mode, family) => {
+ if (mode === "t2i") {
+ setUploadedImageUrls([]);
+ } else {
+ const maxImages = getMaxImagesForI2IModel(variant.model.id);
+ setUploadedImageUrls((urls) => urls.slice(0, maxImages));
+ }
+ setSwapImageUrl(null);
+ applySelectedVariant(variant, mode, family);
+ }, [applySelectedVariant]);
// ── Textarea auto-resize ─────────────────────────────────────────────────
// ── Upload picker callbacks ──────────────────────────────────────────────
const handleUploadSelect = useCallback(
({ url, urls }) => {
const newUrls = urls || [url];
- setUploadedImageUrls(newUrls);
-
- if (!imageMode) {
- // Find the i2i sibling of the currently selected t2i model.
- // Many models follow conventions, but some have completely irregular names —
- // those are handled via a hardcoded exceptions map.
- const curId = selectedModelId;
- const i2iIds = new Set(i2iModels.map((m) => m.id));
-
- // Hardcoded exceptions for models with irregular t2i → i2i naming
- const EXCEPTIONS = {
- 'reve-text-to-image': 'reve-image-edit',
- 'wan2.1-text-to-image': 'wan2.5-image-edit', // no wan2.1 i2i — closest
- 'wan2.5-text-to-image': 'wan2.5-image-edit',
- 'wan2.6-text-to-image': 'wan2.6-image-edit',
- 'kling-o1-text-to-image': 'kling-o1-edit-image',
- 'vidu-q2-text-to-image': 'vidu-q2-reference-to-image',
- 'bytedance-seedream-v3': 'bytedance-seededit-v3',
- 'bytedance-seedream-v4': 'bytedance-seedream-edit-v4',
- 'ideogram-v3-t2i': 'ideogram-v3-reframe',
- };
+ const selection = selectionRef.current;
+ const family = imageModelCatalog.familyById.get(selection.selectedFamilyId);
+ const target = getImageReferenceVariant(
+ imageModelCatalog,
+ family,
+ selection.selectedModelId,
+ );
+ if (!target) {
+ toast.error(`${family.name} does not support image references.`);
+ return;
+ }
- const findI2I = (id) => i2iModels.find((m) => m.id === id) ?? null;
-
- const target =
- // 0. Hardcoded exceptions for irregular names
- findI2I(EXCEPTIONS[curId]) ||
- // 1. Model exists directly in i2i list (e.g. qwen-text-to-image-2512, flux-pulid, flux-redux)
- findI2I(curId) ||
- // 2. {id}-edit suffix (e.g. nano-banana → nano-banana-edit, gpt-image-1.5 → gpt-image-1.5-edit)
- findI2I(`${curId}-edit`) ||
- // 3. -t2i → -i2i (e.g. flux-kontext-dev-t2i → flux-kontext-dev-i2i)
- (curId.includes('-t2i') && findI2I(curId.replace('-t2i', '-i2i'))) ||
- // 4. text-to-image → image-to-image (e.g. gpt4o-text-to-image, midjourney-v7, grok-imagine)
- (curId.includes('text-to-image') && findI2I(curId.replace('text-to-image', 'image-to-image'))) ||
- // 5. Prefix match fallback (e.g. minimax-image-01 → minimax-image-01-subject-reference)
- i2iModels.find((m) => m.id.startsWith(curId)) ||
- // 6. No sibling exists — use first i2i model
- i2iModels[0];
-
- const ars = getAspectRatiosForI2IModel(target.id);
- const resolutions = getResolutionsForI2IModel(target.id);
- const effects = getEffectsForI2IModel(target.id);
- setImageMode(true);
- setSelectedModelId(target.id);
- setSelectedModelName(target.name);
- setSelectedAr(ars[0] || "1:1");
- setSelectedQuality(resolutions[0] || null);
- setSelectedEffect(effects.length > 0 ? (getDefaultEffectForI2IModel(target.id) || effects[0]) : "");
- setMaxImages(getMaxImagesForI2IModel(target.id));
+ const limit = getModelMediaCapabilities(target.model).image.maxItems;
+ setUploadedImageUrls(newUrls.slice(0, limit));
+ const currentMode = selection.imageMode ? "i2i" : "t2i";
+ if (target.model.id !== selection.selectedModelId || target.mode !== currentMode) {
+ applySelectedVariant(target, target.mode, family);
}
},
- [imageMode, selectedModelId],
+ [applySelectedVariant],
);
const handleUploadClear = useCallback(() => {
setUploadedImageUrls([]);
- setImageMode(false);
-
- // Find the t2i parent of the currently selected i2i model (reverse of upload logic)
- const curId = selectedModelId;
- const findT2I = (id) => id ? (t2iModels.find((m) => m.id === id) ?? null) : null;
-
- // Reverse exceptions map (i2i → t2i for irregular names)
- const REVERSE_EXCEPTIONS = {
- 'reve-image-edit': 'reve-text-to-image',
- 'wan2.5-image-edit': 'wan2.5-text-to-image',
- 'wan2.6-image-edit': 'wan2.6-text-to-image',
- 'kling-o1-edit-image': 'kling-o1-text-to-image',
- 'vidu-q2-reference-to-image': 'vidu-q2-text-to-image',
- 'bytedance-seededit-v3': 'bytedance-seedream-v3',
- 'bytedance-seedream-edit-v4': 'bytedance-seedream-v4',
- 'ideogram-v3-reframe': 'ideogram-v3-t2i',
- };
-
- const target =
- // 0. Hardcoded reverse exceptions
- findT2I(REVERSE_EXCEPTIONS[curId]) ||
- // 1. Model exists directly in t2i list (e.g. qwen-text-to-image-2512, flux-pulid, flux-redux)
- findT2I(curId) ||
- // 2. Strip -edit suffix (e.g. nano-banana-edit → nano-banana, gpt-image-1.5-edit → gpt-image-1.5)
- (curId.endsWith('-edit') && findT2I(curId.slice(0, -5))) ||
- // 3. -i2i → -t2i (e.g. flux-kontext-dev-i2i → flux-kontext-dev-t2i)
- (curId.includes('-i2i') && findT2I(curId.replace('-i2i', '-t2i'))) ||
- // 4. image-to-image → text-to-image (e.g. gpt4o-image-to-image → gpt4o-text-to-image)
- (curId.includes('image-to-image') && findT2I(curId.replace('image-to-image', 'text-to-image'))) ||
- // 5. No parent found — use first t2i model
- t2iModels[0];
-
- const ars = getAspectRatiosForModel(target.id);
- const resolutions = getResolutionsForModel(target.id);
- setSelectedModelId(target.id);
- setSelectedModelName(target.name);
- setSelectedAr(ars[0] || "1:1");
- setSelectedQuality(resolutions[0] || null);
- setSelectedEffect("");
- setMaxImages(1);
- }, [selectedModelId]);
+ const selection = selectionRef.current;
+ const family = imageModelCatalog.familyById.get(selection.selectedFamilyId);
+ const target = getFamilyVariant(
+ imageModelCatalog,
+ family,
+ "t2i",
+ selection.selectedModelId,
+ );
+ if (target) applySelectedVariant(target, "t2i", family);
+ }, [applySelectedVariant]);
// ── Model selection ──────────────────────────────────────────────────────
- const handleModelSelect = (m, category = imageMode ? "i2i" : "t2i") => {
- const nextImageMode = category === "i2i";
- const ars = nextImageMode
- ? getAspectRatiosForI2IModel(m.id)
- : getAspectRatiosForModel(m.id);
- const resolutions = nextImageMode
- ? getResolutionsForI2IModel(m.id)
- : getResolutionsForModel(m.id);
- if (!nextImageMode && imageMode) {
- setUploadedImageUrls([]);
- setSwapImageUrl(null);
- }
- setImageMode(nextImageMode);
- setSelectedModelId(m.id);
- setSelectedModelName(m.name);
- setSelectedAr(ars[0] || "1:1");
- setSelectedQuality(resolutions[0] || null);
- setSwapImageUrl(null);
- if (nextImageMode) {
- setMaxImages(getMaxImagesForI2IModel(m.id));
- const effects = getEffectsForI2IModel(m.id);
- setSelectedEffect(effects.length > 0 ? (getDefaultEffectForI2IModel(m.id) || effects[0]) : "");
- } else {
- setMaxImages(1);
- setSelectedEffect("");
- }
+ const handleModelSelect = (pickerEntry, category = "all") => {
+ const { family, variantsByMode, defaultVariant } = pickerEntry;
+ const target = category !== "all"
+ ? variantsByMode[category]
+ : uploadedImageUrls.length > 0 && variantsByMode.i2i
+ ? variantsByMode.i2i
+ : variantsByMode[currentMode] || defaultVariant;
+ if (!target) return;
+
+ applyUserSelectedVariant(target, target.mode, family);
};
// ── History helpers ──────────────────────────────────────────────────────
@@ -1268,12 +1290,13 @@ export default function ImageStudio({
const firstT2I = t2iModels[0];
const ars = getAspectRatiosForModel(firstT2I.id);
const resolutions = getResolutionsForModel(firstT2I.id);
+ const family = imageModelCatalog.familyByVariantId.get(firstT2I.id);
setSelectedModelId(firstT2I.id);
- setSelectedModelName(firstT2I.name);
+ setSelectedFamilyId(family.id);
setSelectedAr(ars[0] || "1:1");
setSelectedQuality(resolutions[0] || null);
setSelectedEffect("");
- setMaxImages(1);
+ setModelParameterValues(createModelParameterValues(firstT2I));
};
// ── Generation ───────────────────────────────────────────────────────────
@@ -1291,6 +1314,11 @@ export default function ImageStudio({
return;
}
} else {
+ const imageCapability = getModelMediaCapabilities(selectedVariant?.model).image;
+ if (uploadedImageUrls.length > 0 && imageCapability.maxItems === 0) {
+ alert(`${selectedModelDisplayName} does not support image references.`);
+ return;
+ }
if (!prompt.trim()) {
alert("Please enter a prompt to generate an image.");
return;
@@ -1307,6 +1335,10 @@ export default function ImageStudio({
if (imageMode) {
const genParams = {
model: selectedModelId,
+ ...buildSupplementalInputPayload(
+ selectedVariant?.model,
+ modelParameterValues,
+ ),
images_list: uploadedImageUrls,
image_url: uploadedImageUrls[0],
aspect_ratio: selectedAr,
@@ -1319,8 +1351,16 @@ export default function ImageStudio({
if (showEffectBtn && selectedEffect) genParams.name = selectedEffect;
return await generateI2I(apiKey, genParams);
} else {
+ const referenceParams = buildReferenceParams(selectedVariant?.model, {
+ imageUrls: uploadedImageUrls,
+ });
const genParams = {
model: selectedModelId,
+ ...buildSupplementalInputPayload(
+ selectedVariant?.model,
+ modelParameterValues,
+ ),
+ ...referenceParams,
prompt: prompt.trim(),
aspect_ratio: selectedAr,
};
@@ -1544,10 +1584,10 @@ export default function ImageStudio({
))}
{/* Main Upload Trigger */}
- {uploadedImageUrls.length < maxImages && (
+ {referenceVariant && uploadedImageUrls.length < referenceImageLimit && (
<UploadButton
apiKey={apiKey}
- maxImages={maxImages}
+ maxImages={referenceImageLimit}
onSelect={handleUploadSelect}
onClear={handleUploadClear}
initialUrls={uploadedImageUrls}
@@ -1596,8 +1636,7 @@ export default function ImageStudio({
>
<div className="w-4 h-4 rounded overflow-hidden shrink-0 flex items-center justify-center bg-white/5">
{(() => {
- const selectedModelObj = currentModels.find(m => m.id === selectedModelId);
- const selectedModelProvider = selectedModelObj?.provider || 'muapi';
+ const selectedModelProvider = selectedFamily.provider || 'muapi';
return PROVIDER_LOGOS[selectedModelProvider] ? (
<img
src={PROVIDER_LOGOS[selectedModelProvider]}
@@ -1630,6 +1669,21 @@ export default function ImageStudio({
)}
</div>
+ <ModelParameterControls
+ inputs={supplementalInputs}
+ values={modelParameterValues}
+ onChange={(key, value) =>
+ setModelParameterValues((values) => ({ ...values, [key]: value }))
+ }
+ open={dropdownOpen === "parameters"}
+ onToggle={(event) => {
+ event.stopPropagation();
+ setDropdownOpen((open) =>
+ open === "parameters" ? null : "parameters",
+ );
+ }}
+ />
+
{/* Aspect ratio button */}
<div className="relative">
<button
diff --git a/packages/studio/src/components/ModelParameterControls.jsx b/packages/studio/src/components/ModelParameterControls.jsx
new file mode 100644
index 00000000..5637be11
--- /dev/null
+++ b/packages/studio/src/components/ModelParameterControls.jsx
@@ -0,0 +1,233 @@
+"use client";
+
+import {
+ PROMPT_CONTROL_LABEL_CLASS,
+ PromptChevronIcon,
+ PromptPopover,
+ PromptPopoverHeader,
+ promptControlClassName,
+} from "./prompt/PromptComposer.jsx";
+
+const FIELD_CLASS =
+ "w-full rounded-lg border border-white/10 bg-white/[0.04] px-3 py-2 text-xs text-white outline-none transition-colors focus:border-[#22d3ee]/50";
+
+function createEmptyValue(schema = {}) {
+ if (schema.default !== undefined) return schema.default;
+ if (schema.type === "boolean") return false;
+ if (schema.type === "array") return [];
+ if (schema.type === "object") {
+ return Object.fromEntries(
+ Object.entries(schema.properties || {}).map(([key, property]) => [
+ key,
+ createEmptyValue(property),
+ ]),
+ );
+ }
+ if (["number", "integer", "int"].includes(schema.type)) return 0;
+ return "";
+}
+
+function FieldLabel({ schema, inputKey }) {
+ return (
+ <div className="min-w-0">
+ <div className="text-xs font-semibold text-white/75">
+ {schema.title || inputKey.replaceAll("_", " ")}
+ </div>
+ {schema.description && (
+ <div className="mt-0.5 text-[10px] leading-relaxed text-white/35">
+ {schema.description}
+ </div>
+ )}
+ </div>
+ );
+}
+
+function ScalarInput({ schema, value, onChange, label }) {
+ if (schema.enum) {
+ return (
+ <select
+ className={FIELD_CLASS}
+ aria-label={label}
+ value={value ?? ""}
+ onChange={(event) => {
+ const selected = schema.enum.find(
+ (option) => String(option) === event.target.value,
+ );
+ onChange(selected);
+ }}
+ >
+ {schema.enum.map((option) => (
+ <option key={String(option)} value={String(option)}>
+ {String(option)}
+ </option>
+ ))}
+ </select>
+ );
+ }
+
+ if (schema.type === "boolean") {
+ return (
+ <button
+ type="button"
+ role="switch"
+ aria-label={label}
+ aria-checked={!!value}
+ onClick={() => onChange(!value)}
+ className={`relative h-6 w-11 shrink-0 rounded-full border transition-colors ${
+ value
+ ? "border-[#22d3ee]/50 bg-[#22d3ee]/30"
+ : "border-white/10 bg-white/[0.06]"
+ }`}
+ >
+ <span
+ className={`absolute left-0.5 top-0.5 h-4 w-4 rounded-full bg-white transition-transform ${
+ value ? "translate-x-5" : "translate-x-0"
+ }`}
+ />
+ </button>
+ );
+ }
+
+ const numeric = ["number", "integer", "int"].includes(schema.type);
+ return (
+ <input
+ className={FIELD_CLASS}
+ aria-label={label}
+ type={numeric ? "number" : "text"}
+ value={value ?? ""}
+ min={schema.minValue ?? schema.minimum}
+ max={schema.maxValue ?? schema.maximum}
+ step={schema.step || (schema.type === "number" ? "any" : 1)}
+ placeholder={schema.examples?.[0] && typeof schema.examples[0] !== "object"
+ ? String(schema.examples[0])
+ : undefined}
+ onChange={(event) => onChange(event.target.value)}
+ />
+ );
+}
+
+function ArrayInput({ schema, value, onChange, label }) {
+ const items = Array.isArray(value) ? value : [];
+ const itemSchema = schema.items || { type: "string" };
+ const maxItems = schema.maxItems ?? schema.max_items ?? Infinity;
+
+ const updateItem = (index, nextValue) => {
+ onChange(items.map((item, itemIndex) => (itemIndex === index ? nextValue : item)));
+ };
+
+ const removeItem = (index) => {
+ onChange(items.filter((_, itemIndex) => itemIndex !== index));
+ };
+
+ return (
+ <div className="flex flex-col gap-2">
+ {items.map((item, index) => (
+ <div
+ key={index}
+ className="rounded-lg border border-white/[0.07] bg-black/20 p-2.5"
+ >
+ {itemSchema.type === "object" ? (
+ <div className="flex flex-col gap-2">
+ {Object.entries(itemSchema.properties || {}).map(([key, property]) => (
+ <label key={key} className="flex flex-col gap-1">
+ <span className="text-[10px] font-semibold text-white/45">
+ {property.title || key.replaceAll("_", " ")}
+ </span>
+ <ScalarInput
+ schema={property}
+ label={property.title || key.replaceAll("_", " ")}
+ value={item?.[key] ?? createEmptyValue(property)}
+ onChange={(nextValue) =>
+ updateItem(index, { ...item, [key]: nextValue })
+ }
+ />
+ </label>
+ ))}
+ </div>
+ ) : (
+ <ScalarInput
+ schema={itemSchema}
+ label={`${label} ${index + 1}`}
+ value={item}
+ onChange={(nextValue) => updateItem(index, nextValue)}
+ />
+ )}
+ <button
+ type="button"
+ onClick={() => removeItem(index)}
+ aria-label={`Remove ${label} ${index + 1}`}
+ className="mt-2 text-[10px] font-semibold text-red-300/70 hover:text-red-300"
+ >
+ Remove
+ </button>
+ </div>
+ ))}
+ {items.length < maxItems && (
+ <button
+ type="button"
+ onClick={() => onChange([...items, createEmptyValue(itemSchema)])}
+ aria-label={`Add ${label}`}
+ className="rounded-lg border border-dashed border-white/10 px-3 py-2 text-xs font-semibold text-white/45 hover:border-[#22d3ee]/30 hover:text-[#22d3ee]"
+ >
+ + Add
+ </button>
+ )}
+ </div>
+ );
+}
+
+export default function ModelParameterControls({
+ inputs,
+ values,
+ onChange,
+ open,
+ onToggle,
+}) {
+ if (inputs.length === 0) return null;
+
+ return (
+ <div className="relative">
+ <button
+ type="button"
+ onClick={onToggle}
+ className={promptControlClassName({ active: open })}
+ >
+ <span className="text-[10px] font-black text-primary/80">PARAMS</span>
+ <span className={PROMPT_CONTROL_LABEL_CLASS}>{inputs.length}</span>
+ <PromptChevronIcon />
+ </button>
+ {open && (
+ <PromptPopover
+ onClick={(event) => event.stopPropagation()}
+ className="w-[min(420px,calc(100vw-2rem))] max-h-[60vh]"
+ >
+ <PromptPopoverHeader>Model parameters</PromptPopoverHeader>
+ <div className="flex flex-col gap-4">
+ {inputs.map(({ key, schema }) => (
+ <div key={key} className="flex flex-col gap-2">
+ <div className={schema.type === "boolean" ? "flex items-center justify-between gap-4" : "flex flex-col gap-2"}>
+ <FieldLabel schema={schema} inputKey={key} />
+ {schema.type === "array" ? (
+ <ArrayInput
+ schema={schema}
+ label={schema.title || key.replaceAll("_", " ")}
+ value={values[key]}
+ onChange={(nextValue) => onChange(key, nextValue)}
+ />
+ ) : (
+ <ScalarInput
+ schema={schema}
+ label={schema.title || key.replaceAll("_", " ")}
+ value={values[key]}
+ onChange={(nextValue) => onChange(key, nextValue)}
+ />
+ )}
+ </div>
+ </div>
+ ))}
+ </div>
+ </PromptPopover>
+ )}
+ </div>
+ );
+}
diff --git a/packages/studio/src/components/VideoStudio.jsx b/packages/studio/src/components/VideoStudio.jsx
index 54615783..c9f9e428 100644
--- a/packages/studio/src/components/VideoStudio.jsx
+++ b/packages/studio/src/components/VideoStudio.jsx
@@ -1,18 +1,17 @@
"use client";
-import { useState, useEffect, useRef, useCallback } from "react";
+import { useState, useEffect, useRef, useCallback, useMemo, useId } from "react";
import toast, { Toaster } from "react-hot-toast";
import { generateVideo, generateI2V, processV2V, uploadFile } from "../muapi.js";
import { formatErrorMessage } from "../utils/formatError.js";
import { scopedPersistKey, migrateLegacyPersistKey } from "../persistKey.js";
import DrawModal from "./DrawModal.jsx";
+import ModelParameterControls from "./ModelParameterControls.jsx";
import MobileGenerationActions, {
GenerationCopyButtons,
} from "./MobileGenerationActions.jsx";
import {
t2vModels,
- i2vModels,
- v2vModels,
getAspectRatiosForVideoModel,
getDurationsForModel,
getResolutionsForVideoModel,
@@ -21,14 +20,43 @@ import {
getResolutionsForI2VModel,
getEffectsForI2VModel,
getDefaultEffectForI2VModel,
- getModesForModel,
- getMaxImagesForI2VModel,
} from "../models.js";
import {
+ getFamilyVariant,
videoModelCatalog,
videoModelPickerEntries,
videoModelPickerEntryByVariantId,
} from "../modelFamilies.js";
+import {
+ buildReferenceParams,
+ getModelMediaCapabilities,
+ recordGenerationSource,
+ shouldDisableVideoPrompt,
+} from "../modelCapabilities.js";
+import {
+ buildSupplementalInputPayload,
+ createModelParameterValues,
+ getSupplementalModelInputs,
+} from "../modelParameters.js";
+import {
+ appendVideoWorkflowMedia,
+ buildVideoWorkflowMediaParams,
+ getVideoWorkflowControlLabel,
+ getVideoWorkflowControlState,
+ getVideoWorkflowDraftKey,
+ getVideoWorkflowFamily,
+ getVideoWorkflowMediaConfig,
+ getVideoWorkflowMediaSlots,
+ getVideoWorkflowSlotRemaining,
+ inferVideoWorkflowId,
+ legacyVideoMediaToWorkflowDraft,
+ projectVideoWorkflowMedia,
+ removeVideoWorkflowMedia,
+ resolvePersistedVideoWorkflowSelection,
+ resolveVideoBaseVariant,
+ resolveVideoWorkflowVariant,
+ validateVideoWorkflowMedia,
+} from "../videoWorkflows.js";
import {
PROMPT_CONTROL_LABEL_CLASS,
PROMPT_MEDIA_PREVIEW_CLASS,
@@ -49,13 +77,6 @@ import {
promptMediaButtonClassName,
} from "./prompt/PromptComposer.jsx";
-// ── tiny helpers ──────────────────────────────────────────────────────────────
-
-function getQualitiesForModel(modelList, modelId) {
- const model = modelList.find((m) => m.id === modelId);
- return model?.inputs?.quality?.enum || [];
-}
-
async function downloadFile(url, filename) {
try {
const response = await fetch(url);
@@ -73,6 +94,177 @@ async function downloadFile(url, filename) {
}
}
+function mergeReferenceUrls(current, incoming, limit) {
+ return [...new Set([...current, ...incoming])].slice(0, limit);
+}
+
+const EMPTY_WORKFLOW_MEDIA_DRAFT = Object.freeze({});
+
+function workflowContextKey(familyId, workflowId) {
+ return `${familyId}:${workflowId || "base"}`;
+}
+
+function isSameSelection(left, right) {
+ return (
+ left?.selectedFamilyId === right?.selectedFamilyId &&
+ left?.selectedModel === right?.selectedModel &&
+ left?.selectedWorkflowId === right?.selectedWorkflowId
+ );
+}
+
+function ReferenceMediaLabel({ label, required = false }) {
+ if (!label) return null;
+ return (
+ <span
+ className={`flex min-h-6 max-w-[88px] items-start justify-center text-balance text-center text-[10px] font-semibold leading-3 ${
+ required ? "text-white/60" : "text-white/45"
+ }`}
+ >
+ {label}
+ {required && (
+ <span className="ml-0.5 text-[#22d3ee]" aria-hidden="true">
+ *
+ </span>
+ )}
+ </span>
+ );
+}
+
+function ReferencePreview({
+ type,
+ url,
+ index,
+ onRemove,
+ label = null,
+ description = null,
+}) {
+ const mediaLabel = label || (type === "image" ? "image" : type === "video" ? "video" : "audio");
+ const actionLabel = description || mediaLabel;
+ return (
+ <div className="flex min-w-[60px] flex-col items-center gap-1.5">
+ <div className={PROMPT_MEDIA_PREVIEW_CLASS}>
+ {type === "image" ? (
+ <img src={url} alt="" className="w-full h-full object-cover" />
+ ) : type === "video" ? (
+ <video src={url} className="w-full h-full object-cover" muted />
+ ) : (
+ <div className="w-full h-full flex items-center justify-center bg-white/5 text-primary">
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5">
+ <path d="M9 18V5l10-2v13" />
+ <circle cx="6" cy="18" r="3" />
+ <circle cx="16" cy="16" r="3" />
+ </svg>
+ </div>
+ )}
+ <button
+ type="button"
+ aria-label={`Remove ${actionLabel.toLowerCase()}`}
+ title={`Remove ${actionLabel.toLowerCase()}`}
+ onClick={() => onRemove(index)}
+ className="absolute top-0.5 right-0.5 w-4 h-4 bg-black/60 hover:bg-black rounded-full flex items-center justify-center text-white/85 hover:text-white text-[8px] border border-white/5"
+ >
+ ×
+ </button>
+ </div>
+ <ReferenceMediaLabel label={mediaLabel} />
+ </div>
+ );
+}
+
+function ReferenceUploadButton({
+ inputRef,
+ accept,
+ multiple,
+ onChange,
+ onClick,
+ title,
+ uploading,
+ progress,
+ type,
+ label = null,
+ required = false,
+ disabled = false,
+}) {
+ const localInputRef = useRef(null);
+ const resolvedInputRef = inputRef || localInputRef;
+ const announcedProgress = Math.min(
+ 100,
+ Math.max(0, Math.floor(progress / 10) * 10),
+ );
+ return (
+ <div
+ className={
+ label
+ ? "relative flex min-w-[60px] flex-col items-center gap-1.5"
+ : "relative"
+ }
+ >
+ <input
+ ref={resolvedInputRef}
+ type="file"
+ accept={accept}
+ multiple={multiple}
+ className="hidden"
+ onChange={onChange}
+ />
+ <button
+ type="button"
+ title={title}
+ aria-label={title}
+ aria-busy={uploading || undefined}
+ disabled={disabled}
+ onClick={onClick || (() => resolvedInputRef.current?.click())}
+ className={`${promptMediaButtonClassName()} disabled:cursor-not-allowed disabled:opacity-50`}
+ >
+ {uploading ? (
+ <div className="flex flex-col items-center justify-center w-full h-full absolute inset-0 bg-black/80 z-20 backdrop-blur-[2px]">
+ <svg className="w-8 h-8 -rotate-90">
+ <circle cx="16" cy="16" r="14" stroke="currentColor" strokeWidth="2" fill="transparent" className="text-white/10" />
+ <circle
+ cx="16"
+ cy="16"
+ r="14"
+ stroke="currentColor"
+ strokeWidth="2"
+ fill="transparent"
+ strokeDasharray={88}
+ strokeDashoffset={88 - (88 * progress) / 100}
+ className="text-[#22d3ee] transition-all duration-300"
+ />
+ </svg>
+ <span className="absolute text-[9px] font-black text-[#22d3ee] leading-none">{progress}%</span>
+ </div>
+ ) : type === "video" ? (
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" className="text-white/40 group-hover:text-[#22d3ee] transition-colors">
+ <polygon points="23 7 16 12 23 17 23 7" />
+ <rect x="1" y="5" width="15" height="14" rx="2" ry="2" />
+ </svg>
+ ) : type === "audio" ? (
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" className="text-white/40 group-hover:text-[#22d3ee] transition-colors">
+ <path d="M9 18V5l10-2v13" />
+ <circle cx="6" cy="18" r="3" />
+ <circle cx="16" cy="16" r="3" />
+ </svg>
+ ) : (
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" className="text-white/40 group-hover:text-[#22d3ee] transition-colors">
+ <line x1="12" y1="5" x2="12" y2="19" />
+ <line x1="5" y1="12" x2="19" y2="12" />
+ </svg>
+ )}
+ </button>
+ <span
+ className="sr-only"
+ role="status"
+ aria-live="polite"
+ aria-atomic="true"
+ >
+ {uploading ? `${title}: ${announcedProgress}% uploaded` : ""}
+ </span>
+ <ReferenceMediaLabel label={label} required={required} />
+ </div>
+ );
+}
+
// ── SVG icons (kept inline to avoid extra deps) ───────────────────────────────
const CheckSvg = () => (
@@ -154,7 +346,6 @@ const invertLogos = ['openai', 'blackforest', 'runway', 'ideogram', 'lightricks'
function ModelDropdown({ selectedModel, onSelect, onClose }) {
const [search, setSearch] = useState("");
const selectedEntry = videoModelPickerEntryByVariantId.get(selectedModel);
- const selectedMode = videoModelCatalog.variantById.get(selectedModel)?.mode || "t2v";
const selectedModelProvider = selectedEntry?.family.provider || "all";
const modelCategories = [
{
@@ -273,11 +464,7 @@ function ModelDropdown({ selectedModel, onSelect, onClose }) {
className={`flex items-center justify-between p-3.5 hover:bg-white/5 rounded-2xl cursor-pointer transition-all border border-transparent hover:border-white/5 ${isSelected ? "bg-white/5 border-white/5" : ""}`}
onClick={(e) => {
e.stopPropagation();
- const variant = activeCategory.id === "all"
- ? entry.variantsByMode[selectedMode] || entry.defaultVariant
- : entry.variantsByMode[activeCategory.id];
- if (!variant) return;
- onSelect(variant.model, variant.mode);
+ onSelect(entry, activeCategory.id);
onClose();
}}
>
@@ -461,16 +648,16 @@ export default function VideoStudio({
migrateLegacyPersistKey(LEGACY_PERSIST_KEY, PERSIST_KEY);
}, [PERSIST_KEY]);
- // ── mode state ──
+ // ── generation state ──
const [imageMode, setImageMode] = useState(false); // i2v
const [v2vMode, setV2vMode] = useState(false);
+ const [selectedWorkflowId, setSelectedWorkflowId] = useState(null);
// ── model / params ──
const defaultModel = t2vModels[0];
+ const defaultFamily = videoModelCatalog.familyByVariantId.get(defaultModel.id);
const [selectedModel, setSelectedModel] = useState(defaultModel.id);
- const [selectedModelName, setSelectedModelName] = useState(defaultModel.name);
- const selectedModelDisplayName =
- videoModelPickerEntryByVariantId.get(selectedModel)?.name || selectedModelName;
+ const [selectedFamilyId, setSelectedFamilyId] = useState(defaultFamily.id);
const [selectedAr, setSelectedAr] = useState(
defaultModel.inputs?.aspect_ratio?.default || "16:9",
);
@@ -483,8 +670,10 @@ export default function VideoStudio({
const [selectedQuality, setSelectedQuality] = useState(
defaultModel.inputs?.quality?.default || "",
);
- const [selectedMode, setSelectedMode] = useState("");
const [selectedEffect, setSelectedEffect] = useState("");
+ const [modelParameterValues, setModelParameterValues] = useState(() =>
+ createModelParameterValues(defaultModel),
+ );
// ── upload progress ──
const [imageProgress, setImageProgress] = useState(0);
@@ -495,19 +684,23 @@ export default function VideoStudio({
const [showDuration, setShowDuration] = useState(true);
const [showResolution, setShowResolution] = useState(false);
const [showQuality, setShowQuality] = useState(false);
- const [showMode, setShowMode] = useState(false);
const [showEffect, setShowEffect] = useState(false);
// ── uploads ──
- const [uploadedImageUrl, setUploadedImageUrl] = useState(null);
const [uploadedImageUrls, setUploadedImageUrls] = useState([]);
const [imageUploading, setImageUploading] = useState(false);
const [uploadedEndImageUrl, setUploadedEndImageUrl] = useState(null);
const [endImageUploading, setEndImageUploading] = useState(false);
const [endImageProgress, setEndImageProgress] = useState(0);
- const [uploadedVideoUrl, setUploadedVideoUrl] = useState(null);
+ const [uploadedVideoUrls, setUploadedVideoUrls] = useState([]);
const [videoUploading, setVideoUploading] = useState(false);
- const [uploadedVideoName, setUploadedVideoName] = useState(null);
+ const [uploadedAudioUrls, setUploadedAudioUrls] = useState([]);
+ const [audioUploading, setAudioUploading] = useState(false);
+ const [audioProgress, setAudioProgress] = useState(0);
+ const [workflowMediaDrafts, setWorkflowMediaDrafts] = useState({});
+ const [workflowUploadSlotId, setWorkflowUploadSlotId] = useState(null);
+ const uploadedImageUrl = uploadedImageUrls[0] || null;
+ const uploadedVideoUrl = uploadedVideoUrls[0] || null;
// ── generation / canvas ──
const [generating, setGenerating] = useState(false);
@@ -517,19 +710,17 @@ export default function VideoStudio({
const [canvasModel, setCanvasModel] = useState(null);
const [showCanvas, setShowCanvas] = useState(false);
const [isDrawModalOpen, setIsDrawModalOpen] = useState(false);
- const [lastGenerationId, setLastGenerationId] = useState(null);
- const [lastGenerationModel, setLastGenerationModel] = useState(null);
+ const [generationSources, setGenerationSources] = useState({});
// ── history ──
const [localHistory, setLocalHistory] = useState([]);
const [activeHistoryIdx, setActiveHistoryIdx] = useState(0);
// ── dropdown ──
- const [openDropdown, setOpenDropdown] = useState(null); // 'model'|'ar'|'duration'|'resolution'|'quality'|'mode'|null
+ const [openDropdown, setOpenDropdown] = useState(null);
// ── prompt ──
const [prompt, setPrompt] = useState("");
- const [promptDisabled, setPromptDisabled] = useState(false);
// ── refs ──
const containerRef = useRef(null);
@@ -538,8 +729,34 @@ export default function VideoStudio({
const imageFileInputRef = useRef(null);
const endImageFileInputRef = useRef(null);
const videoFileInputRef = useRef(null);
+ const audioFileInputRef = useRef(null);
const resultVideoRef = useRef(null);
+ const workflowTriggerRef = useRef(null);
+ const workflowMenuRef = useRef(null);
+ const workflowMenuFocusTargetRef = useRef("selected");
+ const workflowControlId = useId();
+ const workflowMenuId = `${workflowControlId}-menu`;
const hasRestored = useRef(false);
+ const selectionRef = useRef(null);
+ selectionRef.current = {
+ selectedFamilyId,
+ selectedModel,
+ selectedWorkflowId,
+ imageMode,
+ v2vMode,
+ };
+ const workflowVariantPreferencesRef = useRef(new Map());
+ const workflowUploadSlotRef = useRef(null);
+ const workflowDraftSessionRef = useRef(0);
+ const mediaRef = useRef(null);
+ mediaRef.current = {
+ imageUrls: uploadedImageUrls,
+ endImageUrl: uploadedEndImageUrl,
+ videoUrls: uploadedVideoUrls,
+ audioUrls: uploadedAudioUrls,
+ };
+ const workflowMediaDraftsRef = useRef(workflowMediaDrafts);
+ workflowMediaDraftsRef.current = workflowMediaDrafts;
// ── derived data ──
const history = historyItems ?? localHistory;
@@ -556,11 +773,6 @@ export default function VideoStudio({
}
}, [historyItems, onDeleteHistoryItem]);
- const getCurrentModels = useCallback(() => {
- if (v2vMode) return v2vModels;
- return imageMode ? i2vModels : t2vModels;
- }, [imageMode, v2vMode]);
-
const getCurrentAspectRatios = useCallback(
(id) =>
imageMode
@@ -584,20 +796,20 @@ export default function VideoStudio({
);
const getCurrentModel = useCallback(
- () => getCurrentModels().find((m) => m.id === selectedModel),
- [getCurrentModels, selectedModel],
+ () => videoModelCatalog.variantById.get(selectedModel)?.model,
+ [selectedModel],
);
const isMotionControlSelection = useCallback(
(modelId, isV2v) => {
if (!isV2v) return false;
- const m = v2vModels.find((x) => x.id === modelId);
+ const m = videoModelCatalog.variantById.get(modelId)?.model;
return !!m?.imageField;
},
[],
);
- // ── update controls when model/mode changes ──────────────────────────────
+ // ── update controls when the selected model changes ─────────────────────
const applyControlsForModel = useCallback(
(modelId, isImageMode, isV2vMode) => {
if (isV2vMode) {
@@ -605,13 +817,11 @@ export default function VideoStudio({
setShowDuration(false);
setShowResolution(false);
setShowQuality(false);
- setShowMode(false);
setShowEffect(false);
return;
}
- const modelList = isImageMode ? i2vModels : t2vModels;
- const model = modelList.find((m) => m.id === modelId);
+ const model = videoModelCatalog.variantById.get(modelId)?.model;
const ars = isImageMode
? getAspectRatiosForI2VModel(modelId)
@@ -627,7 +837,7 @@ export default function VideoStudio({
? getDurationsForI2VModel(modelId)
: getDurationsForModel(modelId);
if (durations.length > 0) {
- setSelectedDuration(durations[0]);
+ setSelectedDuration(model?.inputs?.duration?.default ?? durations[0]);
setShowDuration(true);
} else {
setShowDuration(false);
@@ -643,7 +853,7 @@ export default function VideoStudio({
setShowResolution(false);
}
- const qualities = getQualitiesForModel(modelList, modelId);
+ const qualities = model?.inputs?.quality?.enum || [];
if (qualities.length > 0) {
setSelectedQuality(model?.inputs?.quality?.default || qualities[0]);
setShowQuality(true);
@@ -652,15 +862,6 @@ export default function VideoStudio({
setShowQuality(false);
}
- const modes = getModesForModel(modelId);
- if (modes.length > 0) {
- setSelectedMode(model?.inputs?.mode?.default || modes[0]);
- setShowMode(true);
- } else {
- setSelectedMode("");
- setShowMode(false);
- }
-
const effects = isImageMode ? getEffectsForI2VModel(modelId) : [];
if (effects.length > 0) {
setSelectedEffect(getDefaultEffectForI2VModel(modelId) || effects[0]);
@@ -673,38 +874,208 @@ export default function VideoStudio({
[],
);
+ const selectedFamily =
+ videoModelCatalog.familyById.get(selectedFamilyId) || defaultFamily;
+ const currentFamilyMode = v2vMode ? "v2v" : imageMode ? "i2v" : "t2v";
+ const workflowFamily = getVideoWorkflowFamily(selectedFamilyId);
+ const selectedWorkflow = selectedWorkflowId
+ ? workflowFamily?.workflowById.get(selectedWorkflowId) || null
+ : null;
+ const workflowControlState = getVideoWorkflowControlState(
+ workflowFamily,
+ selectedModel,
+ );
+ const workflowMediaDraftKey = selectedWorkflowId
+ ? getVideoWorkflowDraftKey(selectedFamilyId, selectedWorkflowId)
+ : null;
+ const selectedVariant = videoModelCatalog.variantById.get(selectedModel);
+ const selectedPickerEntry = videoModelPickerEntryByVariantId.get(selectedModel);
+ const activeWorkflowMediaDraft = useMemo(
+ () => workflowMediaDraftKey
+ ? projectVideoWorkflowMedia(
+ selectedVariant?.model,
+ selectedWorkflowId,
+ workflowMediaDrafts[workflowMediaDraftKey] || EMPTY_WORKFLOW_MEDIA_DRAFT,
+ )
+ : null,
+ [
+ selectedVariant,
+ selectedWorkflowId,
+ workflowMediaDraftKey,
+ workflowMediaDrafts,
+ ],
+ );
+ const promptDisabled = shouldDisableVideoPrompt(
+ selectedVariant?.model,
+ currentFamilyMode,
+ );
+ const workflowMediaSlots = useMemo(
+ () => selectedWorkflowId
+ ? getVideoWorkflowMediaSlots(selectedVariant?.model, selectedWorkflowId)
+ : [],
+ [selectedVariant, selectedWorkflowId],
+ );
+ const currentModelCapabilities = getModelMediaCapabilities(selectedVariant?.model);
+ const supplementalInputs = getSupplementalModelInputs(selectedVariant?.model);
+
+ const applySelectedVariant = useCallback(
+ (variant, mode, family, workflowId = null) => {
+ const model = variant.model;
+ const nextV2VMode = mode === "v2v";
+ const nextImageMode = mode === "i2v";
+
+ const previous = selectionRef.current;
+ if (previous?.selectedFamilyId && previous?.selectedModel) {
+ workflowVariantPreferencesRef.current.set(
+ workflowContextKey(previous.selectedFamilyId, previous.selectedWorkflowId),
+ previous.selectedModel,
+ );
+ }
+ workflowVariantPreferencesRef.current.set(
+ workflowContextKey(family.id, workflowId),
+ model.id,
+ );
+
+ selectionRef.current = {
+ selectedFamilyId: family.id,
+ selectedModel: model.id,
+ selectedWorkflowId: workflowId,
+ imageMode: nextImageMode,
+ v2vMode: nextV2VMode,
+ };
+ setSelectedFamilyId(family.id);
+ setSelectedModel(model.id);
+ setSelectedWorkflowId(workflowId);
+ setModelParameterValues((values) =>
+ createModelParameterValues(model, values),
+ );
+ setV2vMode(nextV2VMode);
+ setImageMode(nextImageMode);
+ applyControlsForModel(model.id, nextImageMode, nextV2VMode);
+ },
+ [applyControlsForModel],
+ );
+
+ const reconcileReferencesForModel = useCallback((model) => {
+ const capabilities = getModelMediaCapabilities(model);
+ setUploadedImageUrls((urls) => urls.slice(0, capabilities.image.maxItems));
+ setUploadedVideoUrls((urls) => urls.slice(0, capabilities.video.maxItems));
+ setUploadedAudioUrls((urls) => urls.slice(0, capabilities.audio.maxItems));
+ if (!capabilities.image.separateLastItem) setUploadedEndImageUrl(null);
+ }, []);
+
+ const applyUserSelectedVariant = useCallback(
+ (variant, mode, family, workflowId = null) => {
+ if (workflowId) {
+ const draftKey = getVideoWorkflowDraftKey(family.id, workflowId);
+ setWorkflowMediaDrafts((drafts) => {
+ if (drafts[draftKey]) return drafts;
+ return {
+ ...drafts,
+ [draftKey]: legacyVideoMediaToWorkflowDraft(
+ variant.model,
+ workflowId,
+ mediaRef.current,
+ ),
+ };
+ });
+ } else {
+ reconcileReferencesForModel(variant.model);
+ }
+ if (shouldDisableVideoPrompt(variant.model, mode)) {
+ setPrompt("");
+ }
+ applySelectedVariant(variant, mode, family, workflowId);
+ },
+ [applySelectedVariant, reconcileReferencesForModel],
+ );
+
// ── Persistence: Load ────────────────────────────────────────────────────
useEffect(() => {
try {
const stored = localStorage.getItem(PERSIST_KEY);
if (stored) {
const data = JSON.parse(stored);
- if (data.imageMode !== undefined) setImageMode(data.imageMode);
- if (data.v2vMode !== undefined) setV2vMode(data.v2vMode);
- if (data.selectedModel) setSelectedModel(data.selectedModel);
- if (data.selectedModelName) setSelectedModelName(data.selectedModelName);
+ let restoredMode = data.v2vMode ? "v2v" : data.imageMode ? "i2v" : "t2v";
+ let restoredModelId = data.selectedModel || defaultModel.id;
+ let restoredWorkflowId = null;
+ let restoredModel = defaultModel;
+ let restoredFamilyId = defaultFamily.id;
+ if (data.selectedModel) {
+ const restored = resolvePersistedVideoWorkflowSelection(
+ data.selectedModel,
+ data.selectedWorkflowId || null,
+ { hasEndFrame: Boolean(data.uploadedEndImageUrl) },
+ );
+ if (restored.family && restored.variant) {
+ restoredModelId = restored.variant.model.id;
+ restoredMode = restored.variant.mode;
+ restoredWorkflowId = restored.workflowId;
+ restoredModel = restored.variant.model;
+ restoredFamilyId = restored.family.id;
+ setSelectedModel(restoredModelId);
+ setSelectedFamilyId(restored.family.id);
+ setSelectedWorkflowId(restored.workflowId);
+ setModelParameterValues(
+ createModelParameterValues(
+ restored.variant.model,
+ data.modelParameterValues || {},
+ ),
+ );
+ }
+ }
+ setImageMode(restoredMode === "i2v");
+ setV2vMode(restoredMode === "v2v");
if (data.selectedAr) setSelectedAr(data.selectedAr);
if (data.selectedDuration) setSelectedDuration(data.selectedDuration);
if (data.selectedResolution) setSelectedResolution(data.selectedResolution);
if (data.selectedQuality) setSelectedQuality(data.selectedQuality);
- if (data.selectedMode) setSelectedMode(data.selectedMode);
if (data.selectedEffect) setSelectedEffect(data.selectedEffect);
- if (data.uploadedImageUrl) setUploadedImageUrl(data.uploadedImageUrl);
if (data.uploadedImageUrls) {
setUploadedImageUrls(data.uploadedImageUrls);
} else if (data.uploadedImageUrl) {
setUploadedImageUrls([data.uploadedImageUrl]);
}
- if (data.uploadedVideoUrl) setUploadedVideoUrl(data.uploadedVideoUrl);
- if (data.uploadedVideoName) setUploadedVideoName(data.uploadedVideoName);
+ if (data.uploadedEndImageUrl) setUploadedEndImageUrl(data.uploadedEndImageUrl);
+ if (data.uploadedVideoUrls) {
+ setUploadedVideoUrls(data.uploadedVideoUrls);
+ } else if (data.uploadedVideoUrl) {
+ setUploadedVideoUrls([data.uploadedVideoUrl]);
+ }
+ if (data.uploadedAudioUrls) setUploadedAudioUrls(data.uploadedAudioUrls);
+ const persistedDrafts =
+ data.workflowMediaDrafts && typeof data.workflowMediaDrafts === "object"
+ ? { ...data.workflowMediaDrafts }
+ : {};
+ if (restoredWorkflowId) {
+ const draftKey = getVideoWorkflowDraftKey(
+ restoredFamilyId,
+ restoredWorkflowId,
+ );
+ if (!persistedDrafts[draftKey]) {
+ persistedDrafts[draftKey] = legacyVideoMediaToWorkflowDraft(
+ restoredModel,
+ restoredWorkflowId,
+ {
+ imageUrls: data.uploadedImageUrls ||
+ (data.uploadedImageUrl ? [data.uploadedImageUrl] : []),
+ endImageUrl: data.uploadedEndImageUrl || null,
+ videoUrls: data.uploadedVideoUrls ||
+ (data.uploadedVideoUrl ? [data.uploadedVideoUrl] : []),
+ audioUrls: data.uploadedAudioUrls || [],
+ },
+ );
+ }
+ }
+ setWorkflowMediaDrafts(persistedDrafts);
if (data.prompt) setPrompt(data.prompt);
if (data.localHistory) setLocalHistory(data.localHistory);
// Update control visibility based on restored model/mode
applyControlsForModel(
- data.selectedModel || defaultModel.id,
- !!data.imageMode,
- !!data.v2vMode
+ restoredModelId,
+ restoredMode === "i2v",
+ restoredMode === "v2v",
);
}
} catch (err) {
@@ -721,18 +1092,20 @@ export default function VideoStudio({
const state = {
imageMode,
v2vMode,
+ selectedWorkflowId,
selectedModel,
- selectedModelName,
+ selectedFamilyId,
selectedAr,
selectedDuration,
selectedResolution,
selectedQuality,
- selectedMode,
selectedEffect,
- uploadedImageUrl,
+ modelParameterValues,
uploadedImageUrls,
- uploadedVideoUrl,
- uploadedVideoName,
+ uploadedEndImageUrl,
+ uploadedVideoUrls,
+ uploadedAudioUrls,
+ workflowMediaDrafts,
prompt,
localHistory,
};
@@ -745,167 +1118,370 @@ export default function VideoStudio({
}, [
imageMode,
v2vMode,
+ selectedWorkflowId,
selectedModel,
- selectedModelName,
+ selectedFamilyId,
selectedAr,
selectedDuration,
selectedResolution,
selectedQuality,
- selectedMode,
selectedEffect,
- uploadedImageUrl,
+ modelParameterValues,
uploadedImageUrls,
- uploadedVideoUrl,
- uploadedVideoName,
+ uploadedEndImageUrl,
+ uploadedVideoUrls,
+ uploadedAudioUrls,
+ workflowMediaDrafts,
prompt,
localHistory,
]);
// ── Derived UI values ────────────────────────────────────────────────────
- const applyImageReferenceUrl = useCallback(
- (url) => {
- if (!url) return;
+ const resolveMediaTarget = useCallback((mediaType) => {
+ const selection = selectionRef.current;
+ const family = videoModelCatalog.familyById.get(selection.selectedFamilyId);
+ const currentVariant = videoModelCatalog.variantById.get(selection.selectedModel);
+ const currentCapabilities = getModelMediaCapabilities(currentVariant?.model);
+ if (currentCapabilities[mediaType].maxItems > 0) {
+ return {
+ family,
+ mode: selection.v2vMode ? "v2v" : selection.imageMode ? "i2v" : "t2v",
+ variant: currentVariant,
+ };
+ }
- setUploadedImageUrl(url);
+ // Families with explicit workflows never switch endpoints because a file
+ // was uploaded. The user chooses the workflow first.
+ if (getVideoWorkflowFamily(family?.id)) return null;
+
+ const targetMode = mediaType === "image" ? "i2v" : mediaType === "video" ? "v2v" : null;
+ if (!targetMode || !family?.supports[targetMode]) return null;
+ const variant = getFamilyVariant(
+ videoModelCatalog,
+ family,
+ targetMode,
+ selection.selectedModel,
+ );
+ return variant ? { family, mode: targetMode, variant } : null;
+ }, []);
- // Motion-control models use the image alongside the uploaded video.
- if (isMotionControlSelection(selectedModel, v2vMode)) {
- setUploadedImageUrls([url]);
- setPromptDisabled(false);
+ const applyReferenceUrls = useCallback(
+ (mediaType, urls, target = null, selectionAtStart = null) => {
+ const validUrls = urls.filter(Boolean);
+ if (validUrls.length === 0) return;
+ if (selectionAtStart && !isSameSelection(selectionAtStart, selectionRef.current)) {
+ toast.error("The model changed during upload. Please add the file again.");
return;
}
-
- const currentT2V = t2vModels.find((model) => model.id === selectedModel);
-
- // Models with native image inputs stay in their current mode.
- if (currentT2V?.inputs?.images_list) {
- const maxImages = currentT2V.inputs.images_list.maxItems || 8;
- setUploadedImageUrls((previousUrls) => {
- if (previousUrls.includes(url)) return previousUrls;
- return [...previousUrls, url].slice(0, maxImages);
- });
- setPromptDisabled(false);
+ const resolvedTarget = target || resolveMediaTarget(mediaType);
+ if (!resolvedTarget) {
+ const family = videoModelCatalog.familyById.get(selectionRef.current.selectedFamilyId);
+ toast.error(`${family.name} does not support ${mediaType} references.`);
return;
}
- setUploadedVideoUrl(null);
- setUploadedVideoName(null);
- setV2vMode(false);
-
- const sibling = currentT2V?.family
- ? i2vModels.find((model) => model.family === currentT2V.family)
- : null;
- const targetModel = imageMode
- ? i2vModels.find((model) => model.id === selectedModel)
- : sibling || i2vModels[0];
-
- if (!targetModel) return;
-
- if (!imageMode) {
- setImageMode(true);
- setSelectedModel(targetModel.id);
- setSelectedModelName(targetModel.name);
- applyControlsForModel(targetModel.id, true, false);
+ const isCurrentVariant =
+ resolvedTarget.variant.model.id === selectionRef.current.selectedModel;
+ if (!isCurrentVariant) {
+ reconcileReferencesForModel(resolvedTarget.variant.model);
+ applySelectedVariant(
+ resolvedTarget.variant,
+ resolvedTarget.mode,
+ resolvedTarget.family,
+ );
}
- const maxImages = getMaxImagesForI2VModel(targetModel.id);
- if (maxImages > 2) {
- setUploadedImageUrls((previousUrls) => {
- if (previousUrls.includes(url)) return previousUrls;
- return [...previousUrls, url].slice(0, maxImages);
- });
- } else {
- setUploadedImageUrls([url]);
- }
- setPromptDisabled(false);
+ const activeWorkflowId = selectionRef.current.selectedWorkflowId;
+ const workflowConfig = activeWorkflowId
+ ? getVideoWorkflowMediaConfig(resolvedTarget.variant.model, activeWorkflowId)
+ : null;
+ const limit = workflowConfig
+ ? mediaType === "image"
+ ? workflowConfig.imageLimit
+ : mediaType === "video"
+ ? workflowConfig.videoLimit
+ : workflowConfig.audioLimit
+ : getModelMediaCapabilities(resolvedTarget.variant.model)[mediaType].maxItems;
+ const setter = mediaType === "image"
+ ? setUploadedImageUrls
+ : mediaType === "video"
+ ? setUploadedVideoUrls
+ : setUploadedAudioUrls;
+ setter((current) => mergeReferenceUrls(current, validUrls, limit));
},
- [
- applyControlsForModel,
- imageMode,
- isMotionControlSelection,
- selectedModel,
- v2vMode,
- ],
+ [applySelectedVariant, reconcileReferencesForModel, resolveMediaTarget],
);
const handleDrawReference = useCallback(
(entry) => {
- applyImageReferenceUrl(entry?.url);
+ if (!selectedWorkflowId) {
+ applyReferenceUrls("image", [entry?.url]);
+ return;
+ }
+ const slot = workflowMediaSlots.find((item) => {
+ return (
+ item.mediaType === "image" &&
+ item.acceptDrop !== false &&
+ getVideoWorkflowSlotRemaining(item, activeWorkflowMediaDraft) > 0
+ );
+ });
+ if (!slot || !workflowMediaDraftKey || !entry?.url) {
+ toast.error("The selected source does not accept images.");
+ return;
+ }
+ setWorkflowMediaDrafts((drafts) => {
+ const draft = drafts[workflowMediaDraftKey] || {};
+ const activeDraft = projectVideoWorkflowMedia(
+ selectedVariant?.model,
+ selectedWorkflowId,
+ draft,
+ );
+ return appendVideoWorkflowMedia(
+ drafts,
+ workflowMediaDraftKey,
+ slot,
+ [entry.url],
+ activeDraft,
+ );
+ });
},
- [applyImageReferenceUrl],
+ [
+ activeWorkflowMediaDraft,
+ applyReferenceUrls,
+ selectedWorkflowId,
+ selectedVariant,
+ workflowMediaDraftKey,
+ workflowMediaSlots,
+ ],
);
- const uploadImageReference = useCallback(
- async (file) => {
- if (file.size > 10 * 1024 * 1024) {
- alert("Image exceeds 10MB limit.");
- return;
+ const uploadFiles = useCallback(
+ async (files, { label, maxBytes, setUploading, setProgress }) => {
+ const selectedFiles = Array.from(files);
+ const tooLarge = selectedFiles.find((file) => file.size > maxBytes);
+ if (tooLarge) {
+ alert(`${label} exceeds ${Math.round(maxBytes / 1024 / 1024)}MB limit.`);
+ return [];
}
-
- setImageUploading(true);
- setImageProgress(0);
+ setUploading(true);
+ setProgress(0);
try {
- const url = await uploadFile(apiKey, file, setImageProgress);
- applyImageReferenceUrl(url);
+ const progress = new Array(selectedFiles.length).fill(0);
+ return await Promise.all(
+ selectedFiles.map((file, index) =>
+ uploadFile(apiKey, file, (value) => {
+ progress[index] = value;
+ setProgress(
+ Math.round(progress.reduce((sum, item) => sum + item, 0) / progress.length),
+ );
+ }),
+ ),
+ );
} catch (err) {
- console.error("[VideoStudio] Image upload failed:", err);
- alert(`Image upload failed: ${err.message}`);
+ console.error(`[VideoStudio] ${label} upload failed:`, err);
+ alert(`${label} upload failed: ${err.message}`);
+ return [];
} finally {
- setImageUploading(false);
- setImageProgress(0);
+ setUploading(false);
+ setProgress(0);
}
},
- [apiKey, applyImageReferenceUrl],
+ [apiKey],
);
- const processDroppedVideo = useCallback(
- async (file) => {
- if (file.size > 50 * 1024 * 1024) {
- alert("Video exceeds 50MB limit.");
- return;
- }
- setVideoUploading(true);
- setVideoProgress(0);
+ const uploadWorkflowSlotFiles = useCallback(
+ async (draftKey, slot, files, context = null) => {
+ if (!draftKey || !slot || workflowUploadSlotRef.current) return;
+ const selectionAtStart = context?.selection || { ...selectionRef.current };
+ const targetModel = videoModelCatalog.variantById.get(
+ selectionAtStart.selectedModel,
+ )?.model;
+ const workflowIdAtStart = selectionAtStart.selectedWorkflowId;
+ const draftSession = context?.session ?? workflowDraftSessionRef.current;
+ const currentDraft = workflowMediaDraftsRef.current[draftKey] || {};
+ const activeDraft = projectVideoWorkflowMedia(
+ targetModel,
+ workflowIdAtStart,
+ currentDraft,
+ );
+ const remaining = getVideoWorkflowSlotRemaining(slot, activeDraft);
+ if (remaining === 0) return;
+
+ const selectedFiles = Array.from(files).slice(0, remaining);
+ if (selectedFiles.length === 0) return;
+ const options = slot.mediaType === "image"
+ ? { label: slot.label, maxBytes: 10 * 1024 * 1024, setUploading: setImageUploading, setProgress: setImageProgress }
+ : slot.mediaType === "video"
+ ? { label: slot.label, maxBytes: 50 * 1024 * 1024, setUploading: setVideoUploading, setProgress: setVideoProgress }
+ : { label: slot.label, maxBytes: 50 * 1024 * 1024, setUploading: setAudioUploading, setProgress: setAudioProgress };
+
+ const uploadKey = `${draftKey}:${slot.id}`;
+ workflowUploadSlotRef.current = uploadKey;
+ setWorkflowUploadSlotId(uploadKey);
try {
- const url = await uploadFile(apiKey, file, setVideoProgress);
- setUploadedVideoUrl(url);
- setUploadedVideoName(file.name);
- if (imageMode) {
- setUploadedImageUrl(null);
- setImageMode(false);
+ const urls = await uploadFiles(selectedFiles, options);
+ if (
+ urls.length > 0 &&
+ draftSession === workflowDraftSessionRef.current
+ ) {
+ const latestDraft = workflowMediaDraftsRef.current[draftKey] || {};
+ const latestActiveDraft = projectVideoWorkflowMedia(
+ targetModel,
+ workflowIdAtStart,
+ latestDraft,
+ );
+ const nextDrafts = appendVideoWorkflowMedia(
+ workflowMediaDraftsRef.current,
+ draftKey,
+ slot,
+ urls,
+ latestActiveDraft,
+ );
+ workflowMediaDraftsRef.current = nextDrafts;
+ setWorkflowMediaDrafts(nextDrafts);
}
- setV2vMode(true);
- const firstV2V = v2vModels[0];
- setSelectedModel(firstV2V.id);
- setSelectedModelName(firstV2V.name);
- applyControlsForModel(firstV2V.id, false, true);
- setPrompt("");
- setPromptDisabled(true);
- } catch (err) {
- alert(`Video upload failed: ${err.message}`);
} finally {
- setVideoUploading(false);
- setVideoProgress(0);
+ workflowUploadSlotRef.current = null;
+ setWorkflowUploadSlotId(null);
+ }
+ },
+ [uploadFiles],
+ );
+
+ const uploadDroppedWorkflowFiles = useCallback(
+ async (files) => {
+ if (!workflowMediaDraftKey) return;
+ const dropSession = workflowDraftSessionRef.current;
+ const dropSelection = { ...selectionRef.current };
+ const dropModel = videoModelCatalog.variantById.get(
+ dropSelection.selectedModel,
+ )?.model;
+ const remainingFiles = Array.from(files);
+ for (const slot of workflowMediaSlots) {
+ if (dropSession !== workflowDraftSessionRef.current) break;
+ if (slot.acceptDrop === false) continue;
+ const matching = remainingFiles.filter((file) =>
+ file.type.startsWith(`${slot.mediaType}/`),
+ );
+ if (matching.length === 0) continue;
+ const currentDraft = workflowMediaDraftsRef.current[workflowMediaDraftKey] || {};
+ const activeDraft = projectVideoWorkflowMedia(
+ dropModel,
+ dropSelection.selectedWorkflowId,
+ currentDraft,
+ );
+ const capacity = getVideoWorkflowSlotRemaining(slot, activeDraft);
+ if (capacity === 0) continue;
+ const batch = matching.slice(0, capacity);
+ await uploadWorkflowSlotFiles(workflowMediaDraftKey, slot, batch, {
+ selection: dropSelection,
+ session: dropSession,
+ });
+ if (dropSession !== workflowDraftSessionRef.current) break;
+ for (const file of batch) {
+ const index = remainingFiles.indexOf(file);
+ if (index >= 0) remainingFiles.splice(index, 1);
+ }
+ }
+ },
+ [uploadWorkflowSlotFiles, workflowMediaDraftKey, workflowMediaSlots],
+ );
+
+ const removeWorkflowMedia = useCallback((slotId, index) => {
+ if (!workflowMediaDraftKey) return;
+ setWorkflowMediaDrafts((drafts) =>
+ removeVideoWorkflowMedia(
+ drafts,
+ workflowMediaDraftKey,
+ slotId,
+ index,
+ ),
+ );
+ }, [workflowMediaDraftKey]);
+
+ const uploadReferences = useCallback(
+ async (mediaType, files) => {
+ const selectionAtStart = { ...selectionRef.current };
+ const target = resolveMediaTarget(mediaType);
+ if (!target) {
+ const family = videoModelCatalog.familyById.get(selectionRef.current.selectedFamilyId);
+ toast.error(`${family.name} does not support ${mediaType} references.`);
+ return;
}
+ const capability = getModelMediaCapabilities(target.variant.model)[mediaType];
+ const workflowConfig = selectionAtStart.selectedWorkflowId
+ ? getVideoWorkflowMediaConfig(
+ target.variant.model,
+ selectionAtStart.selectedWorkflowId,
+ )
+ : null;
+ const currentUrls = mediaType === "image"
+ ? mediaRef.current.imageUrls
+ : mediaType === "video"
+ ? mediaRef.current.videoUrls
+ : mediaRef.current.audioUrls;
+ const configuredLimit = workflowConfig
+ ? mediaType === "image"
+ ? workflowConfig.imageLimit
+ : mediaType === "video"
+ ? workflowConfig.videoLimit
+ : workflowConfig.audioLimit
+ : capability.maxItems;
+ const mainLimit =
+ mediaType === "image" &&
+ (capability.separateLastItem || workflowConfig?.separateEndImage)
+ ? Math.min(configuredLimit, 1)
+ : configuredLimit;
+ const remaining = Math.max(mainLimit - currentUrls.length, 0);
+ if (remaining === 0) return;
+
+ const options = mediaType === "image"
+ ? { label: "Image", maxBytes: 10 * 1024 * 1024, setUploading: setImageUploading, setProgress: setImageProgress }
+ : mediaType === "video"
+ ? { label: "Video", maxBytes: 50 * 1024 * 1024, setUploading: setVideoUploading, setProgress: setVideoProgress }
+ : { label: "Audio", maxBytes: 50 * 1024 * 1024, setUploading: setAudioUploading, setProgress: setAudioProgress };
+ const urls = await uploadFiles(Array.from(files).slice(0, remaining), options);
+ applyReferenceUrls(mediaType, urls, target, selectionAtStart);
},
- [apiKey, applyControlsForModel, imageMode],
+ [applyReferenceUrls, resolveMediaTarget, uploadFiles],
);
// ── Handle Dropped Files ────────────────────────────────────────────────
useEffect(() => {
if (droppedFiles && droppedFiles.length > 0) {
+ if (selectedWorkflowId) {
+ if (workflowUploadSlotRef.current) {
+ toast.error(
+ "Wait for the current upload to finish, then add these files again.",
+ );
+ onFilesHandled?.();
+ return;
+ }
+ void uploadDroppedWorkflowFiles(droppedFiles);
+ onFilesHandled?.();
+ return;
+ }
const imageFiles = droppedFiles.filter(f => f.type.startsWith('image/'));
const videoFiles = droppedFiles.filter(f => f.type.startsWith('video/'));
+ const audioFiles = droppedFiles.filter(f => f.type.startsWith('audio/'));
if (videoFiles.length > 0) {
- processDroppedVideo(videoFiles[0]);
+ uploadReferences("video", videoFiles);
} else if (imageFiles.length > 0) {
- uploadImageReference(imageFiles[0]);
+ uploadReferences("image", imageFiles);
+ } else if (audioFiles.length > 0) {
+ uploadReferences("audio", audioFiles);
}
onFilesHandled?.();
}
- }, [droppedFiles, onFilesHandled, processDroppedVideo, uploadImageReference]);
+ }, [
+ droppedFiles,
+ onFilesHandled,
+ selectedWorkflowId,
+ uploadDroppedWorkflowFiles,
+ uploadReferences,
+ ]);
// Initialise controls for default model on mount
useEffect(() => {
@@ -932,46 +1508,25 @@ export default function VideoStudio({
// ── image upload ─────────────────────────────────────────────────────────
const handleImageFileChange = async (e) => {
- const file = e.target.files[0];
- if (!file) return;
+ const files = Array.from(e.target.files);
+ if (files.length === 0) return;
try {
- await uploadImageReference(file);
+ await uploadReferences("image", files);
} finally {
if (imageFileInputRef.current) imageFileInputRef.current.value = "";
}
};
- const clearImageUpload = () => {
- setUploadedImageUrl(null);
- setUploadedImageUrls([]);
- setUploadedEndImageUrl(null);
- // Motion-control v2v or model with inputs.images_list: keep model, just drop the image
- if (isMotionControlSelection(selectedModel, v2vMode)) return;
- const currentT2V = t2vModels.find((m) => m.id === selectedModel);
- if (currentT2V?.inputs?.images_list) return;
- setImageMode(false);
- const first = t2vModels[0];
- setSelectedModel(first.id);
- setSelectedModelName(first.name);
- applyControlsForModel(first.id, false, false);
- setPromptDisabled(false);
- };
-
const removeImageAtIndex = (idx) => {
const nextUrls = uploadedImageUrls.filter((_, i) => i !== idx);
setUploadedImageUrls(nextUrls);
if (nextUrls.length === 0) {
- setUploadedImageUrl(null);
- // Reset to text-to-video if empty list
+ if (workflowFamily) return;
if (isMotionControlSelection(selectedModel, v2vMode)) return;
- setImageMode(false);
- const first = t2vModels[0];
- setSelectedModel(first.id);
- setSelectedModelName(first.name);
- applyControlsForModel(first.id, false, false);
- setPromptDisabled(false);
- } else {
- setUploadedImageUrl(nextUrls[0]);
+ if (currentFamilyMode === "t2v" && currentModelCapabilities.image.maxItems > 0) return;
+ const family = videoModelCatalog.familyById.get(selectedFamilyId);
+ const target = getFamilyVariant(videoModelCatalog, family, "t2v", selectedModel);
+ if (target) applyUserSelectedVariant(target, "t2v", family);
}
};
@@ -985,11 +1540,21 @@ export default function VideoStudio({
}
setEndImageUploading(true);
setEndImageProgress(0);
+ const selectionAtStart = { ...selectionRef.current };
try {
const url = await uploadFile(apiKey, file, (pct) => {
setEndImageProgress(pct);
});
- setUploadedEndImageUrl(url);
+ const latestModel = videoModelCatalog.variantById.get(
+ selectionRef.current.selectedModel,
+ )?.model;
+ if (
+ isSameSelection(selectionAtStart, selectionRef.current) &&
+ (selectionRef.current.selectedWorkflowId === "keyframes" ||
+ getModelMediaCapabilities(latestModel).image.separateLastItem)
+ ) {
+ setUploadedEndImageUrl(url);
+ }
} catch (err) {
alert(`End frame upload failed: ${err.message}`);
} finally {
@@ -1003,110 +1568,93 @@ export default function VideoStudio({
// ── video upload ─────────────────────────────────────────────────────────
const handleVideoFileChange = async (e) => {
- const file = e.target.files[0];
- if (!file) return;
- if (file.size > 50 * 1024 * 1024) {
- alert("Video exceeds 50MB limit.");
- return;
- }
- setVideoUploading(true);
- setVideoProgress(0);
+ const files = Array.from(e.target.files);
+ if (files.length === 0) return;
try {
- const url = await uploadFile(apiKey, file, (pct) => {
- setVideoProgress(pct);
- });
- setUploadedVideoUrl(url);
- setUploadedVideoName(file.name);
-
- if (isMotionControlSelection(selectedModel, v2vMode)) {
- // Already in motion-control mode — keep model and image, allow prompt
- setPromptDisabled(false);
- } else {
- // Model-native video reference (e.g. Seedance 2.0 Extend with inputs.video_files):
- // keep the current model & mode; just store the video URL as a reference
- const currentT2VOrExtend = t2vModels.find((m) => m.id === selectedModel);
- if (currentT2VOrExtend?.inputs?.video_files) {
- setPromptDisabled(false);
- } else {
- // Default v2v flow (e.g. watermark remover) — auto-pick the first v2v model
- if (imageMode) {
- setUploadedImageUrl(null);
- setImageMode(false);
- }
- setV2vMode(true);
- const firstV2V = v2vModels[0];
- setSelectedModel(firstV2V.id);
- setSelectedModelName(firstV2V.name);
- applyControlsForModel(firstV2V.id, false, true);
- setPrompt("");
- setPromptDisabled(true);
- }
- }
- } catch (err) {
- console.error("[VideoStudio] Video upload failed:", err);
- alert(`Video upload failed: ${err.message}`);
+ await uploadReferences("video", files);
} finally {
- setVideoUploading(false);
- setVideoProgress(0);
if (videoFileInputRef.current) videoFileInputRef.current.value = "";
}
};
- const clearVideoUpload = () => {
- setUploadedVideoUrl(null);
- setUploadedVideoName(null);
- setV2vMode(false);
- const first = t2vModels[0];
- setSelectedModel(first.id);
- setSelectedModelName(first.name);
- applyControlsForModel(first.id, false, false);
- setPromptDisabled(false);
+ const removeVideoAtIndex = (index) => {
+ const nextUrls = uploadedVideoUrls.filter((_, itemIndex) => itemIndex !== index);
+ setUploadedVideoUrls(nextUrls);
+ if (workflowFamily) return;
+ if (nextUrls.length > 0 || currentFamilyMode !== "v2v") return;
+ const family = videoModelCatalog.familyById.get(selectedFamilyId);
+ const target = getFamilyVariant(videoModelCatalog, family, "t2v", selectedModel);
+ if (target) applyUserSelectedVariant(target, "t2v", family);
+ };
+
+ const handleAudioFileChange = async (e) => {
+ const files = Array.from(e.target.files);
+ if (files.length === 0) return;
+ try {
+ await uploadReferences("audio", files);
+ } finally {
+ if (audioFileInputRef.current) audioFileInputRef.current.value = "";
+ }
+ };
+
+ const removeAudioAtIndex = (index) => {
+ setUploadedAudioUrls((urls) => urls.filter((_, itemIndex) => itemIndex !== index));
};
// ── model selection from dropdown ─────────────────────────────────────────
const handleModelSelect = useCallback(
- (m, category = imageMode ? "i2v" : "t2v") => {
- const isV2V = category === "v2v";
- if (isV2V) {
- setV2vMode(true);
- setImageMode(false);
- const isMC = !!m.imageField;
- if (!isMC) {
- // Single-input v2v (watermark remover etc.) — drop any image
- setUploadedImageUrl(null);
- }
- setSelectedModel(m.id);
- setSelectedModelName(m.name);
- applyControlsForModel(m.id, false, true);
- if (isMC) {
- // Motion-control: prompt is editable, video+image are needed
- setPromptDisabled(false);
- } else {
- setPrompt("");
- setPromptDisabled(true);
- }
- } else {
- if (v2vMode) {
- setV2vMode(false);
- setUploadedVideoUrl(null);
- setUploadedVideoName(null);
- setPromptDisabled(false);
- }
- const nextImageMode = category === "i2v";
- if (!nextImageMode && imageMode) {
- setUploadedImageUrl(null);
- setUploadedImageUrls([]);
- setUploadedEndImageUrl(null);
- }
- setImageMode(nextImageMode);
- setSelectedModel(m.id);
- setSelectedModelName(m.name);
- applyControlsForModel(m.id, nextImageMode, false);
+ (pickerEntry, category = "all") => {
+ const { family, variantsByMode, defaultVariant } = pickerEntry;
+ const target = category !== "all"
+ ? variantsByMode[category]
+ : variantsByMode[currentFamilyMode] || defaultVariant;
+ if (!target) return;
+
+ const targetWorkflowFamily = getVideoWorkflowFamily(family.id);
+ if (targetWorkflowFamily) {
+ const workflowId = targetWorkflowFamily.base.variantIds.has(target.model.id) ||
+ targetWorkflowFamily.unmanagedVariantIds.has(target.model.id)
+ ? null
+ : inferVideoWorkflowId(family.id, target.model.id);
+ applyUserSelectedVariant(target, target.mode, family, workflowId);
+ return;
}
+
+ applyUserSelectedVariant(target, target.mode, family);
},
- [v2vMode, imageMode, applyControlsForModel],
+ [
+ applyUserSelectedVariant,
+ currentFamilyMode,
+ ],
);
+ const handleWorkflowSelect = useCallback((workflowId) => {
+ const preferred = workflowVariantPreferencesRef.current.get(
+ workflowContextKey(selectedFamilyId, workflowId),
+ );
+ const target = resolveVideoWorkflowVariant(
+ selectedFamilyId,
+ workflowId,
+ selectedModel,
+ preferred,
+ );
+ if (target) {
+ applyUserSelectedVariant(target, target.mode, selectedFamily, workflowId);
+ }
+ }, [applyUserSelectedVariant, selectedFamily, selectedFamilyId, selectedModel]);
+
+ const clearWorkflow = useCallback(() => {
+ const preferred = workflowVariantPreferencesRef.current.get(
+ workflowContextKey(selectedFamilyId, null),
+ );
+ const target = resolveVideoBaseVariant(
+ selectedFamilyId,
+ selectedModel,
+ preferred,
+ );
+ if (target) applyUserSelectedVariant(target, target.mode, selectedFamily, null);
+ }, [applyUserSelectedVariant, selectedFamily, selectedFamilyId, selectedModel]);
+
// ── add to local history ──────────────────────────────────────────────────
const addToLocalHistory = useCallback((entry) => {
setLocalHistory((prev) => [entry, ...prev].slice(0, 30));
@@ -1124,9 +1672,46 @@ export default function VideoStudio({
const handleGenerate = useCallback(async () => {
const currentModel = getCurrentModel();
const isExtendMode = currentModel?.requiresRequestId;
+ const capabilities = getModelMediaCapabilities(currentModel);
+ const requestSource = generationSources[selectedFamily.id];
const trimmedPrompt = prompt.trim();
+ const workflowMedia = selectedWorkflowId
+ ? activeWorkflowMediaDraft || {}
+ : {
+ imageUrls: uploadedImageUrls,
+ endImageUrl: uploadedEndImageUrl,
+ videoUrls: uploadedVideoUrls,
+ audioUrls: uploadedAudioUrls,
+ };
- if (v2vMode) {
+ if (!selectedWorkflowId && uploadedVideoUrls.length > 0 && capabilities.video.maxItems === 0) {
+ alert(`${selectedFamily.name} does not support video references.`);
+ return;
+ }
+ if (!selectedWorkflowId && uploadedImageUrls.length > 0 && capabilities.image.maxItems === 0) {
+ alert(`${selectedFamily.name} does not support image references.`);
+ return;
+ }
+ if (!selectedWorkflowId && uploadedAudioUrls.length > 0 && capabilities.audio.maxItems === 0) {
+ alert(`${selectedFamily.name} does not support audio references.`);
+ return;
+ }
+ if (currentModel?.promptRequired && !trimmedPrompt) {
+ alert("Please enter a prompt for this model.");
+ return;
+ }
+
+ if (selectedWorkflowId) {
+ const validation = validateVideoWorkflowMedia(
+ selectedWorkflowId,
+ workflowMedia,
+ currentModel,
+ );
+ if (!validation.valid) {
+ alert(validation.message);
+ return;
+ }
+ } else if (v2vMode) {
if (!uploadedVideoUrl) {
alert("Please upload a video first.");
return;
@@ -1135,29 +1720,15 @@ export default function VideoStudio({
alert("Please upload a reference image for motion control.");
return;
}
- if (currentModel?.promptRequired && !trimmedPrompt) {
- alert("Please describe the motion you want.");
- return;
- }
} else if (isExtendMode) {
- if (!lastGenerationId) {
- alert(
- "No Seedance 2.0 generation found to extend. Generate a video first.",
- );
+ if (!requestSource?.requestId) {
+ alert(`No ${selectedFamily.name} generation found to continue.`);
return;
}
} else if (imageMode) {
- const maxImgs = getMaxImagesForI2VModel(selectedModel);
- if (maxImgs > 2) {
- if (uploadedImageUrls.length === 0) {
- alert("Please upload at least one reference image first.");
- return;
- }
- } else {
- if (!uploadedImageUrl) {
- alert("Please upload a start frame image first.");
- return;
- }
+ if (uploadedImageUrls.length === 0) {
+ alert("Please upload at least one reference image first.");
+ return;
}
} else {
if (!trimmedPrompt) {
@@ -1170,21 +1741,24 @@ export default function VideoStudio({
setGenerating(true);
setGenerateError(null);
- let hadError = false;
-
try {
let res;
+ const referenceParams = selectedWorkflowId
+ ? buildVideoWorkflowMediaParams(
+ currentModel,
+ selectedWorkflowId,
+ workflowMedia,
+ )
+ : buildReferenceParams(currentModel, workflowMedia);
if (v2vMode) {
// V2V: dedicated processV2V handles single-input tools (e.g. watermark
// remover) and motion-control models (which take video + image + prompt)
const v2vParams = {
model: selectedModel,
- video_url: uploadedVideoUrl,
+ ...buildSupplementalInputPayload(currentModel, modelParameterValues),
+ ...referenceParams,
};
- if (currentModel?.imageField && uploadedImageUrl) {
- v2vParams.image_url = uploadedImageUrl;
- }
if (currentModel?.hasPrompt && trimmedPrompt) {
v2vParams.prompt = trimmedPrompt;
}
@@ -1192,8 +1766,6 @@ export default function VideoStudio({
if (!res?.url) throw new Error("No video URL returned by API");
const genId = res.id || Date.now().toString();
- setLastGenerationId(null);
- setLastGenerationModel(null);
const entry = {
id: genId,
url: res.url,
@@ -1211,38 +1783,27 @@ export default function VideoStudio({
type: "video",
});
} else if (imageMode) {
- const maxImgs = getMaxImagesForI2VModel(selectedModel);
- const i2vParams = { model: selectedModel };
- if (maxImgs > 2) {
- i2vParams.images_list = uploadedImageUrls;
- } else {
- i2vParams.image_url = uploadedImageUrl;
- }
+ const i2vParams = {
+ model: selectedModel,
+ ...buildSupplementalInputPayload(currentModel, modelParameterValues),
+ ...referenceParams,
+ };
if (trimmedPrompt) i2vParams.prompt = trimmedPrompt;
i2vParams.aspect_ratio = selectedAr;
- const i2vModel = i2vModels.find((m) => m.id === selectedModel);
- if (uploadedEndImageUrl && i2vModel?.lastImageField) {
- i2vParams.last_image = uploadedEndImageUrl;
- }
const durations = getDurationsForI2VModel(selectedModel);
if (durations.length > 0) i2vParams.duration = selectedDuration;
const resolutions = getResolutionsForI2VModel(selectedModel);
if (resolutions.length > 0) i2vParams.resolution = selectedResolution;
if (selectedQuality) i2vParams.quality = selectedQuality;
- if (selectedMode) i2vParams.mode = selectedMode;
if (showEffect && selectedEffect) i2vParams.name = selectedEffect;
res = await generateI2V(apiKey, i2vParams);
if (!res?.url) throw new Error("No video URL returned by API");
const genId = res.id || Date.now().toString();
- if (selectedModel === "seedance-v2.0-i2v") {
- setLastGenerationId(genId);
- setLastGenerationModel(selectedModel);
- } else {
- setLastGenerationId(null);
- setLastGenerationModel(null);
- }
+ setGenerationSources((sources) =>
+ recordGenerationSource(sources, selectedFamily.id, genId, selectedModel),
+ );
const entry = {
id: genId,
url: res.url,
@@ -1263,19 +1824,15 @@ export default function VideoStudio({
});
} else {
// T2V (including extend mode)
- const params = { model: selectedModel };
+ const params = {
+ model: selectedModel,
+ ...buildSupplementalInputPayload(currentModel, modelParameterValues),
+ ...referenceParams,
+ };
if (trimmedPrompt) params.prompt = trimmedPrompt;
if (isExtendMode) {
- params.request_id = lastGenerationId;
- // Optional reference media for Seedance 2.0 Extend:
- // images map to @image2…@image9 and videos map to @video1…@video3 in the prompt
- if (uploadedImageUrls.length > 0) {
- params.images_list = uploadedImageUrls;
- }
- if (uploadedVideoUrl) {
- params.videos_list = [uploadedVideoUrl];
- }
+ params.request_id = requestSource.requestId;
} else {
params.aspect_ratio = selectedAr;
}
@@ -1285,22 +1842,14 @@ export default function VideoStudio({
const resolutions = getResolutionsForVideoModel(selectedModel);
if (resolutions.length > 0) params.resolution = selectedResolution;
if (selectedQuality) params.quality = selectedQuality;
- if (selectedMode) params.mode = selectedMode;
res = await generateVideo(apiKey, params);
if (!res?.url) throw new Error("No video URL returned by API");
const genId = res.id || Date.now().toString();
- if (
- selectedModel === "seedance-v2.0-t2v" ||
- selectedModel === "seedance-v2.0-i2v"
- ) {
- setLastGenerationId(genId);
- setLastGenerationModel(selectedModel);
- } else {
- setLastGenerationId(null);
- setLastGenerationModel(null);
- }
+ setGenerationSources((sources) =>
+ recordGenerationSource(sources, selectedFamily.id, genId, selectedModel),
+ );
const entry = {
id: genId,
url: res.url,
@@ -1321,7 +1870,6 @@ export default function VideoStudio({
});
}
} catch (e) {
- hadError = true;
console.error("[VideoStudio]", e);
const errMsg = formatErrorMessage(e, "Video generation failed");
if (onGenerationError) onGenerationError(errMsg);
@@ -1335,18 +1883,22 @@ export default function VideoStudio({
prompt,
v2vMode,
imageMode,
+ selectedWorkflowId,
selectedModel,
+ selectedFamily,
selectedAr,
selectedDuration,
selectedResolution,
selectedQuality,
- selectedMode,
selectedEffect,
+ modelParameterValues,
showEffect,
- uploadedImageUrl,
uploadedImageUrls,
- uploadedVideoUrl,
- lastGenerationId,
+ uploadedEndImageUrl,
+ uploadedVideoUrls,
+ uploadedAudioUrls,
+ activeWorkflowMediaDraft,
+ generationSources,
getCurrentModel,
addToLocalHistory,
showVideoInCanvas,
@@ -1364,54 +1916,190 @@ export default function VideoStudio({
const handleNewPrompt = useCallback(() => {
resetToPromptBar();
setPrompt("");
- setUploadedImageUrl(null);
setUploadedImageUrls([]);
- setImageMode(false);
- setUploadedVideoUrl(null);
- setUploadedVideoName(null);
- setV2vMode(false);
+ setUploadedEndImageUrl(null);
+ setUploadedVideoUrls([]);
+ setUploadedAudioUrls([]);
+ workflowDraftSessionRef.current += 1;
+ setWorkflowMediaDrafts({});
const first = t2vModels[0];
- setSelectedModel(first.id);
- setSelectedModelName(first.name);
- applyControlsForModel(first.id, false, false);
- setPromptDisabled(false);
+ const family = videoModelCatalog.familyByVariantId.get(first.id);
+ const variant = videoModelCatalog.variantById.get(first.id);
+ applyUserSelectedVariant(variant, "t2v", family);
setTimeout(() => textareaRef.current?.focus(), 50);
- }, [resetToPromptBar, applyControlsForModel]);
+ }, [applyUserSelectedVariant, resetToPromptBar]);
- const handleExtend = useCallback(() => {
- if (!lastGenerationId) return;
+ const handleExtend = useCallback((requestId, sourceModelId) => {
+ if (!requestId) return;
resetToPromptBar();
setPrompt("");
- setUploadedImageUrl(null);
setUploadedImageUrls([]);
- setImageMode(false);
- setSelectedModel("seedance-v2.0-extend");
- setSelectedModelName("Seedance 2.0 Extend");
- applyControlsForModel("seedance-v2.0-extend", false, false);
- setPromptDisabled(false);
+ setUploadedEndImageUrl(null);
+ setUploadedVideoUrls([]);
+ setUploadedAudioUrls([]);
+ const family = videoModelCatalog.familyById.get("seedance-2");
+ const target = videoModelCatalog.variantById.get("seedance-2-extend");
+ setGenerationSources((sources) =>
+ recordGenerationSource(sources, family.id, requestId, sourceModelId),
+ );
+ applyUserSelectedVariant(target, "t2v", family);
setTimeout(() => textareaRef.current?.focus(), 50);
- }, [lastGenerationId, resetToPromptBar, applyControlsForModel]);
+ }, [applyUserSelectedVariant, resetToPromptBar]);
// ── derived UI values ────────────────────────────────────────────────────
const isSeedance2Canvas =
- canvasModel === "seedance-v2.0-t2v" || canvasModel === "seedance-v2.0-i2v";
- const currentModelObj = getCurrentModel();
+ videoModelCatalog.familyByVariantId.get(canvasModel)?.id === "seedance-2";
+ const currentModelObj = selectedVariant?.model;
const isExtendMode = currentModelObj?.requiresRequestId;
- const canUploadImageReference =
- (!v2vMode || isMotionControlSelection(selectedModel, v2vMode)) &&
- (!isExtendMode || currentModelObj?.inputs?.images_list);
-
- const promptPlaceholder = v2vMode
- ? currentModelObj?.imageField
- ? currentModelObj?.promptRequired
+ const isMotionControlModel = isMotionControlSelection(selectedModel, v2vMode);
+ const workflowMediaConfig = selectedWorkflowId
+ ? getVideoWorkflowMediaConfig(currentModelObj, selectedWorkflowId)
+ : null;
+ const canUploadImageReference = workflowMediaConfig
+ ? workflowMediaConfig.imageLimit > 0
+ : workflowFamily
+ ? currentModelCapabilities.image.maxItems > 0
+ : currentModelCapabilities.image.maxItems > 0 ||
+ (!v2vMode && selectedFamily.supports.i2v);
+ const imageTargetVariant = workflowFamily
+ ? selectedVariant
+ : currentModelCapabilities.image.maxItems > 0
+ ? selectedVariant
+ : getFamilyVariant(videoModelCatalog, selectedFamily, "i2v", selectedModel);
+ const imageUploadCapability = getModelMediaCapabilities(imageTargetVariant?.model).image;
+ const imageUploadLimit = workflowMediaConfig
+ ? workflowMediaConfig.imageLimit
+ : imageUploadCapability.separateLastItem
+ ? 1
+ : imageUploadCapability.maxItems;
+ const videoTargetVariant = workflowFamily
+ ? selectedVariant
+ : currentModelCapabilities.video.maxItems > 0
+ ? selectedVariant
+ : getFamilyVariant(videoModelCatalog, selectedFamily, "v2v", selectedModel);
+ const videoUploadLimit = workflowMediaConfig
+ ? workflowMediaConfig.videoLimit
+ : getModelMediaCapabilities(videoTargetVariant?.model).video.maxItems;
+ const audioUploadLimit = workflowMediaConfig
+ ? workflowMediaConfig.audioLimit
+ : currentModelCapabilities.audio.maxItems;
+ const showEndImageUpload = workflowMediaConfig
+ ? workflowMediaConfig.separateEndImage
+ : imageUploadCapability.separateLastItem;
+
+ const promptPlaceholder = selectedWorkflowId === "edit_video"
+ ? "Describe how to edit the video"
+ : selectedWorkflowId === "extend_uploaded_video"
+ ? "Describe how to continue the video"
+ : selectedWorkflowId === "motion_transfer"
? "Describe the motion"
- : "Describe the motion (optional)"
- : "Video ready — click Generate to remove watermark"
- : imageMode
- ? "Describe the motion or effect (optional)"
- : isExtendMode
- ? "Optional: describe how to continue the video..."
- : "Describe the video you want to create";
+ : v2vMode
+ ? currentModelObj?.imageField
+ ? currentModelObj?.promptRequired
+ ? "Describe the motion"
+ : "Describe the motion (optional)"
+ : "Video ready — click Generate to remove watermark"
+ : imageMode
+ ? currentModelObj?.promptRequired
+ ? "Describe the motion or effect"
+ : "Describe the motion or effect (optional)"
+ : isExtendMode
+ ? "Optional: describe how to continue the video..."
+ : "Describe the video you want to create";
+
+ const focusWorkflowMenuItem = useCallback((target = "selected") => {
+ const items = Array.from(
+ workflowMenuRef.current?.querySelectorAll(
+ '[role="menuitemradio"], [role="menuitem"]',
+ ) || [],
+ );
+ if (items.length === 0) return;
+
+ const item = target === "last"
+ ? items[items.length - 1]
+ : target === "first"
+ ? items[0]
+ : items.find((candidate) => candidate.getAttribute("aria-checked") === "true") ||
+ items[0];
+ item.focus();
+ }, []);
+
+ const closeWorkflowMenu = useCallback((restoreFocus = false) => {
+ setOpenDropdown(null);
+ if (restoreFocus) {
+ requestAnimationFrame(() => workflowTriggerRef.current?.focus());
+ }
+ }, []);
+
+ const handleWorkflowTriggerKeyDown = useCallback(
+ (event) => {
+ const focusTarget = event.key === "ArrowUp" || event.key === "End"
+ ? "last"
+ : event.key === "ArrowDown" || event.key === "Home"
+ ? "first"
+ : null;
+ if (!focusTarget) return;
+
+ event.preventDefault();
+ event.stopPropagation();
+ if (openDropdown === "workflow") {
+ focusWorkflowMenuItem(focusTarget);
+ return;
+ }
+ workflowMenuFocusTargetRef.current = focusTarget;
+ setOpenDropdown("workflow");
+ },
+ [focusWorkflowMenuItem, openDropdown],
+ );
+
+ const handleWorkflowMenuKeyDown = useCallback(
+ (event) => {
+ if (event.key === "Escape") {
+ event.preventDefault();
+ event.stopPropagation();
+ closeWorkflowMenu(true);
+ return;
+ }
+ if (event.key === "Tab") {
+ setOpenDropdown(null);
+ return;
+ }
+ if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
+
+ const items = Array.from(
+ workflowMenuRef.current?.querySelectorAll(
+ '[role="menuitemradio"], [role="menuitem"]',
+ ) || [],
+ );
+ if (items.length === 0) return;
+
+ event.preventDefault();
+ event.stopPropagation();
+ const currentIndex = items.indexOf(document.activeElement);
+ const nextIndex = event.key === "Home"
+ ? 0
+ : event.key === "End"
+ ? items.length - 1
+ : event.key === "ArrowDown"
+ ? currentIndex < 0
+ ? 0
+ : (currentIndex + 1) % items.length
+ : currentIndex < 0
+ ? items.length - 1
+ : (currentIndex - 1 + items.length) % items.length;
+ items[nextIndex].focus();
+ },
+ [closeWorkflowMenu],
+ );
+
+ useEffect(() => {
+ if (openDropdown !== "workflow") return undefined;
+ const frame = requestAnimationFrame(() => {
+ focusWorkflowMenuItem(workflowMenuFocusTargetRef.current);
+ workflowMenuFocusTargetRef.current = "selected";
+ });
+ return () => cancelAnimationFrame(frame);
+ }, [focusWorkflowMenuItem, openDropdown, selectedWorkflowId]);
const toggleDropdown = (type) => (e) => {
e.stopPropagation();
@@ -1475,8 +2163,7 @@ export default function VideoStudio({
title="Extend this video using Seedance 2.0 Extend"
onClick={(e) => {
e.stopPropagation();
- setLastGenerationId(entry.id);
- handleExtend();
+ handleExtend(entry.id, entry.model);
}}
className="p-2 bg-black/60 backdrop-blur-md rounded-full text-white hover:bg-primary hover:text-black transition-all border border-white/10"
>
@@ -1519,10 +2206,7 @@ export default function VideoStudio({
isSeedance2 && {
kind: "extend",
label: "Extend",
- onSelect: () => {
- setLastGenerationId(entry.id);
- handleExtend();
- },
+ onSelect: () => handleExtend(entry.id, entry.model),
},
{
kind: "delete",
@@ -1601,7 +2285,7 @@ export default function VideoStudio({
<h1 className="text-2xl sm:text-4xl md:text-5xl font-extrabold tracking-tight mb-4 text-center px-4 flex flex-col items-center">
<span className="text-white font-black uppercase text-xl sm:text-3xl tracking-wide mb-1 opacity-90">START CREATING WITH</span>
<span className="text-[#22d3ee] font-black uppercase text-2xl sm:text-4xl sm:mt-1 tracking-tight">
- {selectedModelDisplayName}
+ {selectedFamily.name}
</span>
</h1>
<p className="text-white/40 text-xs sm:text-sm font-medium tracking-wide text-center max-w-lg leading-relaxed px-4">
@@ -1615,266 +2299,191 @@ export default function VideoStudio({
<PromptComposer>
<div className="flex flex-col gap-3">
{/* Inline list of uploaded media files */}
- <div className="flex items-center gap-2.5 flex-wrap">
- {/* Main image preview */}
- {uploadedImageUrl && (
- <div className={PROMPT_MEDIA_PREVIEW_CLASS}>
- <img src={uploadedImageUrl} alt="" className="w-full h-full object-cover" />
- <button
- type="button"
- onClick={clearImageUpload}
- className="absolute top-0.5 right-0.5 w-4 h-4 bg-black/60 hover:bg-black rounded-full flex items-center justify-center text-white/85 hover:text-white text-[8px] border border-white/5"
- >
- ×
- </button>
- </div>
- )}
+ <div className="flex items-start gap-2.5 flex-wrap">
+ {selectedWorkflowId ? (
+ <>
+ {workflowMediaSlots.flatMap((slot) => {
+ const values = activeWorkflowMediaDraft?.[slot.id] || [];
+ return values.map((url, index) => (
+ <ReferencePreview
+ key={`${slot.id}:${index}:${url}`}
+ type={slot.mediaType}
+ url={url}
+ index={index}
+ onRemove={(itemIndex) =>
+ removeWorkflowMedia(slot.id, itemIndex)
+ }
+ label={
+ values.length > 1
+ ? `${slot.label} · ${index + 1}`
+ : slot.label
+ }
+ description={
+ values.length > 1
+ ? `${slot.description} ${index + 1}`
+ : slot.description
+ }
+ />
+ ));
+ })}
+
+ {workflowMediaSlots.map((slot) => {
+ const values = activeWorkflowMediaDraft?.[slot.id] || [];
+ const remaining = getVideoWorkflowSlotRemaining(
+ slot,
+ activeWorkflowMediaDraft,
+ );
+ if (remaining <= 0) return null;
+ const uploadKey = `${workflowMediaDraftKey}:${slot.id}`;
+ const uploading = workflowUploadSlotId === uploadKey;
+ const progress = slot.mediaType === "image"
+ ? imageProgress
+ : slot.mediaType === "video"
+ ? videoProgress
+ : audioProgress;
+ return (
+ <ReferenceUploadButton
+ key={slot.id}
+ accept={`${slot.mediaType}/*`}
+ multiple={remaining > 1}
+ onChange={async (event) => {
+ const files = Array.from(event.target.files || []);
+ event.target.value = "";
+ await uploadWorkflowSlotFiles(
+ workflowMediaDraftKey,
+ slot,
+ files,
+ );
+ }}
+ title={`${slot.description || slot.label}${slot.required ? " (required)" : " (optional)"}`}
+ uploading={uploading}
+ progress={progress}
+ type={slot.mediaType}
+ label={slot.label}
+ required={slot.required}
+ disabled={Boolean(workflowUploadSlotId)}
+ />
+ );
+ })}
+ </>
+ ) : (
+ <>
+ {uploadedImageUrls.map((url, index) => (
+ <ReferencePreview
+ key={url}
+ type="image"
+ url={url}
+ index={index}
+ onRemove={removeImageAtIndex}
+ label={
+ uploadedImageUrls.length > 1
+ ? `Image · ${index + 1}`
+ : "Image"
+ }
+ />
+ ))}
- {/* End frame image preview */}
{uploadedEndImageUrl && (
- <div className={PROMPT_MEDIA_PREVIEW_CLASS}>
- <img src={uploadedEndImageUrl} alt="" className="w-full h-full object-cover" />
- <button
- type="button"
- onClick={clearEndImage}
- className="absolute top-0.5 right-0.5 w-4 h-4 bg-black/60 hover:bg-black rounded-full flex items-center justify-center text-white/85 hover:text-white text-[8px] border border-white/5"
- >
- ×
- </button>
- <span className="absolute bottom-0.5 left-0.5 px-1 h-3.5 bg-black/60 rounded-md text-[7px] font-black text-[#22d3ee] leading-none flex items-center justify-center pointer-events-none">
- END
- </span>
- </div>
+ <ReferencePreview
+ type="image"
+ url={uploadedEndImageUrl}
+ index={0}
+ onRemove={clearEndImage}
+ label="End frame"
+ />
)}
- {/* Video preview */}
- {uploadedVideoUrl && (
- <div className={PROMPT_MEDIA_PREVIEW_CLASS}>
- <video src={uploadedVideoUrl} className="w-full h-full object-cover" muted />
- <button
- type="button"
- onClick={clearVideoUpload}
- className="absolute top-0.5 right-0.5 w-4 h-4 bg-black/60 hover:bg-black rounded-full flex items-center justify-center text-white/85 hover:text-white text-[8px] border border-white/5"
- >
- ×
- </button>
- </div>
- )}
+ {uploadedVideoUrls.map((url, index) => (
+ <ReferencePreview
+ key={url}
+ type="video"
+ url={url}
+ index={index}
+ onRemove={removeVideoAtIndex}
+ label={
+ uploadedVideoUrls.length > 1
+ ? `Video · ${index + 1}`
+ : "Video"
+ }
+ />
+ ))}
+
+ {uploadedAudioUrls.map((url, index) => (
+ <ReferencePreview
+ key={url}
+ type="audio"
+ url={url}
+ index={index}
+ onRemove={removeAudioAtIndex}
+ label={
+ uploadedAudioUrls.length > 1
+ ? `Audio · ${index + 1}`
+ : "Audio"
+ }
+ />
+ ))}
- {/* Multiple images layout if supported */}
- {imageMode && getMaxImagesForI2VModel(selectedModel) > 2 && (
- <>
- {uploadedImageUrls.map((url, idx) => (
- <div key={url} className={PROMPT_MEDIA_PREVIEW_CLASS}>
- <img src={url} alt="" className="w-full h-full object-cover" />
- <button
- type="button"
- onClick={() => removeImageAtIndex(idx)}
- className="absolute top-0.5 right-0.5 w-4 h-4 bg-black/60 hover:bg-black rounded-full flex items-center justify-center text-white/85 hover:text-white text-[8px] border border-white/5"
- >
- ×
- </button>
- <span className="absolute bottom-0.5 right-0.5 px-1 h-3.5 bg-black/60 rounded-full text-[8px] font-black text-[#22d3ee] leading-none flex items-center justify-center pointer-events-none">
- {idx + 1}
- </span>
- </div>
- ))}
- </>
+ {/* Upload trigger buttons */}
+ {canUploadImageReference && uploadedImageUrls.length < imageUploadLimit && (
+ <ReferenceUploadButton
+ inputRef={imageFileInputRef}
+ accept="image/*"
+ multiple={imageUploadLimit - uploadedImageUrls.length > 1}
+ onChange={handleImageFileChange}
+ onClick={() => imageFileInputRef.current?.click()}
+ title={
+ selectedWorkflowId === "keyframes"
+ ? "Upload start frame"
+ : `Upload up to ${imageUploadLimit} reference images`
+ }
+ uploading={imageUploading}
+ progress={imageProgress}
+ type="image"
+ />
)}
- {/* Upload trigger buttons */}
- {/* Image upload button — shown when the model accepts image input:
- • T2V mode: uploading an image auto-switches to the sibling I2V model
- • I2V mode: uploading the start-frame (multi-image logic applies)
- • V2V motion-control: reference image is required alongside the video
- • T2V with inputs.images_list: optional reference images (e.g. Seedance 2.0 Extend)
- • Hidden in regular V2V mode (watermark remover etc. needs no image)
- • Hidden for extend-type models without inputs.images_list */}
- {canUploadImageReference && (
- getMaxImagesForI2VModel(selectedModel) > 2 ? (
- uploadedImageUrls.length < getMaxImagesForI2VModel(selectedModel) && (
- <div className="relative">
- <input
- ref={imageFileInputRef}
- type="file"
- accept="image/*"
- className="hidden"
- onChange={handleImageFileChange}
- />
- <button
- type="button"
- title="Upload reference image"
- onClick={() => imageFileInputRef.current?.click()}
- className={promptMediaButtonClassName()}
- >
- {imageUploading ? (
- <div className="flex flex-col items-center justify-center w-full h-full absolute inset-0 bg-black/80 z-20 backdrop-blur-[2px]">
- <svg className="w-8 h-8 -rotate-90">
- <circle cx="16" cy="16" r="14" stroke="currentColor" strokeWidth="2" fill="transparent" className="text-white/10" />
- <circle
- cx="16"
- cy="16"
- r="14"
- stroke="currentColor"
- strokeWidth="2"
- fill="transparent"
- strokeDasharray={88}
- strokeDashoffset={88 - (88 * imageProgress) / 100}
- className="text-[#22d3ee] transition-all duration-300"
- />
- </svg>
- <span className="absolute text-[9px] font-black text-[#22d3ee] leading-none">{imageProgress}%</span>
- </div>
- ) : (
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" className="text-white/40 group-hover:text-[#22d3ee] transition-colors">
- <line x1="12" y1="5" x2="12" y2="19" />
- <line x1="5" y1="12" x2="19" y2="12" />
- </svg>
- )}
- </button>
- </div>
- )
- ) : (
- !uploadedImageUrl && (
- <div className="relative">
- <input
- ref={imageFileInputRef}
- type="file"
- accept="image/*"
- className="hidden"
- onChange={handleImageFileChange}
- />
- <button
- type="button"
- title="Upload reference image"
- onClick={() => imageFileInputRef.current?.click()}
- className={promptMediaButtonClassName()}
- >
- {imageUploading ? (
- <div className="flex flex-col items-center justify-center w-full h-full absolute inset-0 bg-black/80 z-20 backdrop-blur-[2px]">
- <svg className="w-8 h-8 -rotate-90">
- <circle cx="16" cy="16" r="14" stroke="currentColor" strokeWidth="2" fill="transparent" className="text-white/10" />
- <circle
- cx="16"
- cy="16"
- r="14"
- stroke="currentColor"
- strokeWidth="2"
- fill="transparent"
- strokeDasharray={88}
- strokeDashoffset={88 - (88 * imageProgress) / 100}
- className="text-[#22d3ee] transition-all duration-300"
- />
- </svg>
- <span className="absolute text-[9px] font-black text-[#22d3ee] leading-none">{imageProgress}%</span>
- </div>
- ) : (
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" className="text-white/40 group-hover:text-[#22d3ee] transition-colors">
- <line x1="12" y1="5" x2="12" y2="19" />
- <line x1="5" y1="12" x2="19" y2="12" />
- </svg>
- )}
- </button>
- </div>
- )
- )
+ {showEndImageUpload && !uploadedEndImageUrl && (
+ <ReferenceUploadButton
+ inputRef={endImageFileInputRef}
+ accept="image/*"
+ multiple={false}
+ onChange={handleEndImageFileChange}
+ onClick={() => endImageFileInputRef.current?.click()}
+ title="Upload end frame"
+ uploading={endImageUploading}
+ progress={endImageProgress}
+ type="image"
+ />
)}
- {/* End frame image button */}
- {imageMode && i2vModels.find((m) => m.id === selectedModel)?.lastImageField && !uploadedEndImageUrl && (
- <div className="relative">
- <input
- ref={endImageFileInputRef}
- type="file"
- accept="image/*"
- className="hidden"
- onChange={handleEndImageFileChange}
- />
- <button
- type="button"
- title="Upload end frame (optional)"
- onClick={() => endImageFileInputRef.current?.click()}
- className={promptMediaButtonClassName()}
- >
- {endImageUploading ? (
- <div className="flex flex-col items-center justify-center w-full h-full absolute inset-0 bg-black/80 z-20 backdrop-blur-[2px]">
- <svg className="w-8 h-8 -rotate-90">
- <circle cx="16" cy="16" r="14" stroke="currentColor" strokeWidth="2" fill="transparent" className="text-white/10" />
- <circle
- cx="16"
- cy="16"
- r="14"
- stroke="currentColor"
- strokeWidth="2"
- fill="transparent"
- strokeDasharray={88}
- strokeDashoffset={88 - (88 * endImageProgress) / 100}
- className="text-[#22d3ee] transition-all duration-300"
- />
- </svg>
- <span className="absolute text-[9px] font-black text-[#22d3ee] leading-none">{endImageProgress}%</span>
- </div>
- ) : (
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" className="text-white/40 group-hover:text-[#22d3ee] transition-colors">
- <line x1="12" y1="5" x2="12" y2="19" />
- <line x1="5" y1="12" x2="19" y2="12" />
- </svg>
- )}
- </button>
- </div>
+ {videoUploadLimit > 0 && uploadedVideoUrls.length < videoUploadLimit && (
+ <ReferenceUploadButton
+ inputRef={videoFileInputRef}
+ accept="video/*"
+ multiple={videoUploadLimit - uploadedVideoUrls.length > 1}
+ onChange={handleVideoFileChange}
+ onClick={() => videoFileInputRef.current?.click()}
+ title={`Upload up to ${videoUploadLimit} reference videos`}
+ uploading={videoUploading}
+ progress={videoProgress}
+ type="video"
+ />
)}
- {/* Video upload button — shown when a V2V model is active, OR when
- the current model has inputs.video_files (e.g. Seedance 2.0 Extend). */}
- {!uploadedVideoUrl && (v2vMode || currentModelObj?.inputs?.video_files) && (
- <div className="relative">
- <input
- ref={videoFileInputRef}
- type="file"
- accept="video/*"
- className="hidden"
- onChange={handleVideoFileChange}
- />
- <button
- type="button"
- title="Upload video to remove watermark"
- onClick={() => videoFileInputRef.current?.click()}
- className={promptMediaButtonClassName()}
- >
- {videoUploading ? (
- <div className="flex flex-col items-center justify-center w-full h-full absolute inset-0 bg-black/80 z-20 backdrop-blur-[2px]">
- <svg className="w-8 h-8 -rotate-90">
- <circle cx="16" cy="16" r="14" stroke="currentColor" strokeWidth="2" fill="transparent" className="text-white/10" />
- <circle
- cx="16"
- cy="16"
- r="14"
- stroke="currentColor"
- strokeWidth="2"
- fill="transparent"
- strokeDasharray={88}
- strokeDashoffset={88 - (88 * videoProgress) / 100}
- className="text-[#22d3ee] transition-all duration-300"
- />
- </svg>
- <span className="absolute text-[9px] font-black text-[#22d3ee] leading-none">{videoProgress}%</span>
- </div>
- ) : (
- <svg
- width="16"
- height="16"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- strokeWidth="2.5"
- className="text-white/40 group-hover:text-[#22d3ee] transition-colors"
- >
- <polygon points="23 7 16 12 23 17 23 7" fill="currentColor" />
- <rect x="1" y="5" width="15" height="14" rx="2" ry="2" fill="currentColor" />
- </svg>
- )}
- </button>
- </div>
+ {audioUploadLimit > 0 && uploadedAudioUrls.length < audioUploadLimit && (
+ <ReferenceUploadButton
+ inputRef={audioFileInputRef}
+ accept="audio/*"
+ multiple={audioUploadLimit - uploadedAudioUrls.length > 1}
+ onChange={handleAudioFileChange}
+ onClick={() => audioFileInputRef.current?.click()}
+ title={`Upload up to ${audioUploadLimit} reference audio files`}
+ uploading={audioUploading}
+ progress={audioProgress}
+ type="audio"
+ />
+ )}
+ </>
)}
</div>
@@ -1903,7 +2512,7 @@ export default function VideoStudio({
>
<path d="M5 12h14M12 5l7 7-7 7" />
</svg>
- <span>Extending previous Seedance 2.0 generation</span>
+ <span>Continuing the previous {selectedFamily.name} generation</span>
</div>
)}
@@ -1921,9 +2530,7 @@ export default function VideoStudio({
>
<div className="w-4 h-4 rounded overflow-hidden shrink-0 flex items-center justify-center bg-white/5">
{(() => {
- const allCurrentModels = [...t2vModels, ...i2vModels, ...v2vModels];
- const selectedModelObj = allCurrentModels.find(m => m.id === selectedModel);
- const selectedModelProvider = selectedModelObj?.provider || 'muapi';
+ const selectedModelProvider = selectedFamily.provider || 'muapi';
return PROVIDER_LOGOS[selectedModelProvider] ? (
<img
src={PROVIDER_LOGOS[selectedModelProvider]}
@@ -1934,9 +2541,9 @@ export default function VideoStudio({
<span className="text-[9px] font-bold text-black uppercase">V</span>
);
})()}
- </div>
+ </div>
<span className={PROMPT_CONTROL_LABEL_CLASS}>
- {selectedModelDisplayName}
+ {selectedPickerEntry?.name || selectedFamily.name}
</span>
<PromptChevronIcon />
</button>
@@ -1955,6 +2562,136 @@ export default function VideoStudio({
)}
</div>
+ {workflowControlState.kind !== "hidden" && (
+ <div className="relative flex items-center gap-1">
+ <button
+ type="button"
+ ref={workflowTriggerRef}
+ id={workflowControlId}
+ aria-haspopup={
+ workflowControlState.kind === "menu" ? "menu" : undefined
+ }
+ aria-controls={
+ workflowControlState.kind === "menu" ? workflowMenuId : undefined
+ }
+ aria-expanded={
+ workflowControlState.kind === "menu"
+ ? openDropdown === "workflow"
+ : undefined
+ }
+ aria-pressed={
+ workflowControlState.kind === "direct"
+ ? Boolean(selectedWorkflowId)
+ : undefined
+ }
+ onClick={(event) => {
+ if (workflowControlState.kind === "direct") {
+ event.stopPropagation();
+ if (selectedWorkflowId) {
+ clearWorkflow();
+ } else if (workflowControlState.workflow) {
+ handleWorkflowSelect(workflowControlState.workflow.id);
+ }
+ setOpenDropdown(null);
+ return;
+ }
+ event.stopPropagation();
+ if (openDropdown === "workflow") {
+ setOpenDropdown(null);
+ return;
+ }
+ workflowMenuFocusTargetRef.current = "selected";
+ setOpenDropdown("workflow");
+ }}
+ onKeyDown={
+ workflowControlState.kind === "menu"
+ ? handleWorkflowTriggerKeyDown
+ : undefined
+ }
+ className={promptControlClassName({
+ active: openDropdown === "workflow",
+ })}
+ >
+ <span className={PROMPT_CONTROL_LABEL_CLASS}>
+ {getVideoWorkflowControlLabel(selectedWorkflow)}
+ </span>
+ {workflowControlState.kind === "menu" && <PromptChevronIcon />}
+ </button>
+ {workflowControlState.kind === "menu" && openDropdown === "workflow" && (
+ <PromptPopover
+ className="min-w-[210px]"
+ style={{ maxHeight: "55vh" }}
+ onClick={(event) => event.stopPropagation()}
+ >
+ <PromptPopoverHeader>Source</PromptPopoverHeader>
+ <div
+ ref={workflowMenuRef}
+ id={workflowMenuId}
+ role="menu"
+ aria-labelledby={workflowControlId}
+ onKeyDown={handleWorkflowMenuKeyDown}
+ className="flex flex-col gap-1"
+ >
+ {workflowFamily.workflows.map((workflow) => (
+ <PromptMenuItem
+ key={workflow.id}
+ selected={selectedWorkflowId === workflow.id}
+ onClick={(event) => {
+ event.stopPropagation();
+ handleWorkflowSelect(workflow.id);
+ closeWorkflowMenu(true);
+ }}
+ >
+ {workflow.label}
+ </PromptMenuItem>
+ ))}
+ {selectedWorkflow && workflowFamily?.hasBase && (
+ <div className="mt-2 border-t border-white/[0.05] pt-2">
+ <button
+ type="button"
+ role="menuitemradio"
+ aria-checked={false}
+ onClick={(event) => {
+ event.stopPropagation();
+ clearWorkflow();
+ closeWorkflowMenu(true);
+ }}
+ className="flex min-h-9 w-full items-center gap-2 rounded-xl px-3 py-2 text-left text-[11px] font-semibold text-white/40 transition-colors hover:bg-white/[0.04] hover:text-white/70 focus:outline-none focus-visible:bg-white/[0.04] focus-visible:text-white/70"
+ >
+ <svg
+ width="13"
+ height="13"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="2"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ aria-hidden="true"
+ >
+ <path d="M3 12a9 9 0 1 0 3-6.7L3 8" />
+ <path d="M3 3v5h5" />
+ </svg>
+ <span>Base generation</span>
+ </button>
+ </div>
+ )}
+ </div>
+ </PromptPopover>
+ )}
+ </div>
+ )}
+
+ <ModelParameterControls
+ inputs={supplementalInputs}
+ values={modelParameterValues}
+ onChange={(key, value) =>
+ setModelParameterValues((values) => ({ ...values, [key]: value }))
+ }
+ open={openDropdown === "parameters"}
+ onToggle={toggleDropdown("parameters")}
+ />
+
{/* Aspect ratio btn */}
{showAr && (
<div className="relative">
diff --git a/packages/studio/src/modelCapabilities.js b/packages/studio/src/modelCapabilities.js
new file mode 100644
index 00000000..73c48b68
--- /dev/null
+++ b/packages/studio/src/modelCapabilities.js
@@ -0,0 +1,223 @@
+const MEDIA_CONFIG = {
+ image: {
+ explicitField: "imageField",
+ explicitMax: "maxImages",
+ fields: [
+ "images_list",
+ "image_urls",
+ "reference_images",
+ "image_url",
+ "start_image_url",
+ "first_image_url",
+ ],
+ singularParam: "image_url",
+ pluralParam: "images_list",
+ },
+ video: {
+ explicitField: "videoField",
+ explicitMax: "maxVideos",
+ fields: [
+ "videos_list",
+ "video_files",
+ "video_urls",
+ "reference_videos",
+ "video_url",
+ ],
+ singularParam: "video_url",
+ pluralParam: "videos_list",
+ },
+ audio: {
+ explicitField: "audioField",
+ explicitMax: "maxAudios",
+ fields: [
+ "audios_list",
+ "audio_files",
+ "audio_urls",
+ "reference_audios",
+ "audio_url",
+ ],
+ singularParam: "audio_url",
+ pluralParam: "audios_list",
+ },
+};
+
+function uniqueUrls(urls) {
+ return [...new Set((urls || []).filter(Boolean))];
+}
+
+export function getMediaCapability(model, mediaType) {
+ const config = MEDIA_CONFIG[mediaType];
+ if (!config || !model) {
+ return {
+ field: null,
+ maxItems: 0,
+ isArray: false,
+ separateLastItem: false,
+ lastField: null,
+ };
+ }
+
+ const explicitField = model[config.explicitField];
+ const schemaField = Object.entries(model.inputs || {}).find(
+ ([, input]) => input?.field === mediaType,
+ )?.[0];
+ const field =
+ explicitField ||
+ config.fields.find((name) => model.inputs?.[name]) ||
+ schemaField ||
+ null;
+ const input = field ? model.inputs?.[field] : null;
+ const isArray = input?.type === "array" || /(?:_list|_urls|_files)$/.test(field || "");
+ const explicitMax = model[config.explicitMax];
+ let maxItems = field
+ ? (explicitMax || (isArray ? input?.maxItems || input?.max_items || 1 : 1))
+ : 0;
+
+ const lastField = mediaType === "image"
+ ? model.lastImageField ||
+ ["last_image", "last_image_url", "end_image_url"].find(
+ (name) => model.inputs?.[name],
+ ) ||
+ null
+ : null;
+ const separateLastItem = !!lastField;
+ if (separateLastItem) maxItems = Math.max(maxItems, 2);
+
+ return { field, maxItems, isArray, separateLastItem, lastField };
+}
+
+export function getModelMediaCapabilities(model) {
+ return {
+ image: getMediaCapability(model, "image"),
+ video: getMediaCapability(model, "video"),
+ audio: getMediaCapability(model, "audio"),
+ };
+}
+
+export function shouldDisableVideoPrompt(model, mode) {
+ return Boolean(
+ model && mode === "v2v" && !model.hasPrompt && !model.imageField,
+ );
+}
+
+export function buildReferenceParams(
+ model,
+ { imageUrls = [], endImageUrl = null, videoUrls = [], audioUrls = [] } = {},
+) {
+ const capabilities = getModelMediaCapabilities(model);
+ const params = {};
+
+ const images = uniqueUrls(imageUrls).slice(0, capabilities.image.maxItems);
+ if (capabilities.image.field && images.length > 0) {
+ if (capabilities.image.separateLastItem) {
+ params.image_url = images[0];
+ const lastImage = endImageUrl || images[1];
+ if (lastImage) params.last_image = lastImage;
+ } else if (capabilities.image.isArray) {
+ params.images_list = images;
+ } else {
+ params.image_url = images[0];
+ }
+ }
+
+ const videos = uniqueUrls(videoUrls).slice(0, capabilities.video.maxItems);
+ if (capabilities.video.field && videos.length > 0) {
+ params[capabilities.video.isArray ? "videos_list" : "video_url"] =
+ capabilities.video.isArray ? videos : videos[0];
+ }
+
+ const audios = uniqueUrls(audioUrls).slice(0, capabilities.audio.maxItems);
+ if (capabilities.audio.field && audios.length > 0) {
+ params[capabilities.audio.isArray ? "audios_list" : "audio_url"] =
+ capabilities.audio.isArray ? audios : audios[0];
+ }
+
+ return params;
+}
+
+function normalizedUrls(params, capability, singularParam, pluralParam) {
+ if (!capability.field) return [];
+ const direct = params[capability.field];
+ if (Array.isArray(direct) && direct.length > 0) return direct;
+ if (direct) return [direct];
+ const plural = params[pluralParam];
+ if (Array.isArray(plural) && plural.length > 0) return plural;
+ const singular = params[singularParam];
+ return singular ? [singular] : [];
+}
+
+function mediaTypeForInput(inputName, input) {
+ for (const [mediaType, config] of Object.entries(MEDIA_CONFIG)) {
+ if (
+ input?.field === mediaType ||
+ config.fields.includes(inputName) ||
+ config.fields.includes(input?.field)
+ ) {
+ return mediaType;
+ }
+ }
+ return null;
+}
+
+export function mapReferenceParams(model, params = {}) {
+ const capabilities = getModelMediaCapabilities(model);
+ const payload = {};
+
+ for (const mediaType of Object.keys(MEDIA_CONFIG)) {
+ const config = MEDIA_CONFIG[mediaType];
+ const capability = capabilities[mediaType];
+ const urls = normalizedUrls(
+ params,
+ capability,
+ config.singularParam,
+ config.pluralParam,
+ ).slice(0, capability.maxItems);
+ if (urls.length === 0) continue;
+ payload[capability.field] = capability.isArray ? urls : urls[0];
+ }
+
+ // Some workflows intentionally declare more than one field of the same
+ // media type (for example Wan: an optional start frame plus reference
+ // images). Keep those secondary declared fields instead of collapsing them
+ // into the primary capability selected above.
+ for (const [inputName, input] of Object.entries(model?.inputs || {})) {
+ const mediaType = mediaTypeForInput(inputName, input);
+ if (!mediaType || capabilities[mediaType].field === inputName) continue;
+ const value = params[inputName];
+ if (value === undefined || value === null || value === "") continue;
+ if (input?.type === "array") {
+ const values = (Array.isArray(value) ? value : [value])
+ .filter(Boolean)
+ .slice(0, input.maxItems || input.max_items || Number.POSITIVE_INFINITY);
+ if (values.length > 0) payload[inputName] = values;
+ } else {
+ payload[inputName] = Array.isArray(value) ? value[0] : value;
+ }
+ }
+
+ const imageCapability = capabilities.image;
+ const directLastImage =
+ imageCapability.lastField && imageCapability.lastField !== imageCapability.field
+ ? params[imageCapability.lastField]
+ : null;
+ const lastImage = directLastImage || params.last_image;
+ if (lastImage && imageCapability.lastField) {
+ if (imageCapability.lastField === imageCapability.field && imageCapability.isArray) {
+ const images = payload[imageCapability.field] || [];
+ if (!images.includes(lastImage)) payload[imageCapability.field] = [...images, lastImage];
+ } else {
+ payload[imageCapability.lastField] = Array.isArray(lastImage)
+ ? lastImage[0]
+ : lastImage;
+ }
+ }
+
+ return payload;
+}
+
+export function recordGenerationSource(sources, familyId, requestId, modelId) {
+ return {
+ ...sources,
+ [familyId]: { requestId, modelId },
+ };
+}
diff --git a/packages/studio/src/modelFamilies.js b/packages/studio/src/modelFamilies.js
index afeaa6c7..91fa3e6a 100644
--- a/packages/studio/src/modelFamilies.js
+++ b/packages/studio/src/modelFamilies.js
@@ -5,6 +5,7 @@ import {
t2vModels,
v2vModels,
} from "./models.js";
+import { getModelMediaCapabilities } from "./modelCapabilities.js";
const IMAGE_FAMILY_ALIASES = {
"bytedance-seededit-v3": "bytedance-seedream-v3",
@@ -108,6 +109,43 @@ function videoVariantKey(model) {
: endpoint;
}
+const PREFERRED_IMAGE_VARIANTS = {
+ "flux-2-klein": {
+ t2i: "flux-2-klein-4b",
+ i2i: "flux-2-klein-4b-edit",
+ },
+ "flux-dev": { t2i: "flux-dev" },
+ "google-imagen4": { t2i: "google-imagen4" },
+ gpt4o: { i2i: "gpt4o-image-to-image" },
+ "midjourney-v7": { i2i: "midjourney-v7-image-to-image" },
+ "nano-banana": { i2i: "nano-banana-edit" },
+ "qwen-image-2.0": {
+ t2i: "qwen-image-2.0",
+ i2i: "qwen-image-2.0-edit",
+ },
+ "qwen-plus": { i2i: "qwen-image-edit-plus" },
+ qwen3: {
+ t2i: "qwen3-text-to-image",
+ i2i: "qwen3-image-to-image",
+ },
+ "seedream-5.0": {
+ t2i: "bytedance-seedream-v5.0",
+ i2i: "bytedance-seedream-v5.0-edit",
+ },
+ "wan2.7": {
+ t2i: "wan2.7-text-to-image",
+ i2i: "wan2.7-image-edit",
+ },
+};
+
+const PREFERRED_VIDEO_VARIANTS = {
+ "kling-v3": {
+ t2v: "kling-v3.0-standard-text-to-video",
+ i2v: "kling-v3.0-standard-image-to-video",
+ v2v: "kling-v3.0-std-motion-control",
+ },
+};
+
function normalizeVersion(value) {
return value.replace(/^v/i, "").replace(/\.0$/, "");
}
@@ -406,9 +444,53 @@ function buildCatalog(modeLists, config) {
familyById,
familyByVariantId,
variantById,
+ preferredVariants: config.preferredVariants || {},
};
}
+function getPickerEntryByVariantId(catalog, variantId) {
+ return catalog === imageModelCatalog
+ ? imageModelPickerEntryByVariantId.get(variantId)
+ : videoModelPickerEntryByVariantId.get(variantId);
+}
+
+export function getFamilyVariant(catalog, familyOrId, mode, currentVariantId = null) {
+ const family =
+ typeof familyOrId === "string" ? catalog.familyById.get(familyOrId) : familyOrId;
+ const variants = family?.variants[mode] || [];
+ if (variants.length === 0) return null;
+
+ const currentFamily = currentVariantId
+ ? catalog.familyByVariantId.get(currentVariantId)
+ : null;
+ if (currentFamily?.id === family.id) {
+ const currentVariant = catalog.variantById.get(currentVariantId);
+ if (currentVariant?.mode === mode) return currentVariant;
+ const currentEntry = getPickerEntryByVariantId(catalog, currentVariantId);
+ return currentEntry?.variantsByMode[mode] || null;
+ }
+
+ const preferredId = catalog.preferredVariants[family.id]?.[mode];
+ const preferred = preferredId ? catalog.variantById.get(preferredId) : null;
+ if (preferred) return preferred;
+
+ return variants[0];
+}
+
+export function getImageReferenceVariant(catalog, familyOrId, currentVariantId) {
+ const family =
+ typeof familyOrId === "string" ? catalog.familyById.get(familyOrId) : familyOrId;
+ const currentVariant = catalog.variantById.get(currentVariantId);
+ if (
+ family &&
+ catalog.familyByVariantId.get(currentVariantId)?.id === family.id &&
+ getModelMediaCapabilities(currentVariant?.model).image.maxItems > 0
+ ) {
+ return currentVariant;
+ }
+ return getFamilyVariant(catalog, family, "i2i", currentVariantId);
+}
+
export const imageModelCatalog = buildCatalog(
[
{ mode: "t2i", models: t2iModels },
@@ -418,6 +500,7 @@ export const imageModelCatalog = buildCatalog(
familyId: imageFamilyId,
familyName: (id, fallback) => IMAGE_FAMILY_NAMES[id] || cleanImageFamilyName(fallback),
namingModes: ["t2i", "i2i"],
+ preferredVariants: PREFERRED_IMAGE_VARIANTS,
seriesVersion: imageSeriesVersion,
},
);
@@ -432,6 +515,7 @@ export const videoModelCatalog = buildCatalog(
familyId: videoFamilyId,
familyName: videoFamilyName,
namingModes: ["t2v", "i2v", "v2v"],
+ preferredVariants: PREFERRED_VIDEO_VARIANTS,
seriesVersion: videoSeriesVersion,
variantKey: videoVariantKey,
},
diff --git a/packages/studio/src/modelParameters.js b/packages/studio/src/modelParameters.js
new file mode 100644
index 00000000..e2f3531b
--- /dev/null
+++ b/packages/studio/src/modelParameters.js
@@ -0,0 +1,124 @@
+import { getModelMediaCapabilities } from "./modelCapabilities.js";
+
+const COMMON_INPUT_KEYS = new Set([
+ "prompt",
+ "aspect_ratio",
+ "resolution",
+ "quality",
+ "mode",
+ "duration",
+ "name",
+ "api_key",
+ "request_id",
+ "num_images",
+ "batch_size",
+]);
+
+function mediaInputKeys(model) {
+ const capabilities = getModelMediaCapabilities(model);
+ const keys = new Set();
+ for (const capability of Object.values(capabilities)) {
+ if (capability.field) keys.add(capability.field);
+ if (capability.lastField) keys.add(capability.lastField);
+ }
+ for (const [key, input] of Object.entries(model?.inputs || {})) {
+ if (["image", "video", "audio"].includes(input?.field)) keys.add(key);
+ }
+ return keys;
+}
+
+export function getSupplementalModelInputs(model) {
+ if (!model?.inputs) return [];
+ const mediaKeys = mediaInputKeys(model);
+ return Object.entries(model.inputs)
+ .filter(([key]) => !COMMON_INPUT_KEYS.has(key) && !mediaKeys.has(key))
+ .map(([key, schema]) => ({ key, schema }));
+}
+
+function defaultValue(schema) {
+ if (schema.default !== undefined) return schema.default;
+ if (schema.type === "boolean") return false;
+ if (schema.type === "array") return [];
+ return "";
+}
+
+function clampNumber(value, schema) {
+ const number = Number(value);
+ if (!Number.isFinite(number)) return undefined;
+ const minimum = schema.minValue ?? schema.minimum;
+ const maximum = schema.maxValue ?? schema.maximum;
+ const clamped = Math.min(maximum ?? number, Math.max(minimum ?? number, number));
+ const fractionalStep = schema.step !== undefined && !Number.isInteger(Number(schema.step));
+ return ["int", "integer"].includes(schema.type) && !fractionalStep
+ ? Math.round(clamped)
+ : clamped;
+}
+
+function normalizeValue(value, schema, { includeEmpty = false } = {}) {
+ if (schema.enum) {
+ return schema.enum.includes(value) ? value : schema.default;
+ }
+ if (schema.type === "boolean") return typeof value === "boolean" ? value : !!schema.default;
+ if (["number", "integer", "int"].includes(schema.type)) {
+ return clampNumber(value, schema);
+ }
+ if (schema.type === "array") {
+ if (!Array.isArray(value)) return [];
+ const maxItems = schema.maxItems ?? schema.max_items ?? value.length;
+ return value
+ .slice(0, maxItems)
+ .map((item) => normalizeValue(item, schema.items || {}, { includeEmpty }))
+ .filter((item) => item !== undefined && (includeEmpty || item !== ""));
+ }
+ if (schema.type === "object") {
+ if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
+ const requiredKeys = schema.required || [];
+ const stringKeys = Object.entries(schema.properties || {})
+ .filter(([, propertySchema]) => propertySchema.type === "string")
+ .map(([key]) => key);
+ const identifyingKeys = requiredKeys.length > 0 ? requiredKeys : stringKeys;
+ if (
+ !includeEmpty &&
+ identifyingKeys.length > 0 &&
+ identifyingKeys.every((key) => !String(value[key] ?? "").trim())
+ ) {
+ return undefined;
+ }
+ const normalized = {};
+ for (const [key, propertySchema] of Object.entries(schema.properties || {})) {
+ const propertyValue = normalizeValue(value[key], propertySchema, { includeEmpty });
+ if (propertyValue !== undefined && (includeEmpty || propertyValue !== "")) {
+ normalized[key] = propertyValue;
+ }
+ }
+ return Object.keys(normalized).length > 0 ? normalized : undefined;
+ }
+ if (value === null || value === undefined) return includeEmpty ? "" : undefined;
+ const stringValue = String(value);
+ return includeEmpty || stringValue.trim() ? stringValue : undefined;
+}
+
+export function createModelParameterValues(model, previousValues = {}) {
+ const values = {};
+ for (const { key, schema } of getSupplementalModelInputs(model)) {
+ const source = Object.hasOwn(previousValues, key)
+ ? previousValues[key]
+ : defaultValue(schema);
+ const normalized = normalizeValue(source, schema, { includeEmpty: true });
+ values[key] = normalized === undefined ? defaultValue(schema) : normalized;
+ }
+ return values;
+}
+
+export function buildSupplementalInputPayload(model, values = {}) {
+ const payload = {};
+ for (const { key, schema } of getSupplementalModelInputs(model)) {
+ if (!Object.hasOwn(values, key)) continue;
+ const normalized = normalizeValue(values[key], schema);
+ const isEmptyArray = Array.isArray(normalized) && normalized.length === 0;
+ if (normalized !== undefined && normalized !== "" && !isEmptyArray) {
+ payload[key] = normalized;
+ }
+ }
+ return payload;
+}
diff --git a/packages/studio/src/models.js b/packages/studio/src/models.js
index 79bb3d12..939813e0 100644
--- a/packages/studio/src/models.js
+++ b/packages/studio/src/models.js
@@ -1,3 +1,5 @@
+import { getMediaCapability } from "./modelCapabilities.js";
+
// Auto-generated from models_dump.json
export const t2iModels = [
{
@@ -7342,6 +7344,7 @@ export const t2vModels = [
"id": "seedance-2-mini-omni-reference",
"name": "Seedance 2 Mini Omni Reference",
"endpoint": "seedance-2-mini-omni-reference",
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [
@@ -7815,13 +7818,28 @@ export const getAspectRatiosForVideoModel = (modelId) => {
return ['16:9', '9:16', '1:1'];
};
+const getInputOptions = (input) => {
+ if (!input) return [];
+ if (input.enum) return input.enum;
+ if (input.minValue !== undefined && input.maxValue !== undefined) {
+ const step = input.step ?? 1;
+ const precision = Math.max(
+ String(input.minValue).split('.')[1]?.length || 0,
+ String(step).split('.')[1]?.length || 0,
+ );
+ const count = Math.floor((input.maxValue - input.minValue) / step + 1e-9);
+ return Array.from(
+ { length: count + 1 },
+ (_, index) => Number((input.minValue + index * step).toFixed(precision)),
+ );
+ }
+ return input.default !== undefined ? [input.default] : [];
+};
+
export const getDurationsForModel = (modelId) => {
const model = getVideoModelById(modelId);
if (!model) return [5];
- const durInput = model.inputs?.duration;
- if (durInput && durInput.enum) return durInput.enum;
- if (durInput) return [durInput.default || 5];
- return [];
+ return getInputOptions(model.inputs?.duration);
};
export const getResolutionsForVideoModel = (modelId) => {
@@ -8174,7 +8192,7 @@ export const i2iModels = [
},
{
"id": "gpt4o-edit",
- "name": "GPT-4o Edit",
+ "name": "GPT-4o Mask Edit",
"endpoint": "gpt4o-edit",
"family": "gpt",
"imageField": "image_url",
@@ -11604,6 +11622,7 @@ export const i2vModels = [
"family": "wan2.1",
"imageField": "image_url",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -11796,6 +11815,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -11840,6 +11860,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -11884,6 +11905,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -11928,6 +11950,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -12168,6 +12191,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "end_image_url",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -12212,6 +12236,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "end_image_url",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -12316,6 +12341,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -12475,6 +12501,7 @@ export const i2vModels = [
"family": "bytedance",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"maxImages": 4,
"inputs": {
"prompt": {
@@ -12518,6 +12545,7 @@ export const i2vModels = [
"family": "wan2.1",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"maxImages": 5,
"inputs": {
"prompt": {
@@ -12854,6 +12882,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -12907,6 +12936,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -12960,6 +12990,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -13009,6 +13040,7 @@ export const i2vModels = [
"family": "veo3.1",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"maxImages": 3,
"inputs": {
"prompt": {
@@ -13194,6 +13226,7 @@ export const i2vModels = [
"family": "vidu-q2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"maxImages": 7,
"inputs": {
"prompt": {
@@ -13267,6 +13300,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -13330,6 +13364,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -13525,6 +13560,7 @@ export const i2vModels = [
"family": "grok",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"maxImages": 7,
"inputs": {
"prompt": {
@@ -13572,6 +13608,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -13615,7 +13652,9 @@ export const i2vModels = [
"endpoint": "kling-o1-reference-to-video",
"family": "kling-o1",
"imageField": "images_list",
+ "videoField": "video_url",
"hasPrompt": true,
+ "promptRequired": true,
"maxImages": 7,
"inputs": {
"prompt": {
@@ -13667,6 +13706,7 @@ export const i2vModels = [
"family": "kling-v2.6",
"imageField": "image_url",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -13808,6 +13848,7 @@ export const i2vModels = [
"family": "wan2.2",
"imageField": "image_url",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -13907,6 +13948,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -13939,6 +13981,7 @@ export const i2vModels = [
"family": "kling-o1",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"maxImages": 7,
"inputs": {
"prompt": {
@@ -13985,6 +14028,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -14058,6 +14102,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -14172,6 +14217,7 @@ export const i2vModels = [
"family": "kling-v3.0-omni",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"maxImages": 4,
"inputs": {
"prompt": {
@@ -14235,6 +14281,7 @@ export const i2vModels = [
"family": "kling-v3.0-omni",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"maxImages": 4,
"inputs": {
"prompt": {
@@ -14298,6 +14345,7 @@ export const i2vModels = [
"family": "kling-v3.0-omni",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"maxImages": 4,
"inputs": {
"prompt": {
@@ -14355,6 +14403,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -14394,6 +14443,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -14488,6 +14538,7 @@ export const i2vModels = [
"family": "sd-v2.0",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [
@@ -14552,6 +14603,7 @@ export const i2vModels = [
"family": "ltx2.3",
"imageField": "image_url",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [
@@ -14858,6 +14910,7 @@ export const i2vModels = [
"family": "sd-v2.0",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [
@@ -14953,6 +15006,7 @@ export const i2vModels = [
"family": "pixverse-v6",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -15031,6 +15085,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -15146,6 +15201,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [],
@@ -15216,6 +15272,7 @@ export const i2vModels = [
"family": "wan2.7",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -15312,6 +15369,7 @@ export const i2vModels = [
"family": "sd-v2.0",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [
@@ -15380,6 +15438,7 @@ export const i2vModels = [
"family": "sd-v2.0",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [
@@ -15473,6 +15532,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -15533,6 +15593,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -15593,6 +15654,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -15654,6 +15716,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -15715,6 +15778,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -15786,6 +15850,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -15857,6 +15922,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -15924,6 +15990,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -15991,6 +16058,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -16059,6 +16127,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -16127,6 +16196,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -16211,6 +16281,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -16470,6 +16541,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"images_list": {
"examples": [
@@ -16530,6 +16602,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"images_list": {
"examples": [
@@ -16590,6 +16663,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -16674,6 +16748,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -16758,6 +16833,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -16820,6 +16896,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [
@@ -16878,6 +16955,7 @@ export const i2vModels = [
"family": "vidu-q3-pro",
"imageField": "image_url",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [
@@ -16954,6 +17032,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [
@@ -17039,6 +17118,7 @@ export const i2vModels = [
"family": "vidu-q3-turbo",
"imageField": "image_url",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [
@@ -17115,6 +17195,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [
@@ -17200,6 +17281,7 @@ export const i2vModels = [
"family": "vidu-q2",
"imageField": "image_url",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [
@@ -17284,6 +17366,7 @@ export const i2vModels = [
"family": "vidu-q2",
"imageField": "image_url",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"examples": [
@@ -17368,6 +17451,7 @@ export const i2vModels = [
"family": "happy-horse-1",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -17438,6 +17522,7 @@ export const i2vModels = [
"family": "happy-horse-1",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -17508,6 +17593,7 @@ export const i2vModels = [
"family": "gemini-omni",
"imageField": "image_urls",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -17681,6 +17767,7 @@ export const i2vModels = [
"family": "kling-v3.0",
"imageField": "image_url",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -17722,6 +17809,7 @@ export const i2vModels = [
"family": "kling-v3.0",
"imageField": "image_url",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -18153,6 +18241,7 @@ export const i2vModels = [
"family": "happy-horse-1.1",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -18223,6 +18312,7 @@ export const i2vModels = [
"family": "happy-horse-1.1",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -18293,6 +18383,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"images_list": {
"examples": [
@@ -18353,6 +18444,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -18414,6 +18506,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -18984,6 +19077,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -19051,6 +19145,7 @@ export const i2vModels = [
"family": "sd-2",
"imageField": "images_list",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -19204,6 +19299,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image_url",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -19248,6 +19344,7 @@ export const i2vModels = [
"family": "minimax-h3",
"imageField": "reference_images",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -19309,6 +19406,7 @@ export const i2vModels = [
"imageField": "image_url",
"lastImageField": "last_image",
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -19354,6 +19452,7 @@ export const i2vModels = [
"imageField": "images_list",
"maxImages": 9,
"hasPrompt": true,
+ "promptRequired": true,
"inputs": {
"prompt": {
"type": "string",
@@ -19417,12 +19516,7 @@ export const getI2VModelById = (id) => i2vModels.find(m => m.id === id);
export const getMaxImagesForI2VModel = (modelId) => {
const model = getI2VModelById(modelId);
- if (!model) return 1;
- if (model.maxImages) return model.maxImages;
- const imageInput = model.inputs?.[model.imageField];
- if (imageInput?.type === 'array') return imageInput.maxItems || 1;
- if (model.lastImageField) return 2;
- return 1;
+ return model ? getMediaCapability(model, 'image').maxItems : 1;
};
export const getAspectRatiosForI2IModel = (modelId) => {
@@ -19442,16 +19536,7 @@ export const getAspectRatiosForI2VModel = (modelId) => {
export const getDurationsForI2VModel = (modelId) => {
const model = getI2VModelById(modelId);
if (!model) return [];
- const dur = model.inputs && model.inputs.duration;
- if (!dur) return [];
- if (dur.enum) return dur.enum;
- if (dur.minValue !== undefined && dur.maxValue !== undefined && dur.step) {
- const vals = [];
- for (let v = dur.minValue; v <= dur.maxValue; v += dur.step) vals.push(v);
- return vals;
- }
- if (dur.default) return [dur.default];
- return [];
+ return getInputOptions(model.inputs?.duration);
};
export const getResolutionsForI2VModel = (modelId) => {
@@ -19473,14 +19558,6 @@ export const getDefaultEffectForI2VModel = (modelId) => {
return model?.inputs?.name?.default || null;
};
-export const getModesForModel = (modelId) => {
- const model = [...t2vModels, ...i2vModels].find(m => m.id === modelId);
- if (!model) return [];
- const modeInput = model.inputs?.mode;
- if (modeInput?.enum) return modeInput.enum;
- return [];
-};
-
export const getResolutionsForI2IModel = (modelId) => {
const model = getI2IModelById(modelId);
if (!model) return [];
@@ -19529,7 +19606,7 @@ export const getQualityFieldForI2IModel = (modelId) => {
// Returns the maximum number of images an i2i model accepts (defaults to 1)
export const getMaxImagesForI2IModel = (modelId) => {
const model = getI2IModelById(modelId);
- return model?.maxImages || 1;
+ return model ? getMediaCapability(model, 'image').maxItems : 1;
};
// ─── Video-to-Video models ────────────────────────────────────────────────────
@@ -19658,6 +19735,7 @@ export const v2vModels = [
"family": "wan2.2",
"videoField": "video_url",
"hasPrompt": true,
+ "promptRequired": true,
"description": "Easily modify existing videos using simple text commands.",
"provider": "alibaba",
"provider_name": "Alibaba"
@@ -19712,7 +19790,25 @@ export const v2vModels = [
"endpoint": "kling-o1-video-edit",
"family": "kling-o1",
"videoField": "video_url",
+ "imageField": "images_list",
+ "maxImages": 4,
"hasPrompt": true,
+ "promptRequired": true,
+ "required": [
+ "prompt",
+ "images_list",
+ "video_url"
+ ],
+ "inputs": {
+ "images_list": {
+ "field": "images_list",
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "maxItems": 4
+ }
+ },
"description": "Kling O1 Video Edit lets you send an existing video clip plus an instruction/prompt to edit or transform the clip while preserving temporal coherence and subject identity.",
"provider": "kling",
"provider_name": "Kling AI"
@@ -19723,7 +19819,25 @@ export const v2vModels = [
"endpoint": "kling-o1-video-edit-fast",
"family": "kling-o1",
"videoField": "video_url",
+ "imageField": "images_list",
+ "maxImages": 4,
"hasPrompt": true,
+ "promptRequired": true,
+ "required": [
+ "prompt",
+ "images_list",
+ "video_url"
+ ],
+ "inputs": {
+ "images_list": {
+ "field": "images_list",
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "maxItems": 4
+ }
+ },
"description": "Video Edit Fast is the lightweight, high-speed editing mode of Kling O1.",
"provider": "kling",
"provider_name": "Kling AI"
@@ -19734,7 +19848,25 @@ export const v2vModels = [
"endpoint": "kling-o1-standard-video-edit",
"family": "kling-o1",
"videoField": "video_url",
+ "imageField": "images_list",
+ "maxImages": 4,
"hasPrompt": true,
+ "promptRequired": true,
+ "required": [
+ "prompt",
+ "images_list",
+ "video_url"
+ ],
+ "inputs": {
+ "images_list": {
+ "field": "images_list",
+ "type": "array",
+ "items": {
+ "type": "string"
+ },
+ "maxItems": 4
+ }
+ },
"description": "Kling O1 Standard Video-to-Video Edit modifies an existing video while preserving its original structure, motion, and realism.",
"provider": "kling",
"provider_name": "Kling AI"
@@ -19746,6 +19878,7 @@ export const v2vModels = [
"family": "wan2.2",
"videoField": "video_url",
"hasPrompt": true,
+ "promptRequired": true,
"description": "Wan-2.2-spicy Video Extend continues an existing video by generating new frames that match the original style but add stronger motion, bolder effects, and spicier dramatics.",
"provider": "alibaba",
"provider_name": "Alibaba"
@@ -19757,6 +19890,7 @@ export const v2vModels = [
"family": "seedance-v1.5-pro",
"videoField": "video_url",
"hasPrompt": true,
+ "promptRequired": true,
"description": "Seedance v1.5 Pro Video Extend continues an existing video by generating additional frames that match the original scene’s style, lighting, motion, and mood.",
"provider": "bytedance",
"provider_name": "ByteDance"
@@ -19768,6 +19902,7 @@ export const v2vModels = [
"family": "seedance-v1.5-pro",
"videoField": "video_url",
"hasPrompt": true,
+ "promptRequired": true,
"description": "Seedance v1.5 Pro Video Extend Fast quickly extends an existing video by generating a short continuation that matches the original style, motion, and lighting.",
"provider": "bytedance",
"provider_name": "ByteDance"
@@ -19845,7 +19980,9 @@ export const v2vModels = [
"endpoint": "wan2.7-video-extend",
"family": "wan2.7",
"videoField": "video_url",
+ "audioField": "audio_url",
"hasPrompt": true,
+ "promptRequired": true,
"description": "Extend existing videos seamlessly with Wan 2.7.",
"provider": "alibaba",
"provider_name": "Alibaba"
@@ -19856,7 +19993,10 @@ export const v2vModels = [
"endpoint": "wan2.7-video-edit",
"family": "wan2.7",
"videoField": "video_url",
+ "imageField": "images_list",
+ "maxImages": 4,
"hasPrompt": true,
+ "promptRequired": true,
"description": "Perform prompt-driven video editing with multi-image reference support.",
"provider": "alibaba",
"provider_name": "Alibaba"
@@ -19867,7 +20007,10 @@ export const v2vModels = [
"endpoint": "happy-horse-1-video-edit-1080p",
"family": "happy-horse-1",
"videoField": "video_url",
+ "imageField": "images_list",
+ "maxImages": 5,
"hasPrompt": true,
+ "promptRequired": true,
"description": "Happy Horse 1.0 Video Edit (1080p) - modify an input video at 1080p using a natural-language instruction with optional reference images.",
"provider": "happy-horse",
"provider_name": "Happy Horse"
@@ -19878,7 +20021,10 @@ export const v2vModels = [
"endpoint": "happy-horse-1-video-edit-720p",
"family": "happy-horse-1",
"videoField": "video_url",
+ "imageField": "images_list",
+ "maxImages": 5,
"hasPrompt": true,
+ "promptRequired": true,
"description": "Happy Horse 1.0 Video Edit (720p) - modify an input video at 720p using a natural-language instruction with optional reference images.",
"provider": "happy-horse",
"provider_name": "Happy Horse"
@@ -19911,7 +20057,10 @@ export const v2vModels = [
"endpoint": "gemini-omni-video-edit",
"family": "gemini-omni",
"videoField": "video_url",
+ "imageField": "image_urls",
+ "maxImages": 7,
"hasPrompt": true,
+ "promptRequired": true,
"description": "Gemini Omni Video Edit — natively multimodal video-to-video editing.",
"provider": "google",
"provider_name": "Google"
diff --git a/packages/studio/src/muapi.js b/packages/studio/src/muapi.js
index 1bef9fec..56241d91 100644
--- a/packages/studio/src/muapi.js
+++ b/packages/studio/src/muapi.js
@@ -1,4 +1,6 @@
import { getModelById, getVideoModelById, getI2IModelById, getI2VModelById, getV2VModelById, getRecastModelById, getLipSyncModelById, getAudioModelById } from './models.js';
+import { mapReferenceParams } from './modelCapabilities.js';
+import { buildSupplementalInputPayload } from './modelParameters.js';
// In an http(s) browser we route through the host app's proxy (Next.js routes
// under /api/* re-issue the call server-side) so api.muapi.ai CORS is bypassed.
@@ -14,6 +16,21 @@ function notifyAuthRequired(status, detail) {
window.dispatchEvent(new CustomEvent('muapi:auth-required', { detail: { status, message: detail } }));
}
+function assertRequiredPrompt(model, params) {
+ if (model?.promptRequired && !String(params.prompt || '').trim()) {
+ throw new Error('Prompt is required for this model.');
+ }
+}
+
+function includeRequiredArrayDefaults(model, payload) {
+ const defaults = {};
+ for (const field of model?.required || []) {
+ if (payload[field] !== undefined || model?.inputs?.[field]?.type !== 'array') continue;
+ defaults[field] = [];
+ }
+ return Object.keys(defaults).length > 0 ? { ...defaults, ...payload } : payload;
+}
+
async function pollForResult(requestId, key, maxAttempts = 900, interval = 2000) {
const pollUrl = `${BASE_URL}/api/v1/predictions/${requestId}/result`;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
@@ -63,7 +80,10 @@ async function submitAndPoll(endpoint, payload, key, onRequestId, maxAttempts =
export async function generateImage(apiKey, params) {
const modelInfo = getModelById(params.model);
const endpoint = modelInfo?.endpoint || params.model;
- const payload = { prompt: params.prompt };
+ const payload = {
+ ...buildSupplementalInputPayload(modelInfo, params),
+ prompt: params.prompt
+ };
if (params.aspect_ratio) payload.aspect_ratio = params.aspect_ratio;
if (params.resolution) payload.resolution = params.resolution;
if (params.quality) payload.quality = params.quality;
@@ -82,14 +102,11 @@ export async function generateImage(apiKey, params) {
export async function generateI2I(apiKey, params) {
const modelInfo = getI2IModelById(params.model);
const endpoint = modelInfo?.endpoint || params.model;
- const payload = {};
+ const payload = {
+ ...mapReferenceParams(modelInfo, params),
+ ...buildSupplementalInputPayload(modelInfo, params)
+ };
if (params.prompt) payload.prompt = params.prompt;
- const imageField = modelInfo?.imageField || 'image_url';
- const imagesList = params.images_list?.length > 0 ? params.images_list : (params.image_url ? [params.image_url] : null);
- if (imagesList) {
- if (imageField === 'images_list') payload.images_list = imagesList;
- else payload[imageField] = imagesList[0];
- }
if (modelInfo?.swapField && params.swap_url) {
payload[modelInfo.swapField] = params.swap_url;
}
@@ -119,7 +136,11 @@ export async function decomposeLayers(apiKey, params) {
export async function generateVideo(apiKey, params) {
const modelInfo = getVideoModelById(params.model);
const endpoint = modelInfo?.endpoint || params.model;
- const payload = {};
+ assertRequiredPrompt(modelInfo, params);
+ let payload = {
+ ...mapReferenceParams(modelInfo, params),
+ ...buildSupplementalInputPayload(modelInfo, params)
+ };
if (params.prompt) payload.prompt = params.prompt;
if (params.request_id) payload.request_id = params.request_id;
if (params.aspect_ratio) payload.aspect_ratio = params.aspect_ratio;
@@ -127,40 +148,19 @@ export async function generateVideo(apiKey, params) {
if (params.resolution) payload.resolution = params.resolution;
if (params.quality) payload.quality = params.quality;
if (params.mode) payload.mode = params.mode;
- if (params.image_url) payload.image_url = params.image_url;
- if (params.images_list?.length > 0) payload.images_list = params.images_list;
- if (params.videos_list?.length > 0) payload.videos_list = params.videos_list;
+ payload = includeRequiredArrayDefaults(modelInfo, payload);
return submitAndPoll(endpoint, payload, apiKey, params.onRequestId, 900);
}
export async function generateI2V(apiKey, params) {
const modelInfo = getI2VModelById(params.model);
const endpoint = modelInfo?.endpoint || params.model;
- const payload = {};
+ assertRequiredPrompt(modelInfo, params);
+ let payload = {
+ ...mapReferenceParams(modelInfo, params),
+ ...buildSupplementalInputPayload(modelInfo, params)
+ };
if (params.prompt) payload.prompt = params.prompt;
- const imageField = modelInfo?.imageField || 'image_url';
- const imageInput = modelInfo?.inputs?.[imageField];
- const imageUrls = params.images_list?.length > 0
- ? params.images_list
- : (params.image_url ? [params.image_url] : []);
- if (imageUrls.length > 0) {
- if (imageInput?.type === 'array' || imageField === 'images_list') {
- payload[imageField] = imageUrls;
- } else {
- payload[imageField] = imageUrls[0];
- }
- }
- const lastImageField = modelInfo?.lastImageField;
- if (lastImageField && params.last_image) {
- if (lastImageField === 'images_list') {
- if (!payload.images_list) payload.images_list = [];
- if (payload.images_list.indexOf(params.last_image) === -1) {
- payload.images_list.push(params.last_image);
- }
- } else {
- payload[lastImageField] = params.last_image;
- }
- }
if (params.aspect_ratio) payload.aspect_ratio = params.aspect_ratio;
if (params.duration) payload.duration = params.duration;
if (params.resolution) payload.resolution = params.resolution;
@@ -169,6 +169,7 @@ export async function generateI2V(apiKey, params) {
if (modelInfo?.inputs?.name) {
payload.name = params.name || modelInfo.inputs.name.default;
}
+ payload = includeRequiredArrayDefaults(modelInfo, payload);
return submitAndPoll(endpoint, payload, apiKey, params.onRequestId, 900);
}
@@ -187,14 +188,15 @@ export async function generateMarketingStudioAd(apiKey, params) {
export async function processV2V(apiKey, params) {
const modelInfo = getV2VModelById(params.model);
const endpoint = modelInfo?.endpoint || params.model;
- const videoField = modelInfo?.videoField || 'video_url';
- const payload = { [videoField]: params.video_url };
- if (modelInfo?.imageField && params.image_url) {
- payload[modelInfo.imageField] = params.image_url;
- }
+ assertRequiredPrompt(modelInfo, params);
+ let payload = {
+ ...mapReferenceParams(modelInfo, params),
+ ...buildSupplementalInputPayload(modelInfo, params)
+ };
if (modelInfo?.hasPrompt && params.prompt) {
payload.prompt = params.prompt;
}
+ payload = includeRequiredArrayDefaults(modelInfo, payload);
return submitAndPoll(endpoint, payload, apiKey, params.onRequestId, 900);
}
@@ -916,5 +918,3 @@ export async function expandImage(apiKey, { image_url, onRequestId }) {
const payload = { image_url };
return submitAndPoll(endpoint, payload, apiKey, onRequestId, 90);
}
-
-
diff --git a/packages/studio/src/videoWorkflows.js b/packages/studio/src/videoWorkflows.js
new file mode 100644
index 00000000..a68cfab7
--- /dev/null
+++ b/packages/studio/src/videoWorkflows.js
@@ -0,0 +1,1032 @@
+import { getModelMediaCapabilities } from "./modelCapabilities.js";
+import {
+ videoModelCatalog,
+ videoModelPickerEntryByVariantId,
+} from "./modelFamilies.js";
+
+export const VIDEO_WORKFLOW_IDS = Object.freeze([
+ "animate_image",
+ "keyframes",
+ "references",
+ "edit_video",
+ "extend_uploaded_video",
+ "motion_transfer",
+]);
+
+const WORKFLOW_DEFINITIONS = Object.freeze({
+ animate_image: { id: "animate_image", label: "Animate Image" },
+ keyframes: { id: "keyframes", label: "Start & End Frames" },
+ references: { id: "references", label: "References" },
+ edit_video: { id: "edit_video", label: "Edit Video" },
+ extend_uploaded_video: {
+ id: "extend_uploaded_video",
+ label: "Extend Video",
+ },
+ motion_transfer: { id: "motion_transfer", label: "Motion Transfer" },
+});
+
+const WORKFLOW_REQUIRED_MEDIA = Object.freeze({
+ animate_image: Object.freeze({
+ startFrame: "Please upload an image to animate.",
+ }),
+ keyframes: Object.freeze({
+ startFrame: "Please upload a start frame.",
+ endFrame: "Please upload an end frame.",
+ }),
+ edit_video: Object.freeze({
+ sourceVideo: "Please upload a source video.",
+ }),
+ extend_uploaded_video: Object.freeze({
+ sourceVideo: "Please upload a source video.",
+ }),
+ motion_transfer: Object.freeze({
+ characterImage: "Please upload a character image.",
+ drivingVideo: "Please upload a motion video.",
+ }),
+});
+
+// Opt-in only: models outside this registry retain their existing behavior.
+export const VIDEO_WORKFLOW_VARIANTS = Object.freeze({
+ "kling-v3": {
+ animate_image: [
+ "kling-v3-turbo-pro-image-to-video",
+ "kling-v3-turbo-standard-image-to-video",
+ "kling-v3.0-4k-image-to-video",
+ "kling-v3.0-standard-image-to-video",
+ "kling-v3.0-pro-image-to-video",
+ ],
+ keyframes: [
+ "kling-v3.0-4k-image-to-video",
+ "kling-v3.0-standard-image-to-video",
+ "kling-v3.0-pro-image-to-video",
+ ],
+ references: [
+ "kling-v3.0-omni-4k-image-to-video",
+ "kling-v3.0-omni-pro-image-to-video",
+ "kling-v3.0-omni-standard-image-to-video",
+ ],
+ motion_transfer: [
+ "kling-v3.0-pro-motion-control",
+ "kling-v3.0-std-motion-control",
+ ],
+ },
+ "minimax-h3": {
+ animate_image: ["minimax-h3-open-image-to-video", "minimax-h3-image-to-video"],
+ keyframes: ["minimax-h3-open-image-to-video", "minimax-h3-image-to-video"],
+ references: [
+ "minimax-h3-open-reference-to-video",
+ "minimax-h3-reference-to-video",
+ ],
+ },
+ "seedance-2": {
+ animate_image: [
+ "seedance-2-i2v",
+ "seedance-2-i2v-480p",
+ "seedance-2-image-to-video",
+ "seedance-2-image-to-video-fast",
+ "seedance-2-vip-image-to-video",
+ "seedance-2-vip-image-to-video-fast",
+ "seedance-2-vip-image-to-video-1080p",
+ "seedance-2-vip-image-to-video-fast-1080p",
+ "seedance-2-vip-image-to-video-4k",
+ "seedance-2-mini-image-to-video",
+ "seedance-2-spicy-image-to-video",
+ "seedance-2-spicy-image-to-video-fast",
+ "seedance-2-mini-spicy-image-to-video",
+ ],
+ keyframes: [
+ "seedance-2-new-first-last",
+ "seedance-2-first-last-frame",
+ "seedance-2-first-last-frame-fast",
+ "seedance-2-vip-first-last-frame",
+ "seedance-2-vip-first-last-frame-fast",
+ "seedance-2-vip-first-last-frame-1080p",
+ "seedance-2-vip-first-last-frame-4k",
+ ],
+ references: [
+ "seedance-2-new-omni",
+ "seedance-2-omni-reference",
+ "seedance-2-omni-reference-480p",
+ "seedance-2-omni-reference-no-video",
+ "seedance-2-omni-reference-no-video-fast",
+ "seedance-2-vip-omni-reference",
+ "seedance-2-vip-omni-reference-fast",
+ "seedance-2-vip-omni-reference-1080p",
+ "seedance-2-vip-omni-reference-fast-1080p",
+ "seedance-2-vip-omni-reference-4k",
+ "seedance-2-mini-omni-reference",
+ ],
+ },
+ "gemini-omni": {
+ animate_image: ["gemini-omni-image-to-video"],
+ references: ["gemini-omni-image-to-video"],
+ edit_video: ["gemini-omni-video-edit"],
+ },
+ "grok-imagine-video": {
+ animate_image: ["grok-imagine-video-1-5-preview"],
+ references: ["grok-imagine-image-to-video"],
+ },
+ "veo-3.1": {
+ animate_image: [
+ "veo3.1-image-to-video",
+ "veo3.1-fast-image-to-video",
+ "veo3.1-lite-image-to-video",
+ ],
+ keyframes: [
+ "veo3.1-image-to-video",
+ "veo3.1-fast-image-to-video",
+ "veo3.1-lite-image-to-video",
+ ],
+ references: ["veo3.1-reference-to-video"],
+ },
+ "wan-2.7": {
+ animate_image: ["wan2.7-image-to-video"],
+ keyframes: ["wan2.7-image-to-video"],
+ references: ["wan2.7-reference-to-video"],
+ edit_video: ["wan2.7-video-edit"],
+ extend_uploaded_video: ["wan2.7-video-extend"],
+ },
+ "vidu-q3": {
+ animate_image: ["vidu-q3-turbo-image-to-video", "vidu-q3-pro-image-to-video"],
+ keyframes: ["vidu-q3-turbo-first-last-frames", "vidu-q3-pro-first-last-frames"],
+ },
+ "vidu-q2": {
+ animate_image: ["vidu-q2-turbo-image-to-video", "vidu-q2-pro-image-to-video"],
+ keyframes: ["vidu-q2-pro-start-end-video", "vidu-q2-turbo-start-end-video"],
+ references: ["vidu-q2-reference"],
+ },
+ "pixverse-6": {
+ animate_image: ["pixverse-v6-i2v"],
+ keyframes: ["pixverse-v6-transition"],
+ },
+ "kling-o1": {
+ animate_image: ["kling-o1-standard-image-to-video", "kling-o1-image-to-video"],
+ keyframes: ["kling-o1-standard-image-to-video", "kling-o1-image-to-video"],
+ references: ["kling-o1-standard-reference-to-video", "kling-o1-reference-to-video"],
+ edit_video: [
+ "kling-o1-standard-video-edit",
+ "kling-o1-video-edit-fast",
+ "kling-o1-video-edit",
+ ],
+ },
+ "happy-horse-1": {
+ animate_image: [
+ "happy-horse-1-image-to-video-720p",
+ "happy-horse-1-image-to-video-1080p",
+ ],
+ references: [
+ "happy-horse-1-reference-to-video-720p",
+ "happy-horse-1-reference-to-video-1080p",
+ ],
+ edit_video: [
+ "happy-horse-1-video-edit-720p",
+ "happy-horse-1-video-edit-1080p",
+ ],
+ },
+ "happy-horse-1.1": {
+ animate_image: [
+ "happy-horse-1.1-image-to-video-720p",
+ "happy-horse-1.1-image-to-video-1080p",
+ ],
+ references: [
+ "happy-horse-1.1-reference-to-video-720p",
+ "happy-horse-1.1-reference-to-video-1080p",
+ ],
+ },
+ "kling-v2.6": {
+ animate_image: ["kling-v2.6-pro-i2v"],
+ motion_transfer: ["kling-v2.6-pro-motion-control", "kling-v2.6-std-motion-control"],
+ },
+ "ltx-2.3": {
+ animate_image: ["ltx-2.3-image-to-video"],
+ extend_uploaded_video: ["ltx-2.3-video-extend"],
+ },
+ "seedance-1.5": {
+ animate_image: ["seedance-v1.5-pro-i2v-fast", "seedance-v1.5-pro-i2v"],
+ keyframes: ["seedance-v1.5-pro-i2v-fast", "seedance-v1.5-pro-i2v"],
+ extend_uploaded_video: [
+ "seedance-v1.5-pro-video-extend-fast",
+ "seedance-v1.5-pro-video-extend",
+ ],
+ },
+ "wan-2.2": {
+ animate_image: ["wan2.2-spicy-image-to-video", "wan2.2-image-to-video"],
+ keyframes: ["wan2.2-image-to-video"],
+ edit_video: ["wan2.2-edit-video"],
+ extend_uploaded_video: ["wan2.2-spicy-video-extend"],
+ },
+ "wan-2.1": {
+ animate_image: ["wan2.1-image-to-video"],
+ references: ["wan2.1-reference-video"],
+ },
+ "seedance-lite": {
+ animate_image: ["seedance-lite-i2v"],
+ keyframes: ["seedance-lite-i2v"],
+ references: ["seedance-lite-reference-video"],
+ },
+ "minimax-hailuo-02": {
+ animate_image: ["minimax-hailuo-02-pro-i2v", "minimax-hailuo-02-standard-i2v"],
+ keyframes: ["minimax-hailuo-02-pro-i2v", "minimax-hailuo-02-standard-i2v"],
+ },
+ "kling-v2.1": {
+ animate_image: [
+ "kling-v2.1-pro-i2v",
+ "kling-v2.1-standard-i2v",
+ "kling-v2.1-master-i2v",
+ ],
+ keyframes: ["kling-v2.1-pro-i2v"],
+ },
+});
+
+const TECHNICAL_EXCLUDED_VARIANTS = Object.freeze({
+ "kling-v3": new Set([
+ "kling-v3.0-omni-4k-text-to-video",
+ "kling-v3.0-omni-pro-text-to-video",
+ "kling-v3.0-omni-standard-text-to-video",
+ ]),
+});
+
+function createVariantGroup(variants) {
+ const uniqueVariants = [];
+ const seen = new Set();
+ for (const variant of variants) {
+ if (seen.has(variant.model.id)) continue;
+ seen.add(variant.model.id);
+ uniqueVariants.push(variant);
+ }
+
+ return {
+ variants: uniqueVariants,
+ variantIds: new Set(uniqueVariants.map((variant) => variant.model.id)),
+ };
+}
+
+function createWorkflowCatalog() {
+ const familyById = new Map();
+
+ for (const [familyId, configuredWorkflows] of Object.entries(VIDEO_WORKFLOW_VARIANTS)) {
+ const family = videoModelCatalog.familyById.get(familyId);
+ if (!family) continue;
+
+ const workflows = [];
+ const workflowById = new Map();
+ const workflowIdsByVariantId = new Map();
+ const workflowVariantIds = new Set();
+
+ for (const workflowId of VIDEO_WORKFLOW_IDS) {
+ const variants = (configuredWorkflows[workflowId] || [])
+ .map((variantId) => videoModelCatalog.variantById.get(variantId))
+ .filter(
+ (variant) =>
+ variant &&
+ videoModelCatalog.familyByVariantId.get(variant.model.id)?.id === familyId,
+ );
+ if (variants.length === 0) continue;
+
+ const workflow = {
+ ...WORKFLOW_DEFINITIONS[workflowId],
+ ...createVariantGroup(variants),
+ };
+ workflows.push(workflow);
+ workflowById.set(workflowId, workflow);
+ for (const variant of variants) {
+ workflowVariantIds.add(variant.model.id);
+ const ids = workflowIdsByVariantId.get(variant.model.id) || [];
+ ids.push(workflowId);
+ workflowIdsByVariantId.set(variant.model.id, ids);
+ }
+ }
+
+ const excluded = TECHNICAL_EXCLUDED_VARIANTS[familyId] || new Set();
+ const base = createVariantGroup(
+ family.variants.t2v.filter(
+ (variant) =>
+ !workflowVariantIds.has(variant.model.id) &&
+ !excluded.has(variant.model.id) &&
+ !variant.model.requiresRequestId,
+ ),
+ );
+
+ const unmanagedByMode = new Map();
+ const unmanagedVariantIds = new Set();
+ for (const mode of ["t2v", "i2v", "v2v"]) {
+ const unmanaged = createVariantGroup(
+ family.variants[mode].filter(
+ (variant) =>
+ !base.variantIds.has(variant.model.id) &&
+ !workflowVariantIds.has(variant.model.id) &&
+ !excluded.has(variant.model.id) &&
+ !variant.model.requiresRequestId,
+ ),
+ );
+ if (unmanaged.variants.length > 0) {
+ unmanagedByMode.set(mode, unmanaged);
+ for (const variant of unmanaged.variants) {
+ unmanagedVariantIds.add(variant.model.id);
+ }
+ }
+ }
+
+ familyById.set(familyId, {
+ family,
+ familyId,
+ base,
+ hasBase: base.variants.length > 0,
+ workflows,
+ workflowById,
+ workflowIdsByVariantId,
+ unmanagedByMode,
+ unmanagedVariantIds,
+ });
+ }
+
+ return { familyById };
+}
+
+export const videoWorkflowCatalog = createWorkflowCatalog();
+
+export function getVideoWorkflowFamily(familyId) {
+ return videoWorkflowCatalog.familyById.get(familyId) || null;
+}
+
+export function getVideoWorkflowControlState(workflowFamilyOrId, variantId = null) {
+ const workflowFamily = typeof workflowFamilyOrId === "string"
+ ? getVideoWorkflowFamily(workflowFamilyOrId)
+ : workflowFamilyOrId;
+ if (!workflowFamily) return { kind: "hidden", workflow: null };
+
+ if (variantId && workflowFamily.unmanagedVariantIds?.has(variantId)) {
+ return { kind: "hidden", workflow: null };
+ }
+
+ if (!workflowFamily.hasBase && workflowFamily.workflows.length === 1) {
+ return { kind: "hidden", workflow: workflowFamily.workflows[0] };
+ }
+ if (workflowFamily.workflows.length === 1) {
+ return { kind: "direct", workflow: workflowFamily.workflows[0] };
+ }
+ if (workflowFamily.workflows.length > 1) {
+ return { kind: "menu", workflow: null };
+ }
+ return { kind: "hidden", workflow: null };
+}
+
+export function getVideoWorkflowControlLabel(workflow) {
+ return workflow?.label || "+ Source";
+}
+
+export function getVideoWorkflowGroup(familyId, workflowId = null) {
+ const workflowFamily = getVideoWorkflowFamily(familyId);
+ if (!workflowFamily) return null;
+ return workflowId === null
+ ? workflowFamily.base
+ : workflowFamily.workflowById.get(workflowId) || null;
+}
+
+function variantForId(group, variantId) {
+ return group?.variantIds.has(variantId)
+ ? videoModelCatalog.variantById.get(variantId) || null
+ : null;
+}
+
+function variantForPickerEntry(group, variantId) {
+ const entry = videoModelPickerEntryByVariantId.get(variantId);
+ if (!entry) return null;
+ return group.variants.find(
+ (candidate) => videoModelPickerEntryByVariantId.get(candidate.model.id) === entry,
+ ) || null;
+}
+
+const COMPATIBILITY_TOKENS = Object.freeze([
+ "4k",
+ "1080p",
+ "720p",
+ "480p",
+ "pro",
+ "standard",
+ "std",
+ "turbo",
+ "fast",
+ "lite",
+ "open",
+ "vip",
+ "mini",
+ "spicy",
+]);
+
+function variantCompatibilityTokens(variantId) {
+ const tokens = new Set(variantId.toLowerCase().split(/[^a-z0-9]+/));
+ if (tokens.has("std")) tokens.add("standard");
+ return COMPATIBILITY_TOKENS.filter((token) => tokens.has(token));
+}
+
+function variantForCompatibleId(group, variantId) {
+ if (!variantId) return null;
+ const expected = new Set(variantCompatibilityTokens(variantId));
+ if (expected.size === 0) return null;
+
+ let best = null;
+ let bestScore = -Infinity;
+ for (const candidate of group.variants) {
+ const candidateTokens = new Set(variantCompatibilityTokens(candidate.model.id));
+ let matches = 0;
+ for (const token of expected) matches += Number(candidateTokens.has(token));
+ const extras = [...candidateTokens].filter((token) => !expected.has(token)).length;
+ const missing = [...expected].filter((token) => !candidateTokens.has(token)).length;
+ const score = matches * 3 - extras - missing;
+ if (score > bestScore) {
+ best = candidate;
+ bestScore = score;
+ }
+ }
+ return bestScore > 0 ? best : null;
+}
+
+function resolveVariantFromGroup(group, currentVariantId, preferredVariantId) {
+ if (!group || group.variants.length === 0) return null;
+ return (
+ variantForId(group, preferredVariantId) ||
+ variantForId(group, currentVariantId) ||
+ variantForPickerEntry(group, preferredVariantId) ||
+ variantForPickerEntry(group, currentVariantId) ||
+ variantForCompatibleId(group, preferredVariantId) ||
+ variantForCompatibleId(group, currentVariantId) ||
+ group.variants[0]
+ );
+}
+
+function sameFamilyVariantId(familyId, variantId) {
+ return videoModelCatalog.familyByVariantId.get(variantId)?.id === familyId
+ ? variantId
+ : null;
+}
+
+export function resolveVideoWorkflowVariant(
+ familyId,
+ workflowId,
+ currentVariantId = null,
+ preferredVariantId = null,
+) {
+ const group = getVideoWorkflowGroup(familyId, workflowId);
+ if (!group) return null;
+ return resolveVariantFromGroup(
+ group,
+ sameFamilyVariantId(familyId, currentVariantId),
+ sameFamilyVariantId(familyId, preferredVariantId),
+ );
+}
+
+export function resolveVideoBaseVariant(
+ familyId,
+ currentVariantId = null,
+ preferredVariantId = null,
+) {
+ const group = getVideoWorkflowGroup(familyId, null);
+ if (!group) return null;
+ return resolveVariantFromGroup(
+ group,
+ sameFamilyVariantId(familyId, currentVariantId),
+ sameFamilyVariantId(familyId, preferredVariantId),
+ );
+}
+
+export function inferVideoWorkflowId(
+ familyId,
+ variantId,
+ { hasEndFrame = false } = {},
+) {
+ const ids = getVideoWorkflowFamily(familyId)?.workflowIdsByVariantId.get(variantId) || [];
+ if (hasEndFrame && ids.includes("keyframes")) return "keyframes";
+ if (ids.includes("animate_image")) return "animate_image";
+ return ids[0] || null;
+}
+
+export function resolvePersistedVideoWorkflowSelection(
+ variantId,
+ storedWorkflowId = null,
+ { hasEndFrame = false } = {},
+) {
+ const family = videoModelCatalog.familyByVariantId.get(variantId) || null;
+ const variant = videoModelCatalog.variantById.get(variantId) || null;
+ const workflowFamily = family ? getVideoWorkflowFamily(family.id) : null;
+ if (!family || !variant || !workflowFamily) {
+ return { family, variant, workflowId: null };
+ }
+
+ const storedWorkflow = workflowFamily.workflowById.get(storedWorkflowId);
+ const workflowId = storedWorkflow?.variantIds.has(variantId)
+ ? storedWorkflowId
+ : inferVideoWorkflowId(family.id, variantId, { hasEndFrame });
+ if (!workflowId) {
+ if (workflowFamily.unmanagedVariantIds.has(variantId)) {
+ return { family, variant, workflowId: null };
+ }
+ const baseVariant = resolveVideoBaseVariant(family.id, variantId);
+ return {
+ family,
+ variant: baseVariant || variant,
+ workflowId: null,
+ };
+ }
+
+ const resolved = resolveVideoWorkflowVariant(family.id, workflowId, variantId);
+ return {
+ family,
+ variant: resolved || variant,
+ workflowId: resolved ? workflowId : null,
+ };
+}
+
+export function getVideoWorkflowMediaConfig(model, workflowId) {
+ const capabilities = getModelMediaCapabilities(model);
+ const config = {
+ imageLimit: capabilities.image.maxItems,
+ videoLimit: capabilities.video.maxItems,
+ audioLimit: capabilities.audio.maxItems,
+ separateEndImage: capabilities.image.separateLastItem,
+ };
+
+ if (workflowId === "animate_image") {
+ return {
+ ...config,
+ imageLimit: Math.min(config.imageLimit, 1),
+ videoLimit: 0,
+ separateEndImage: false,
+ };
+ }
+ if (workflowId === "keyframes") {
+ return {
+ ...config,
+ imageLimit: Math.min(config.imageLimit, 1),
+ videoLimit: 0,
+ separateEndImage: true,
+ };
+ }
+ if (workflowId === "motion_transfer") {
+ return {
+ imageLimit: Math.min(config.imageLimit, 1),
+ videoLimit: Math.min(config.videoLimit, 1),
+ audioLimit: 0,
+ separateEndImage: false,
+ };
+ }
+ if (workflowId === "edit_video" || workflowId === "extend_uploaded_video") {
+ return {
+ ...config,
+ videoLimit: Math.min(config.videoLimit, 1),
+ separateEndImage: false,
+ };
+ }
+ return config;
+}
+
+function modelFamilyId(model) {
+ return videoModelCatalog.familyByVariantId.get(model?.id)?.id || null;
+}
+
+function providerField(model, field) {
+ if (!field) return null;
+ const declaredField = model?.inputs?.[field]?.field;
+ return declaredField && !["image", "video", "audio"].includes(declaredField)
+ ? declaredField
+ : field;
+}
+
+function mediaSlot(
+ workflowId,
+ id,
+ mediaType,
+ field,
+ label,
+ description,
+ maxItems,
+ options = {},
+) {
+ return Object.freeze({
+ id,
+ mediaType,
+ field,
+ label,
+ description,
+ maxItems,
+ required: Boolean(WORKFLOW_REQUIRED_MEDIA[workflowId]?.[id]),
+ isArray: false,
+ ...options,
+ });
+}
+
+const VISUAL_REFERENCE_SLOT_IDS = Object.freeze([
+ "referenceImages",
+ "referenceVideos",
+]);
+const MULTIMODAL_REFERENCE_SLOT_IDS = Object.freeze([
+ "referenceImages",
+ "referenceVideos",
+ "referenceAudios",
+]);
+const WAN_REFERENCE_CONSTRAINT = Object.freeze({
+ combinedSlotIds: VISUAL_REFERENCE_SLOT_IDS,
+ combinedLimit: 5,
+ requiredSlotIds: VISUAL_REFERENCE_SLOT_IDS,
+ combinedLimitMessage: "Wan 2.7 supports up to 5 references in total.",
+});
+const MINIMAX_H3_REFERENCE_CONSTRAINT = Object.freeze({
+ combinedSlotIds: MULTIMODAL_REFERENCE_SLOT_IDS,
+ combinedLimit: 12,
+ requiredSlotIds: VISUAL_REFERENCE_SLOT_IDS,
+ combinedLimitMessage: "MiniMax H3 supports up to 12 references in total.",
+});
+
+export function getVideoWorkflowMediaSlots(model, workflowId) {
+ if (!model || !workflowId) return [];
+ const capabilities = getModelMediaCapabilities(model);
+ const familyId = modelFamilyId(model);
+ const imageField = providerField(model, capabilities.image.field);
+ const videoField = providerField(model, capabilities.video.field);
+ const audioField = providerField(model, capabilities.audio.field);
+ const lastImageField = providerField(model, capabilities.image.lastField);
+ const createMediaSlot = (...args) => mediaSlot(workflowId, ...args);
+
+ if (workflowId === "animate_image") {
+ return [
+ imageField && createMediaSlot(
+ "startFrame",
+ "image",
+ imageField,
+ "Image",
+ "Image to animate",
+ 1,
+ { isArray: capabilities.image.isArray },
+ ),
+ audioField && createMediaSlot(
+ "referenceAudios",
+ "audio",
+ audioField,
+ "Audio",
+ "Guiding audio",
+ Math.max(capabilities.audio.maxItems, 1),
+ { isArray: capabilities.audio.isArray },
+ ),
+ ].filter(Boolean);
+ }
+ if (workflowId === "keyframes") {
+ if (!imageField) return [];
+ const sharedArrayField = capabilities.image.isArray && !lastImageField;
+ return [
+ createMediaSlot(
+ "startFrame",
+ "image",
+ imageField,
+ "Start",
+ "Start frame",
+ 1,
+ sharedArrayField
+ ? { index: 0, isArray: true }
+ : { isArray: capabilities.image.isArray },
+ ),
+ createMediaSlot(
+ "endFrame",
+ "image",
+ sharedArrayField ? imageField : lastImageField,
+ "End",
+ "End frame",
+ 1,
+ sharedArrayField ? { index: 1, isArray: true } : {},
+ ),
+ audioField && createMediaSlot(
+ "referenceAudios",
+ "audio",
+ audioField,
+ "Audio",
+ "Guiding audio",
+ Math.max(capabilities.audio.maxItems, 1),
+ { isArray: capabilities.audio.isArray },
+ ),
+ ].filter((slot) => slot?.field);
+ }
+ if (workflowId === "references") {
+ if (familyId === "wan-2.7") {
+ return [
+ createMediaSlot(
+ "anchorImage",
+ "image",
+ "image_url",
+ "Start",
+ "Start frame",
+ 1,
+ { acceptDrop: false },
+ ),
+ createMediaSlot(
+ "referenceImages",
+ "image",
+ "images_list",
+ "Image",
+ "Reference images",
+ 4,
+ { isArray: true, ...WAN_REFERENCE_CONSTRAINT },
+ ),
+ createMediaSlot(
+ "referenceVideos",
+ "video",
+ "videos_list",
+ "Video",
+ "Reference videos",
+ 4,
+ { isArray: true, ...WAN_REFERENCE_CONSTRAINT },
+ ),
+ ];
+ }
+ return [
+ imageField && createMediaSlot(
+ "referenceImages",
+ "image",
+ imageField,
+ "Image",
+ "Reference images",
+ Math.max(capabilities.image.maxItems, 1),
+ {
+ isArray: capabilities.image.isArray,
+ ...(familyId === "minimax-h3"
+ ? MINIMAX_H3_REFERENCE_CONSTRAINT
+ : {}),
+ },
+ ),
+ videoField && createMediaSlot(
+ "referenceVideos",
+ "video",
+ videoField,
+ "Video",
+ "Reference videos",
+ Math.max(capabilities.video.maxItems, 1),
+ {
+ isArray: capabilities.video.isArray,
+ ...(familyId === "minimax-h3"
+ ? MINIMAX_H3_REFERENCE_CONSTRAINT
+ : {}),
+ },
+ ),
+ audioField && createMediaSlot(
+ "referenceAudios",
+ "audio",
+ audioField,
+ "Audio",
+ "Reference audio",
+ Math.max(capabilities.audio.maxItems, 1),
+ {
+ isArray: capabilities.audio.isArray,
+ ...(familyId === "minimax-h3"
+ ? MINIMAX_H3_REFERENCE_CONSTRAINT
+ : {}),
+ },
+ ),
+ ].filter(Boolean);
+ }
+ if (workflowId === "edit_video") {
+ return [
+ videoField && createMediaSlot(
+ "sourceVideo",
+ "video",
+ videoField,
+ "Video",
+ "Video to edit",
+ 1,
+ { isArray: capabilities.video.isArray },
+ ),
+ imageField && createMediaSlot(
+ "referenceImages",
+ "image",
+ imageField,
+ "Image",
+ "Reference images",
+ Math.max(capabilities.image.maxItems, 1),
+ { isArray: capabilities.image.isArray },
+ ),
+ audioField && createMediaSlot(
+ "referenceAudios",
+ "audio",
+ audioField,
+ "Audio",
+ "Reference audio",
+ Math.max(capabilities.audio.maxItems, 1),
+ { isArray: capabilities.audio.isArray },
+ ),
+ ].filter(Boolean);
+ }
+ if (workflowId === "extend_uploaded_video") {
+ return [
+ videoField && createMediaSlot(
+ "sourceVideo",
+ "video",
+ videoField,
+ "Video",
+ "Video to extend",
+ 1,
+ { isArray: capabilities.video.isArray },
+ ),
+ audioField && createMediaSlot(
+ "referenceAudios",
+ "audio",
+ audioField,
+ "Audio",
+ "Reference audio",
+ 1,
+ { isArray: capabilities.audio.isArray },
+ ),
+ ].filter(Boolean);
+ }
+ if (workflowId === "motion_transfer") {
+ return [
+ imageField && createMediaSlot(
+ "characterImage",
+ "image",
+ imageField,
+ "Character",
+ "Character image",
+ 1,
+ { isArray: capabilities.image.isArray },
+ ),
+ videoField && createMediaSlot(
+ "drivingVideo",
+ "video",
+ videoField,
+ "Motion",
+ "Motion source video",
+ 1,
+ { isArray: capabilities.video.isArray },
+ ),
+ ].filter(Boolean);
+ }
+ return [];
+}
+
+export function getVideoWorkflowDraftKey(familyId, workflowId) {
+ return `${familyId}:${workflowId}`;
+}
+
+export function appendVideoWorkflowMedia(
+ drafts,
+ draftKey,
+ slot,
+ urls,
+ capacityMedia = null,
+) {
+ const currentDraft = drafts[draftKey] || {};
+ const currentValues = currentDraft[slot.id] || [];
+ const remaining = getVideoWorkflowSlotRemaining(
+ slot,
+ capacityMedia || currentDraft,
+ );
+ const existingUrls = new Set(currentValues);
+ const additions = [...new Set((urls || []).filter(Boolean))]
+ .filter((url) => !existingUrls.has(url))
+ .slice(0, remaining);
+ if (additions.length === 0) return drafts;
+ return {
+ ...drafts,
+ [draftKey]: {
+ ...currentDraft,
+ [slot.id]: [...currentValues, ...additions],
+ },
+ };
+}
+
+export function removeVideoWorkflowMedia(drafts, draftKey, slotId, index) {
+ const currentDraft = drafts[draftKey] || {};
+ const values = currentDraft[slotId] || [];
+ return {
+ ...drafts,
+ [draftKey]: {
+ ...currentDraft,
+ [slotId]: values.filter((_, itemIndex) => itemIndex !== index),
+ },
+ };
+}
+
+const LEGACY_MEDIA_KEYS = Object.freeze({
+ startFrame: "imageUrls",
+ endFrame: "endImageUrl",
+ anchorImage: "anchorImageUrl",
+ referenceImages: "imageUrls",
+ referenceVideos: "videoUrls",
+ referenceAudios: "audioUrls",
+ sourceVideo: "videoUrls",
+ characterImage: "imageUrls",
+ drivingVideo: "videoUrls",
+});
+
+function mediaValues(media, slotId) {
+ if (Object.prototype.hasOwnProperty.call(media || {}, slotId)) {
+ const value = media[slotId];
+ return (Array.isArray(value) ? value : [value]).filter(Boolean);
+ }
+ const legacyValue = media?.[LEGACY_MEDIA_KEYS[slotId]];
+ return (Array.isArray(legacyValue) ? legacyValue : [legacyValue]).filter(Boolean);
+}
+
+export function projectVideoWorkflowMedia(model, workflowId, media = {}) {
+ const projected = {};
+ for (const slot of getVideoWorkflowMediaSlots(model, workflowId)) {
+ const values = mediaValues(media, slot.id).slice(0, slot.maxItems);
+ if (values.length > 0) projected[slot.id] = values;
+ }
+ return projected;
+}
+
+export function getVideoWorkflowSlotRemaining(slot, media = {}) {
+ if (!slot) return 0;
+ const ownRemaining = Math.max(
+ slot.maxItems - mediaValues(media, slot.id).length,
+ 0,
+ );
+ if (!slot.combinedLimit || !slot.combinedSlotIds) return ownRemaining;
+ const combinedCount = combinedMediaCount(media, slot.combinedSlotIds);
+ return Math.min(
+ ownRemaining,
+ Math.max(slot.combinedLimit - combinedCount, 0),
+ );
+}
+
+export function legacyVideoMediaToWorkflowDraft(model, workflowId, media = {}) {
+ const draft = {};
+ for (const slot of getVideoWorkflowMediaSlots(model, workflowId)) {
+ const values = mediaValues(media, slot.id).slice(0, slot.maxItems);
+ if (values.length > 0) draft[slot.id] = values;
+ }
+ return draft;
+}
+
+function mediaCount(media, slotId) {
+ return mediaValues(media, slotId).length;
+}
+
+function combinedMediaCount(media, slotIds, excludedSlotId = null) {
+ return slotIds.reduce(
+ (total, slotId) =>
+ slotId === excludedSlotId ? total : total + mediaCount(media, slotId),
+ 0,
+ );
+}
+
+export function validateVideoWorkflowMedia(workflowId, media = {}, model = null) {
+ const slots = getVideoWorkflowMediaSlots(model, workflowId);
+ const activeMedia = model
+ ? projectVideoWorkflowMedia(model, workflowId, media)
+ : media;
+ for (const [slotId, message] of Object.entries(
+ WORKFLOW_REQUIRED_MEDIA[workflowId] || {},
+ )) {
+ if (mediaCount(activeMedia, slotId) === 0) {
+ return { valid: false, message };
+ }
+ }
+
+ if (workflowId === "references") {
+ const combinedConstraint = slots.find(
+ (slot) => slot.combinedLimit && slot.combinedSlotIds,
+ );
+ const requiredSlotIds = combinedConstraint?.requiredSlotIds ||
+ MULTIMODAL_REFERENCE_SLOT_IDS;
+ const requiredCount = requiredSlotIds.reduce(
+ (total, slotId) => total + mediaCount(activeMedia, slotId),
+ 0,
+ );
+ if (requiredCount === 0) {
+ return { valid: false, message: "Please add at least one reference." };
+ }
+ if (combinedConstraint) {
+ const combinedCount = combinedMediaCount(
+ activeMedia,
+ combinedConstraint.combinedSlotIds,
+ );
+ if (combinedCount > combinedConstraint.combinedLimit) {
+ return {
+ valid: false,
+ message: combinedConstraint.combinedLimitMessage,
+ };
+ }
+ }
+ }
+ return { valid: true, message: "" };
+}
+
+export function buildVideoWorkflowMediaParams(model, workflowId, media = {}) {
+ const payload = {};
+ const activeMedia = projectVideoWorkflowMedia(model, workflowId, media);
+ for (const slot of getVideoWorkflowMediaSlots(model, workflowId)) {
+ const values = mediaValues(activeMedia, slot.id);
+ if (!slot.field || values.length === 0) continue;
+ if (slot.index !== undefined) {
+ const current = Array.isArray(payload[slot.field]) ? payload[slot.field] : [];
+ current[slot.index] = values[0];
+ payload[slot.field] = current;
+ } else if (slot.isArray) {
+ payload[slot.field] = values;
+ } else {
+ payload[slot.field] = values[0];
+ }
+ }
+ for (const [field, value] of Object.entries(payload)) {
+ if (Array.isArray(value)) payload[field] = value.filter(Boolean);
+ }
+ return payload;
+}