import { useState } from 'react'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { ArrowRight, Check, Save } from 'lucide-react'; import { api, assetUrl, request } from '../../shared/api/client'; import type { ConversationInput, Generation } from '../../shared/api/types'; import { useCapabilities } from '../../shared/api/use-capabilities'; import { UnavailableFeature } from '../../shared/components/unavailable-feature'; import { ErrorNotice, Loading } from '../../shared/components/ui'; import { ScenePreview } from '../scenes/scene-preview'; import { DEMO_SCENE_ID, DEMO_IMAGE_ID, DEMO_CHARACTER_IDS } from '../../shared/api/demo'; import { DialogueEditor } from '../conversations/dialogue-editor'; export function StudioPage() { const capabilities = useCapabilities(); const chars = useQuery({ queryKey: ['characters'], queryFn: api.characters }); const scripts = useQuery({ queryKey: ['conversations'], queryFn: api.conversations }); const scenes = useQuery({ queryKey: ['scenes'], queryFn: api.scenes }); const characters = chars.data?.filter((c) => !c.archived && DEMO_CHARACTER_IDS.some((id) => id === c.id)) || []; const scene = scenes.data?.find((s) => s.id === DEMO_SCENE_ID); const [script, setScript] = useState({ title: 'My first conversation', mode: 'scripted', approved: false, turns: [ { character_id: 'royale', text: '', direction: '', pause_after: 0.4 }, { character_id: 'summer', text: '', direction: '', pause_after: 0.4 }, ], }); const [scriptId, setScriptId] = useState(); const [busy, setBusy] = useState(false); const [error, setError] = useState(); const [notice, setNotice] = useState(''); const query = useQueryClient(); const [jobId, setJobId] = useState(); const job = useQuery({ queryKey: ['generation', jobId], queryFn: () => request(`/generations/${jobId}`), enabled: !!jobId, refetchInterval: (query) => ['completed', 'failed', 'cancelled'].includes(query.state.data?.status || '') ? false : 3000, }); const cast = DEMO_CHARACTER_IDS.map((id) => characters.find((c) => c.id === id)).filter( (c) => c !== undefined, ); const scriptValid = !!script.title.trim() && script.turns.every((t) => t.text.trim() && characters.some((c) => c.id === t.character_id)); const sceneValid = scene?.image_asset_id === DEMO_IMAGE_ID && cast.length === 2; const matchingSpeakers = new Set(script.turns.map((t) => t.character_id)).size === 2 && script.turns.every((t) => DEMO_CHARACTER_IDS.some((id) => id === t.character_id)); const ready = scriptValid && sceneValid && matchingSpeakers && script.approved && scene?.approved; const remaining = !sceneValid ? 'The demo scene is not available. Check the backend connection.' : !scriptValid ? 'Give your conversation a name and fill in each line. Videos follow the conversation length, up to 60 seconds.' : !matchingSpeakers ? 'Give both characters at least one line.' : !script.approved ? 'Approve the dialogue to create your preview.' : ''; async function save(kind?: 'storyboard' | 'animated') { if ( busy || !scriptValid || (kind && (!ready || capabilities.workerReason || (kind === 'animated' && !capabilities.animation))) ) return; setBusy(true); setError(null); setNotice(''); try { const conversation = await api.saveConversation(script, scriptId); setScriptId(conversation.id); await query.invalidateQueries({ queryKey: ['conversations'] }); if (kind && scene) { const generation = await api.generate(conversation.id, DEMO_SCENE_ID, kind, 60); setJobId(generation.id); setNotice( kind === 'animated' ? 'Talking video queued with speech and lip-sync.' : 'Silent storyboard preview queued.', ); } else setNotice('Conversation saved.'); } catch (e) { setError(e); } finally { setBusy(false); } } if (chars.isLoading || scenes.isLoading) return ; return (

Create a conversation

Write a conversation for R.Royale and Summer Breeze.

{notice && (
{notice}
)} { setScript(v); setNotice(''); }} characters={cast} saved={scripts.data || []} onLoad={(s) => { setScript(s); setScriptId(s.id); }} />
3

Save or create

Video length follows your spoken dialogue and pauses, up to 60 seconds.
Talking videos include voices and lip-sync for both characters. Short conversations produce short videos, without padding to a minute.

{remaining &&

{remaining}

}
Optional silent storyboard preview

This creates a still image video without voices or lip-sync. Duration is estimated from the script.

{jobId && (

Your render

{job.isLoading && } {job.data && ( <>

{job.data.status} · {job.data.stage}

{job.data.settings.kind === 'storyboard' ? 'Silent scene preview — no spoken dialogue or lip-sync.' : 'Review the spoken dialogue and animation before sharing.'}

{job.data.error && (
{job.data.error}
)} {job.data.output_asset_id && ( <>
)}
); }