Open History to see the last commit
1import { useEffect, useRef, useState } from 'react'
2import { Circle, Download, Loader2, Square, TriangleAlert } from 'lucide-react'
3import { generateWorldFn } from '@/lib/server-functions'
4import { attachStream } from '@/lib/attach-stream'
5import {
6 MarblePlanError,
7 downloadMarbleAsset,
8 splatFileName,
9} from '@/lib/marble-splat'
10import { readMediaFile } from '@/lib/media'
11import { LingbotControls } from '@/components/LingbotControls'
12import { MarbleViewer } from '@/components/MarbleViewer'
13import { SeedImageField } from '@/components/SeedImageField'
14import {
15 byok,
16 callWithByok,
17 reactorByok,
18 requestByokFromError,
19 worldlabsByok,
20} from '@/lib/byok'
21import {
22 WORLD_MODEL_LABELS,
23 WORLD_MODELS,
24 WORLD_PROMPTS,
25 WORLD_RESOLUTIONS,
26 isReactorWorldModel,
27 isWorldLabsWorldModel,
28 isWorldModelId,
29} from '@/lib/models'
30import {
31 LINGBOT_ROTATION_SPEED_DEG,
32 lingbotPrompt,
33 isRecorderUnavailable,
34 setReactorImage,
35 watchReactorFailure,
36 worldNeedsSeedImage,
37} from '@/lib/reactor-session'
38import type { Reactor } from '@reactor-team/js-sdk'
39import type {
40 ReactorWorldModel,
41 WorldModelId,
42 WorldResolution,
43} from '@/lib/models'
44
45type SessionStatus =
46 | 'idle'
47 | 'connecting'
48 | 'live'
49 | 'generating'
50 | 'ready'
51 | 'error'
52
53type MarbleResult = {
54 url: string
55 splatUrl?: string
56 metricScaleFactor?: number
57 groundPlaneOffset?: number
58 thumbnailUrl?: string
59 caption?: string
60 panoUrl?: string
61 meshUrl?: string
62}
63
64function isWorldResolution(value: string): value is WorldResolution {
65 return (WORLD_RESOLUTIONS as ReadonlyArray<string>).includes(value)
66}
67
68function errorMessage(error: unknown): string {
69 if (!(error instanceof Error)) return String(error)
70 const cause = error.cause
71 if (cause instanceof Error && cause.message.length > 0) {
72 return `${error.message} ${cause.message}`
73 }
74 return error.message
75}
76
77function readReactorPayload(value: unknown): {
78 token: string
79 model: string
80 prompt: string
81} {
82 if (typeof value !== 'object' || value === null) {
83 throw new Error('World payload is incomplete')
84 }
85 const token =
86 'token' in value && typeof value.token === 'string' ? value.token : ''
87 const model =
88 'model' in value && typeof value.model === 'string' ? value.model : ''
89 const prompt =
90 'prompt' in value && typeof value.prompt === 'string' ? value.prompt : ''
91 if (token.length === 0 || model.length === 0 || prompt.length === 0) {
92 throw new Error('World payload is incomplete')
93 }
94 return { token, model, prompt }
95}
96
97const WORLDLABS_MAX_SEED_IMAGES = 4
98
99function imageExtension(file: File): string | undefined {
100 switch (file.type) {
101 case 'image/jpeg':
102 return 'jpg'
103 case 'image/png':
104 return 'png'
105 case 'image/webp':
106 return 'webp'
107 }
108 const ext = file.name.split('.').pop()?.toLowerCase()
109 if (ext === 'jpeg') return 'jpg'
110 if (ext === 'jpg' || ext === 'png' || ext === 'webp') return ext
111 return undefined
112}
113
114function readMarblePayload(value: unknown): MarbleResult {
115 if (typeof value !== 'object' || value === null) {
116 throw new Error('World payload is incomplete')
117 }
118 const url = 'url' in value && typeof value.url === 'string' ? value.url : ''
119 if (url.length === 0) {
120 throw new Error('World payload is incomplete')
121 }
122 const thumbnailUrl =
123 'thumbnailUrl' in value && typeof value.thumbnailUrl === 'string'
124 ? value.thumbnailUrl
125 : undefined
126 const caption =
127 'caption' in value && typeof value.caption === 'string'
128 ? value.caption
129 : undefined
130 const splatUrl =
131 'splatUrl' in value && typeof value.splatUrl === 'string'
132 ? value.splatUrl
133 : undefined
134 const metricScaleFactor =
135 'metricScaleFactor' in value && typeof value.metricScaleFactor === 'number'
136 ? value.metricScaleFactor
137 : undefined
138 const groundPlaneOffset =
139 'groundPlaneOffset' in value && typeof value.groundPlaneOffset === 'number'
140 ? value.groundPlaneOffset
141 : undefined
142 const panoUrl =
143 'panoUrl' in value && typeof value.panoUrl === 'string'
144 ? value.panoUrl
145 : undefined
146 const meshUrl =
147 'meshUrl' in value && typeof value.meshUrl === 'string'
148 ? value.meshUrl
149 : undefined
150 return {
151 url,
152 thumbnailUrl,
153 caption,
154 splatUrl,
155 metricScaleFactor,
156 groundPlaneOffset,
157 panoUrl,
158 meshUrl,
159 }
160}
161
162function marbleAssetLinks(
163 marble: MarbleResult,
164): Array<{ label: string; url: string; filename: string }> {
165 const links: Array<{ label: string; url: string; filename: string }> = []
166 if (marble.splatUrl) {
167 links.push({
168 label: 'Splat',
169 url: marble.splatUrl,
170 filename: splatFileName(marble.splatUrl),
171 })
172 }
173 if (marble.meshUrl) {
174 links.push({
175 label: 'Mesh',
176 url: marble.meshUrl,
177 filename: 'world-collider.glb',
178 })
179 }
180 if (marble.panoUrl) {
181 links.push({
182 label: 'Pano',
183 url: marble.panoUrl,
184 filename: 'world-pano.jpg',
185 })
186 }
187 return links
188}
189
190async function startReactorWorld(
191 reactor: Reactor,
192 model: ReactorWorldModel,
193 prompt: string,
194 resolution: WorldResolution,
195 seedFile: File | null,
196): Promise<void> {
197 if (model === 'helios') {
198 await reactor.sendCommand('set_sr_scale', {
199 sr_scale: resolution === '2k' || resolution === '4k' ? '4x' : '2x',
200 })
201 } else if (!worldNeedsSeedImage(model)) {
202 await reactor.sendCommand('set_resolution', { resolution })
203 }
204 if (worldNeedsSeedImage(model)) {
205 if (!seedFile) throw new Error('LingBot needs a seed image before start')
206 await setReactorImage(reactor, seedFile)
207 await reactor.sendCommand('set_rotation_speed_deg', {
208 rotation_speed_deg: LINGBOT_ROTATION_SPEED_DEG,
209 })
210 await reactor.sendCommand('set_prompt', { prompt: lingbotPrompt(prompt) })
211 await reactor.sendCommand('start', {})
212 return
213 }
214 if (seedFile && model === 'helios') {
215 const image = await reactor.uploadFile(seedFile)
216 await reactor.sendCommand('set_conditioning', { prompt, image })
217 await reactor.sendCommand('start', {})
218 return
219 }
220 // Orbis: the image is optional and only read before start.
221 if (seedFile) await setReactorImage(reactor, seedFile)
222 await reactor.sendCommand('set_prompt', { prompt })
223 await reactor.sendCommand('start', {})
224}
225
226export default function WorldStudio() {
227 const [prompt, setPrompt] = useState<string>(WORLD_PROMPTS[0] ?? '')
228 const [steerPrompt, setSteerPrompt] = useState('')
229 const [model, setModel] = useState<WorldModelId>('visko-orbis-stable')
230 const [resolution, setResolution] = useState<WorldResolution>('1080p')
231 const [seedFiles, setSeedFiles] = useState<Array<File>>([])
232 const [status, setStatus] = useState<SessionStatus>('idle')
233 const [error, setError] = useState<string | null>(null)
234 const [playing, setPlaying] = useState(false)
235 const [marble, setMarble] = useState<MarbleResult | null>(null)
236 const [recording, setRecording] = useState(false)
237 const [recorderUnavailable, setRecorderUnavailable] = useState(false)
238 const [downloading, setDownloading] = useState<string | null>(null)
239 const [thumbFailed, setThumbFailed] = useState(false)
240 const videoRef = useRef<HTMLVideoElement>(null)
241 const reactorRef = useRef<Reactor | null>(null)
242 const reactorTokenRef = useRef<string | null>(null)
243 const detachStreamRef = useRef<(() => void) | null>(null)
244 const unwatchRef = useRef<(() => void) | null>(null)
245 const statusRef = useRef<SessionStatus>('idle')
246 statusRef.current = status
247
248 const isMarble = isWorldLabsWorldModel(model)
249 const seedFile = seedFiles[0] ?? null
250 const needsSeed = isReactorWorldModel(model) && worldNeedsSeedImage(model)
251
252 async function teardown() {
253 unwatchRef.current?.()
254 unwatchRef.current = null
255 const reactor = reactorRef.current
256 reactorRef.current = null
257 reactorTokenRef.current = null
258 detachStreamRef.current?.()
259 detachStreamRef.current = null
260 if (reactor) {
261 try {
262 await reactor.disconnect()
263 } catch (caught) {
264 const message = errorMessage(caught)
265 if (!/already (ended|closed|disconnected)/i.test(message)) {
266 console.warn('Reactor disconnect failed', caught)
267 }
268 }
269 }
270 const video = videoRef.current
271 if (video) {
272 video.srcObject = null
273 }
274 }
275
276 async function stop() {
277 await teardown()
278 setPlaying(false)
279 setMarble(null)
280 setThumbFailed(false)
281 setRecording(false)
282 setRecorderUnavailable(false)
283 setDownloading(null)
284 setStatus('idle')
285 }
286
287 useEffect(() => {
288 return () => {
289 void teardown()
290 }
291 }, [])
292
293 async function startMarble() {
294 setError(null)
295 setMarble(null)
296 setStatus('generating')
297 try {
298 await byok.prepare(worldlabsByok.id)
299 const seedImages = await Promise.all(
300 seedFiles.slice(0, WORLDLABS_MAX_SEED_IMAGES).map(async (file) => {
301 const media = await readMediaFile(file)
302 const extension = imageExtension(file)
303 return {
304 dataBase64: media.base64,
305 ...(extension ? { extension } : {}),
306 }
307 }),
308 )
309 const world = readMarblePayload(
310 await callWithByok(
311 generateWorldFn({
312 data: {
313 prompt,
314 model,
315 resolution,
316 ...(seedImages.length > 0 ? { seedImages } : {}),
317 },
318 headers: byok.headers(worldlabsByok.id),
319 }),
320 ),
321 )
322 setMarble(world)
323 setThumbFailed(false)
324 setStatus('ready')
325 } catch (caught) {
326 setMarble(null)
327 requestByokFromError(caught)
328 setError(errorMessage(caught))
329 setStatus('error')
330 }
331 }
332
333 async function startReactor() {
334 if (!isReactorWorldModel(model)) {
335 throw new Error(`Unknown world model: ${model}`)
336 }
337 setError(null)
338 setPlaying(false)
339 setMarble(null)
340 setRecorderUnavailable(false)
341 setStatus('connecting')
342 try {
343 if (needsSeed && !seedFile) {
344 throw new Error('LingBot needs a seed image before start')
345 }
346 await byok.prepare(reactorByok.id)
347 const world = readReactorPayload(
348 await callWithByok(
349 generateWorldFn({
350 data: { prompt, model, resolution },
351 headers: byok.headers(reactorByok.id),
352 }),
353 ),
354 )
355
356 const { Reactor: ReactorClient } = await import('@reactor-team/js-sdk')
357 const reactor = new ReactorClient({
358 modelName: world.model,
359 })
360 reactorRef.current = reactor
361 reactorTokenRef.current = world.token
362
363 let rejectStart: ((error: Error) => void) | undefined
364 const startFailed = new Promise<never>((_, reject) => {
365 rejectStart = reject
366 })
367 unwatchRef.current = watchReactorFailure(reactor, (message) => {
368 setError(message)
369 rejectStart?.(new Error(message))
370 if (statusRef.current === 'live') setStatus('error')
371 })
372 reactor.on('trackReceived', (name, _track, stream) => {
373 if (name !== 'main_video') return
374 const video = videoRef.current
375 if (!video) {
376 setError('Video element is missing')
377 setStatus('error')
378 return
379 }
380 detachStreamRef.current?.()
381 detachStreamRef.current = attachStream(video, stream, (playError) => {
382 setError(errorMessage(playError))
383 })
384 })
385
386 await reactor.connect(world.token)
387 try {
388 await Promise.race([
389 startReactorWorld(reactor, model, world.prompt, resolution, seedFile),
390 startFailed,
391 ])
392 } finally {
393 rejectStart = undefined
394 }
395 setSteerPrompt('')
396 setStatus('live')
397 } catch (caught) {
398 await stop()
399 requestByokFromError(caught)
400 setError(errorMessage(caught))
401 setStatus('error')
402 }
403 }
404
405 async function start() {
406 if (isMarble) {
407 await startMarble()
408 return
409 }
410 await startReactor()
411 }
412
413 async function recordSession() {
414 const reactor = reactorRef.current
415 const jwt = reactorTokenRef.current
416 if (!reactor || !jwt || recording || recorderUnavailable) return
417 setRecording(true)
418 setError(null)
419 try {
420 const clip = await reactor.requestRecording()
421 await reactor.downloadClipAsFile(clip, 'world-session.mp4', { jwt })
422 } catch (caught) {
423 if (isRecorderUnavailable(caught)) {
424 setRecorderUnavailable(true)
425 setError(
426 'Recording is not enabled for this model or plan. The live session still works.',
427 )
428 } else {
429 setError(errorMessage(caught))
430 }
431 } finally {
432 setRecording(false)
433 }
434 }
435
436 async function downloadMarble(url: string, filename: string) {
437 if (downloading) return
438 setDownloading(filename)
439 setError(null)
440 try {
441 await downloadMarbleAsset(url, filename)
442 } catch (caught) {
443 if (caught instanceof MarblePlanError) {
444 setError(caught.message)
445 } else {
446 setError(errorMessage(caught))
447 }
448 } finally {
449 setDownloading(null)
450 }
451 }
452
453 async function steer() {
454 const reactor = reactorRef.current
455 const next = steerPrompt.trim()
456 if (!reactor || next.length === 0) return
457 setError(null)
458 try {
459 if (needsSeed) {
460 // LingBot follows the image over the text. Keep the scene base and
461 // add the steer as a detail so the prompt still matches the image.
462 await reactor.sendCommand('set_prompt', {
463 prompt: lingbotPrompt(prompt, next),
464 })
465 } else {
466 await reactor.sendCommand('set_prompt', { prompt: next })
467 setPrompt(next)
468 }
469 setSteerPrompt('')
470 // Hand the keyboard back to the LingBot pads.
471 if (document.activeElement instanceof HTMLElement) {
472 document.activeElement.blur()
473 }
474 } catch (caught) {
475 setError(errorMessage(caught))
476 }
477 }
478
479 const isLive = status === 'live'
480 const isBusy = status === 'connecting' || status === 'generating'
481 const canStart =
482 !isBusy && prompt.trim().length > 0 && (!needsSeed || seedFile !== null)
483 const startLabel = isMarble ? 'Generate world' : 'Start world'
484 const busyLabel = isMarble ? 'Generating…' : 'Starting…'
485
486 return (
487 <div className="space-y-3">
488 <p className="text-sm text-gray-400">
489 {isMarble ? (
490 <>
491 World Labs Marble generates a finished 3D world (about 5 minutes).
492 Paste a key in the header dialog, or set{' '}
493 <code className="font-mono text-gray-300">WORLDLABS_API_KEY</code>{' '}
494 on the server. Add optional seed photos (up to four of the same
495 scene). If splat files are present, the world opens here. Click the
496 world, then WASD to move. Download files when the response includes
497 them.
498 </>
499 ) : (
500 <>
501 Live Reactor world. Paste a key in the header dialog, or set{' '}
502 <code className="font-mono text-gray-300">REACTOR_API_KEY</code> on
503 the server.
504 {needsSeed
505 ? ' Attach a seed image, describe what it shows, then start. The world opens full screen. Move with the pads, WASD, or the arrow keys. Record saves an MP4 when the model allows it.'
506 : ' Add an optional 16:9 seed image and start. The world opens full screen. Type in the bar at the bottom to steer. Record saves an MP4 when the model allows it.'}
507 </>
508 )}
509 </p>
510
511 {isMarble ? (
512 <div className="overflow-hidden rounded-xl border border-gray-700 bg-black">
513 {status === 'generating' ? (
514 <p className="flex aspect-video items-center justify-center gap-2 text-sm text-gray-400">
515 <Loader2 className="h-4 w-4 animate-spin" />
516 Generating the world. This usually takes a few minutes.
517 </p>
518 ) : marble?.splatUrl ? (
519 <MarbleViewer
520 splatUrl={marble.splatUrl}
521 metricScaleFactor={marble.metricScaleFactor}
522 groundPlaneOffset={marble.groundPlaneOffset}
523 />
524 ) : marble?.thumbnailUrl && !thumbFailed ? (
525 <img
526 src={marble.thumbnailUrl}
527 alt={marble.caption ?? 'Generated world'}
528 className="aspect-video w-full object-cover"
529 onError={() => setThumbFailed(true)}
530 />
531 ) : null}
532 {marble && status !== 'generating' ? (
533 <div className="flex flex-wrap items-center gap-3 px-4 py-3 text-sm">
534 {marble.splatUrl ? (
535 <p className="text-gray-400">
536 Click the world, then WASD to move, drag to look.
537 </p>
538 ) : (
539 <p className="text-gray-400">
540 No splat file on this world. Open in Marble still works.
541 </p>
542 )}
543 {marbleAssetLinks(marble).map((asset) => (
544 <button
545 key={asset.filename}
546 type="button"
547 disabled={downloading !== null}
548 onClick={() => void downloadMarble(asset.url, asset.filename)}
549 className="inline-flex items-center gap-1 font-medium text-purple-300 hover:text-purple-200 disabled:cursor-not-allowed disabled:opacity-50"
550 >
551 {downloading === asset.filename ? (
552 <Loader2 className="h-3.5 w-3.5 animate-spin" />
553 ) : (
554 <Download className="h-3.5 w-3.5" />
555 )}
556 {asset.label}
557 </button>
558 ))}
559 <a
560 href={marble.url}
561 target="_blank"
562 rel="noreferrer"
563 className="inline-flex font-medium text-purple-300 hover:text-purple-200"
564 >
565 Open in Marble
566 </a>
567 </div>
568 ) : status === 'idle' || status === 'error' ? (
569 <p className="px-4 py-3 text-sm text-gray-400">
570 The 3D world appears here after generation finishes.
571 </p>
572 ) : null}
573 </div>
574 ) : (
575 <div
576 className={
577 isLive
578 ? 'fixed inset-0 z-50 bg-black'
579 : 'overflow-hidden rounded-xl border border-gray-700 bg-black'
580 }
581 >
582 <video
583 ref={videoRef}
584 className={
585 isLive
586 ? 'h-full w-full object-cover'
587 : 'aspect-video w-full bg-black'
588 }
589 autoPlay
590 playsInline
591 muted
592 onPlaying={() => setPlaying(true)}
593 />
594 {status === 'idle' || status === 'error' ? (
595 <p className="px-4 py-3 text-sm text-gray-400">
596 The live stream appears here after you start a session.
597 </p>
598 ) : null}
599 {status === 'connecting' ? (
600 <p className="px-4 py-3 text-sm text-gray-400">
601 Connecting to the world model…
602 </p>
603 ) : null}
604 {isLive && !playing ? (
605 <p className="absolute inset-0 flex items-center justify-center text-sm text-gray-300">
606 Waiting for the first frame…
607 </p>
608 ) : null}
609 {isLive &&
610 needsSeed &&
611 isReactorWorldModel(model) &&
612 reactorRef.current ? (
613 <div className="absolute inset-x-0 top-0 bottom-24">
614 <LingbotControls
615 reactor={reactorRef.current}
616 model={model}
617 onError={setError}
618 />
619 </div>
620 ) : null}
621 {isLive ? (
622 <form
623 className="absolute inset-x-0 bottom-0 space-y-2 bg-gradient-to-t from-black/80 to-transparent px-4 pt-10 pb-4"
624 onSubmit={(event) => {
625 event.preventDefault()
626 void steer()
627 }}
628 >
629 {error ? (
630 <p className="flex items-start gap-2 text-sm text-red-300">
631 <TriangleAlert className="mt-0.5 h-4 w-4 shrink-0" />
632 {error}
633 </p>
634 ) : null}
635 <div className="mx-auto flex max-w-3xl items-end gap-2">
636 <label className="flex-1">
637 <span className="sr-only">Steer prompt</span>
638 <textarea
639 value={steerPrompt}
640 onChange={(event) => setSteerPrompt(event.target.value)}
641 onKeyDown={(event) => {
642 if (event.key !== 'Enter' || event.shiftKey) return
643 event.preventDefault()
644 event.currentTarget.form?.requestSubmit()
645 }}
646 rows={1}
647 placeholder={
648 needsSeed
649 ? 'Add a detail, e.g. It is night and the street lamps glow.'
650 : 'Steer the scene. The picture morphs at the next chunk.'
651 }
652 className="block w-full resize-none rounded-xl border border-white/20 bg-black/40 px-4 py-3 text-white placeholder-gray-300 backdrop-blur-md focus:border-purple-400 focus:outline-none"
653 />
654 </label>
655 <button
656 type="submit"
657 disabled={steerPrompt.trim().length === 0}
658 className="rounded-xl bg-purple-600/90 px-4 py-3 font-medium text-white backdrop-blur-md hover:bg-purple-500 disabled:cursor-not-allowed disabled:opacity-50"
659 >
660 Send
661 </button>
662 <button
663 type="button"
664 onClick={() => void recordSession()}
665 disabled={recording || recorderUnavailable}
666 title={
667 recorderUnavailable
668 ? 'Recording is not enabled for this model or plan'
669 : 'Save the session as an MP4'
670 }
671 className="inline-flex items-center gap-2 rounded-xl bg-white/10 px-4 py-3 font-medium text-white backdrop-blur-md hover:bg-white/20 disabled:cursor-not-allowed disabled:opacity-50"
672 >
673 {recording ? (
674 <Loader2 className="h-4 w-4 animate-spin" />
675 ) : (
676 <Circle className="h-4 w-4 fill-red-500 text-red-500" />
677 )}
678 {recording ? 'Saving…' : 'Record'}
679 </button>
680 <button
681 type="button"
682 onClick={() => void stop()}
683 className="inline-flex items-center gap-2 rounded-xl bg-red-600/90 px-4 py-3 font-medium text-white backdrop-blur-md hover:bg-red-500"
684 >
685 <Square className="h-4 w-4" />
686 Stop
687 </button>
688 </div>
689 </form>
690 ) : null}
691 </div>
692 )}
693
694 {isLive ? null : (
695 <form
696 className="space-y-2"
697 onSubmit={(event) => {
698 event.preventDefault()
699 if (canStart) void start()
700 }}
701 >
702 <label className="block">
703 <span className="sr-only">Prompt</span>
704 <textarea
705 value={prompt}
706 onChange={(event) => setPrompt(event.target.value)}
707 disabled={isBusy}
708 onKeyDown={(event) => {
709 if (event.key !== 'Enter' || event.shiftKey) return
710 event.preventDefault()
711 event.currentTarget.form?.requestSubmit()
712 }}
713 rows={2}
714 placeholder={
715 needsSeed
716 ? 'Describe what the seed image shows…'
717 : 'Describe the world to generate…'
718 }
719 className="w-full rounded-lg border border-gray-700 bg-gray-900 px-3 py-2 text-white placeholder-gray-500 focus:border-purple-500 focus:outline-none disabled:opacity-50"
720 />
721 </label>
722
723 {needsSeed ? null : (
724 <div className="flex flex-wrap gap-1.5">
725 {WORLD_PROMPTS.map((example) => (
726 <button
727 key={example}
728 type="button"
729 title={example}
730 onClick={() => setPrompt(example)}
731 disabled={isBusy}
732 className={`rounded-full border px-2.5 py-1 text-xs transition-colors ${
733 prompt === example
734 ? 'border-purple-500 bg-purple-600 text-white'
735 : 'border-gray-700 bg-gray-900 text-gray-400 hover:bg-gray-800 hover:text-gray-200'
736 } disabled:cursor-not-allowed disabled:opacity-50`}
737 >
738 {example.length > 36 ? `${example.slice(0, 36)}…` : example}
739 </button>
740 ))}
741 </div>
742 )}
743
744 <div className="flex flex-wrap items-center gap-2">
745 <button
746 type="submit"
747 disabled={!canStart}
748 className="inline-flex items-center gap-2 rounded-lg bg-purple-600 px-4 py-2 font-medium text-white hover:bg-purple-500 disabled:cursor-not-allowed disabled:opacity-50"
749 >
750 {isBusy ? <Loader2 className="h-4 w-4 animate-spin" /> : null}
751 {isBusy ? busyLabel : startLabel}
752 </button>
753
754 <label className="flex items-center gap-2 text-sm text-gray-400">
755 <span className="sr-only">Model</span>
756 <select
757 value={model}
758 onChange={(event) => {
759 const next = event.target.value
760 if (!isWorldModelId(next)) return
761 if (isLive || status === 'ready') void stop()
762 if (!isWorldLabsWorldModel(next) && seedFiles.length > 1) {
763 setSeedFiles(seedFiles.slice(0, 1))
764 }
765 setModel(next)
766 }}
767 disabled={isBusy}
768 className="rounded-lg border border-gray-700 bg-gray-900 px-2 py-2 text-sm text-white focus:border-purple-500 focus:outline-none disabled:opacity-50"
769 >
770 {WORLD_MODELS.map((id) => (
771 <option key={id} value={id}>
772 {WORLD_MODEL_LABELS[id]}
773 </option>
774 ))}
775 </select>
776 </label>
777
778 {needsSeed || isMarble ? null : (
779 <label className="flex items-center gap-2 text-sm text-gray-400">
780 <span className="sr-only">Resolution</span>
781 <select
782 value={resolution}
783 onChange={(event) => {
784 const next = event.target.value
785 if (isWorldResolution(next)) setResolution(next)
786 }}
787 disabled={isBusy}
788 className="rounded-lg border border-gray-700 bg-gray-900 px-2 py-2 text-sm text-white focus:border-purple-500 focus:outline-none disabled:opacity-50"
789 >
790 {WORLD_RESOLUTIONS.map((value) => (
791 <option key={value} value={value}>
792 {value}
793 </option>
794 ))}
795 </select>
796 </label>
797 )}
798
799 <SeedImageField
800 files={seedFiles}
801 onChange={setSeedFiles}
802 maxFiles={isMarble ? WORLDLABS_MAX_SEED_IMAGES : 1}
803 required={needsSeed}
804 disabled={isBusy}
805 />
806 </div>
807 </form>
808 )}
809
810 {error && !isLive ? (
811 <p className="flex items-start gap-2 text-sm text-red-400">
812 <TriangleAlert className="mt-0.5 h-4 w-4 shrink-0" />
813 {error}
814 </p>
815 ) : null}
816 </div>
817 )
818}