({
provider,
mode,
testId,
aimockPort,
withImageInput,
}: VideoGenUIProps)
| 40 | } |
| 41 | |
| 42 | export function VideoGenUI({ |
| 43 | provider, |
| 44 | mode, |
| 45 | testId, |
| 46 | aimockPort, |
| 47 | withImageInput, |
| 48 | }: VideoGenUIProps) { |
| 49 | const [prompt, setPrompt] = useState('') |
| 50 | const [imageFile, setImageFile] = useState<File | null>(null) |
| 51 | |
| 52 | const connectionOptions = () => { |
| 53 | const body = { provider, testId, aimockPort } |
| 54 | |
| 55 | if (mode === 'sse') { |
| 56 | return { connection: fetchServerSentEvents('/api/video'), body } |
| 57 | } |
| 58 | if (mode === 'http-stream') { |
| 59 | return { connection: fetchHttpStream('/api/video/stream'), body } |
| 60 | } |
| 61 | return { |
| 62 | fetcher: async (input: { prompt: MediaPrompt }) => { |
| 63 | return generateVideoFn({ |
| 64 | data: { prompt: input.prompt, provider, aimockPort, testId }, |
| 65 | }) as Promise<VideoGenerateResult> |
| 66 | }, |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | const { generate, result, videoStatus, isLoading, error, status } = |
| 71 | useGenerateVideo(connectionOptions()) |
| 72 | |
| 73 | const handleGenerate = async () => { |
| 74 | if (!imageFile) { |
| 75 | await generate({ prompt }) |
| 76 | return |
| 77 | } |
| 78 | const base64 = await fileToBase64(imageFile) |
| 79 | await generate({ |
| 80 | prompt: [ |
| 81 | { type: 'text', content: prompt }, |
| 82 | { |
| 83 | type: 'image', |
| 84 | source: { type: 'data', value: base64, mimeType: imageFile.type }, |
| 85 | }, |
| 86 | ], |
| 87 | }) |
| 88 | } |
| 89 | |
| 90 | return ( |
| 91 | <div className="p-4 space-y-4"> |
| 92 | <div className="flex gap-2"> |
| 93 | <input |
| 94 | data-testid="prompt-input" |
| 95 | type="text" |
| 96 | value={prompt} |
| 97 | onChange={(e) => setPrompt(e.target.value)} |
| 98 | placeholder="Describe the video..." |
| 99 | className="flex-1 bg-gray-800 border border-gray-700 rounded px-3 py-2 text-sm" |
nothing calls this directly
no test coverage detected