Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

SeedanceStudio.tsx

1,418 lines52.4 KB

1import { useEffect, useRef, useState } from 'react'
2import {
3 AlertTriangle,
4 ChevronDown,
5 ChevronRight,
6 Clock,
7 Dices,
8 Download,
9 Film,
10 Loader2,
11 Music,
12 Play,
13 Shuffle,
14 Upload,
15 X,
16} from 'lucide-react'
17import { useGenerateVideo } from '@tanstack/ai-react'
18import type {
19 BytePlusVideoModel,
20 BytePlusVideoModelOrString,
21 BytePlusVideoRatio,
22 BytePlusVideoResolution,
23} from '@tanstack/ai-byteplus'
24import type { MediaPromptPart } from '@tanstack/ai/client'
25import type { AttachedMedia } from '@/lib/media'
26import type {
27 SeedanceTemplate,
28 SeedanceTemplateMedia,
29} from '@/lib/seedance-templates'
30import type { VideoBilling } from '@/lib/billing'
31import type {
32 SeedanceCapability,
33 SeedanceInputMode,
34 SeedanceJobOptions,
35 SeedanceModelEntry,
36} from '@/lib/seedance'
37​
38import { generateSeedanceVideoFn } from '@/lib/server-functions'
39import { byok, callWithByok, toByokProvider } from '@/lib/byok'
40import { mediaUrlToPart, readMediaFile, toImagePart } from '@/lib/media'
41import { readVideoBilling } from '@/lib/billing'
42import { getRandomVideoPrompt } from '@/lib/prompts'
43import {
44 SEEDANCE_CUSTOM_MODEL_PLACEHOLDER,
45 SEEDANCE_FPS,
46 SEEDANCE_MAX_FRAMES,
47 SEEDANCE_MIN_FRAMES,
48 SEEDANCE_MODELS,
49 SEEDANCE_RATIOS,
50 SEEDANCE_RESOLUTION_TIERS,
51 SEEDANCE_UNKNOWN_MODEL_EXTRAS,
52 describeSeedanceModel,
53 seedanceModel,
54 snapSeedanceFrames,
55} from '@/lib/seedance'
56import {
57 SEEDANCE_TEMPLATES,
58 SEEDANCE_TEMPLATE_MODEL,
59 SEEDANCE_TEMPLATE_RESOLUTION,
60} from '@/lib/seedance-templates'
61​
62/** How many reference images the studio offers on the 2.0 family. */
63const MAX_REFERENCE_IMAGES = 4
64/** Documented seed range; `-1` leaves generation unseeded. */
65const MIN_SEED = -1
66const MAX_SEED = 2 ** 32 - 1
67​
68/** What was actually requested, kept alongside the job for the result panel. */
69interface JobSettings {
70 model: BytePlusVideoModelOrString
71 ratio: BytePlusVideoRatio
72 /** A tier this package knows, or whatever a custom model was asked for. */
73 resolution: string
74 /** Seconds, `-1` for model-chosen, or null when a frame count was sent. */
75 duration: number | null
76 frames: number | null
77 seed: number | null
78 serviceTier: 'default' | 'flex' | null
80​
81function formatElapsed(ms: number): string {
82 const total = Math.max(0, Math.round(ms / 1000))
83 const minutes = Math.floor(total / 60)
84 const seconds = total % 60
85 return minutes > 0 ? `${minutes}m ${seconds}s` : `${seconds}s`
87​
88/**
89 * Direct BytePlus Seedance studio: one model at a time, with every control
90 * gated on what that model actually accepts.
91 *
92 * The gating is not cosmetic. Ark rejects an inapplicable field outright
93 * ("the specified parameter `draft` is not supported for model
94 * seedance-1-0-pro …") and sorts prompt media into mutually exclusive task
95 * types, so a form that let you mix a reference image into a first-and-last
96 * frame request, or send `priority` to a 1.x model, would only ever produce a
97 * 400. The capability half of the gating (`capabilities`) is read out of the
98 * adapter package on the server; the option-applicability half comes from
99 * `SEEDANCE_MODELS`.
100 */
101export default function SeedanceStudio({
102 capabilities,
103}: {
104 capabilities: Array<SeedanceCapability>
105}) {
106 const [modelId, setModelId] = useState<BytePlusVideoModel>(
107 'dreamina-seedance-2-0-260128',
108 )
109 const [prompt, setPrompt] = useState('')
110 const [inputMode, setInputMode] = useState<SeedanceInputMode>('text')
111 const [firstFrame, setFirstFrame] = useState<AttachedMedia | null>(null)
112 const [lastFrame, setLastFrame] = useState<AttachedMedia | null>(null)
113 const [references, setReferences] = useState<Array<AttachedMedia>>([])
114 /** Last file-attach failure, rendered beside the pickers. */
115 const [attachError, setAttachError] = useState<string | null>(null)
116 /**
117 * Template media, kept apart from the uploads: these are remote URLs the app
118 * never holds bytes for, and their order carries the prompt's `@Video1` /
119 * `@Image1` ordinals.
120 */
121 const [templateMedia, setTemplateMedia] = useState<
122 Array<SeedanceTemplateMedia>
123 >([])
124 const [appliedTemplateId, setAppliedTemplateId] = useState<string | null>(
125 null,
126 )
127​
128 const [ratio, setRatio] = useState<BytePlusVideoRatio>('16:9')
129 const [resolution, setResolution] = useState<BytePlusVideoResolution>('720p')
130 const [duration, setDuration] = useState(5)
131 const [autoDuration, setAutoDuration] = useState(false)
132 const [useFrames, setUseFrames] = useState(false)
133 const [frames, setFrames] = useState(121)
134​
135 // Advanced escape hatch: a model id this package has no metadata for.
136 const [showAdvanced, setShowAdvanced] = useState(false)
137 const [customModelId, setCustomModelId] = useState('')
138 const [customResolution, setCustomResolution] = useState('')
139​
140 const [seed, setSeed] = useState('')
141 const [watermark, setWatermark] = useState(false)
142 const [generateAudio, setGenerateAudio] = useState(false)
143 const [cameraFixed, setCameraFixed] = useState(false)
144 const [flexTier, setFlexTier] = useState(false)
145 const [draft, setDraft] = useState(false)
146 const [priority, setPriority] = useState(5)
147​
148 /** What the in-flight (or last) task was actually asked for. */
149 const [settings, setSettings] = useState<JobSettings | null>(null)
150 const [startedAt, setStartedAt] = useState<number | null>(null)
151 const [finishedAt, setFinishedAt] = useState<number | null>(null)
152 const [billing, setBilling] = useState<VideoBilling | undefined>(undefined)
153 const [now, setNow] = useState(() => Date.now())
154​
155 const firstFrameInputRef = useRef<HTMLInputElement>(null)
156 const lastFrameInputRef = useRef<HTMLInputElement>(null)
157 const referenceInputRef = useRef<HTMLInputElement>(null)
158 /**
159 * Model and provider options for the task on the wire. `useGenerateVideo`
160 * builds its client — and captures the fetcher — once, so a submission's
161 * settings are read from here at call time instead of being closed over,
162 * which is also what keeps a running task pinned to the model it was
163 * submitted with while the picker moves on.
164 */
165 const submissionRef = useRef<{
166 model: BytePlusVideoModelOrString
167 options: SeedanceJobOptions
168 } | null>(null)
169​
170 // A non-empty custom id switches the studio into unknown-model mode: the
171 // adapter's per-model guards are off for an id it has no table for, so the
172 // full option surface is offered and Ark judges the request.
173 const customModel = customModelId.trim()
174 const usingCustomId = showAdvanced && customModel.length > 0
175 const activeModel: BytePlusVideoModelOrString = usingCustomId
176 ? customModel
177 : modelId
178​
179 // A catalog miss takes the same path as a custom id rather than borrowing
180 // another model's option policy. It cannot happen while
181 // `SeedanceCatalogCoversEveryModel` compiles, which is the point.
182 const catalogEntry = usingCustomId ? undefined : seedanceModel(modelId)
183 const unknownMode = catalogEntry === undefined
184 const entry: SeedanceModelEntry = catalogEntry ?? {
185 id: activeModel,
186 name: activeModel,
187 blurb: 'Custom model id — capabilities unverified',
188 extras: SEEDANCE_UNKNOWN_MODEL_EXTRAS,
189 }
190 const capability = unknownMode
191 ? undefined
192 : capabilities.find((c) => c.model === modelId)
193 const resolutions = unknownMode
194 ? SEEDANCE_RESOLUTION_TIERS
195 : (capability?.resolutions ?? [])
196 const durationRange = capability?.duration ?? { min: 4, max: 12, step: 1 }
197 const canLastFrame = unknownMode || (capability?.supportsLastFrame ?? false)
198 const canReference =
199 unknownMode || (capability?.supportsReferenceMedia ?? false)
200​
201 // Everything below clamps the raw control state to the selected model rather
202 // than rewriting it on change, so switching models to compare and switching
203 // back leaves your settings where you left them.
204 const effectiveMode: SeedanceInputMode =
205 (inputMode === 'first-last-frame' && !canLastFrame) ||
206 (inputMode === 'reference' && !canReference)
207 ? 'text'
208 : inputMode
209 const effectiveResolution = resolutions.includes(resolution)
210 ? resolution
211 : (resolutions[resolutions.length - 1] ?? '720p')
212 // A custom tier wins over the picker: a future model may bring one that does
213 // not exist today, which is the whole point of the free-text field.
214 const requestResolution: string =
215 unknownMode && customResolution.trim().length > 0
216 ? customResolution.trim()
217 : effectiveResolution
218 // An unknown model's duration is sent verbatim (the adapter deliberately
219 // does not snap it), so the input is free rather than clamped to a range
220 // borrowed from the models that happen to exist today.
221 const effectiveDuration = unknownMode
222 ? duration
223 : Math.min(durationRange.max, Math.max(durationRange.min, duration))
224 const effectiveFrames = snapSeedanceFrames(frames)
225 const framesActive = entry.extras.frames && useFrames
226 const autoDurationActive = entry.extras.autoDuration && autoDuration
227 const hasImageInput = effectiveMode !== 'text'
228 // `adaptive` follows the input frame, so it is only meaningful — and on the
229 // 1.0 models only accepted — once an image is attached.
230 const effectiveRatio: BytePlusVideoRatio =
231 ratio === 'adaptive' && !hasImageInput ? '16:9' : ratio
232​
233 // The server holds the request open and polls Ark itself, streaming job id,
234 // status and the finished url back on the one connection — so the studio
235 // reads the task's whole lifecycle off the hook instead of running a timer.
236 const { generate, result, jobId, videoStatus, isLoading, error } =
237 useGenerateVideo({
238 threadId: 'seedance-studio',
239 byok,
240 byokProvider: () => toByokProvider('byteplus'),
241 // `options.signal` is the hook's abort signal; cancelling the response
242 // is what ends the server's polling loop instead of leaving it running
243 // to the 30-minute ceiling.
244 fetcher: (input, options) => {
245 const submission = submissionRef.current
246 if (!submission) throw new Error('No Seedance task in flight')
247 return callWithByok(
248 generateSeedanceVideoFn({
249 data: {
250 prompt: input.prompt,
251 model: submission.model,
252 options: submission.options,
253 },
254 signal: options?.signal,
255 headers: options?.headers,
256 }),
257 )
258 },
259 onResult: () => {
260 // Clearing the ref is what re-opens the form to the next task.
261 submissionRef.current = null
262 setFinishedAt(Date.now())
263 },
264 onError: () => {
265 submissionRef.current = null
266 },
267 onChunk: (chunk) => {
268 const usage = readVideoBilling(chunk)
269 if (usage) setBilling(usage)
270 },
271 })
272​
273 const isBusy = isLoading
274​
275 // Drive the elapsed-time readout; flex tasks can sit queued for many
276 // minutes, so the wait needs to look like progress.
277 useEffect(() => {
278 if (!isBusy) return
279 const tick = setInterval(() => setNow(Date.now()), 1000)
280 return () => clearInterval(tick)
281 }, [isBusy])
282​
283 const attachFile = async (
284 e: React.ChangeEvent<HTMLInputElement>,
285 apply: (media: AttachedMedia) => void,
286 ) => {
287 const file = e.target.files?.[0]
288 e.target.value = ''
289 if (!file) return
290 setAttachError(null)
291 try {
292 apply(await readMediaFile(file))
293 } catch (error) {
294 // The input was already reset above, so without this the failure has no
295 // observable effect at all: no message, no console entry, and the same
296 // file re-picks to the same silence. Surface it next to the picker.
297 setAttachError(
298 `Could not read "${file.name}": ${
299 error instanceof Error ? error.message : String(error)
300 }`,
301 )
302 }
303 }
304​
305 /**
306 * Load a playground template. It sets four things and nothing else:
307 *
308 * 1. the model — Seedance 2.0, since templates need multimodal reference
309 * media, clearing any custom id that would otherwise override it;
310 * 2. the prompt, verbatim from the console;
311 * 3. reference mode and the template's media (replacing any uploads);
312 * 4. the console's generation defaults for templates — smart length, sound
313 * on, 720p, and a ratio that follows the reference media.
314 *
315 * The seed is reset because a leftover one silently changes the output.
316 * Watermark, priority, fixed camera, draft and flex tier are deliberately
317 * left as you had them: none of them contradicts a template, and the
318 * console has no opinion about them.
319 */
320 const applyTemplate = (template: SeedanceTemplate) => {
321 if (isBusy) return
322 setModelId(SEEDANCE_TEMPLATE_MODEL)
323 setCustomModelId('')
324 setShowAdvanced(false)
325 setPrompt(template.prompt)
326 setInputMode('reference')
327 setTemplateMedia(template.media)
328 setReferences([])
329 setAppliedTemplateId(template.id)
330 setSeed('')
331 setAutoDuration(true)
332 setGenerateAudio(true)
333 setResolution(SEEDANCE_TEMPLATE_RESOLUTION)
334 setRatio('adaptive')
335 }
336​
337 /**
338 * Edit the prompt and the card stops claiming to be applied — what's on
339 * screen is no longer the template the console would have sent.
340 */
341 const handlePromptChange = (value: string) => {
342 setPrompt(value)
343 if (appliedTemplateId !== null) setAppliedTemplateId(null)
344 }
345​
346 /** Dropping any of a template's media diverges it the same way. */
347 const removeTemplateMedia = (url: string) => {
348 setTemplateMedia((prev) => prev.filter((m) => m.url !== url))
349 setAppliedTemplateId(null)
350 }
351​
352 const clearTemplate = () => {
353 setTemplateMedia([])
354 setAppliedTemplateId(null)
355 }
356​
357 const handleGenerate = async () => {
358 if (!prompt.trim() && !hasImageInput) return
359 // `isBusy` comes from React state, which hasn't re-rendered yet for a
360 // second click in the same tick; the ref is set synchronously below and
361 // cleared when the task settles, so it closes that window — without it a
362 // second submit would swap the model out from under the running task.
363 if (isBusy || submissionRef.current) return
364​
365 const parts: Array<MediaPromptPart> = []
366 if (prompt.trim()) parts.push({ type: 'text', content: prompt })
367 if (
368 effectiveMode === 'first-frame' ||
369 effectiveMode === 'first-last-frame'
370 ) {
371 if (firstFrame)
372 parts.push(toImagePart(firstFrame, { role: 'start_frame' }))
373 if (effectiveMode === 'first-last-frame' && lastFrame) {
374 parts.push(toImagePart(lastFrame, { role: 'end_frame' }))
375 }
376 }
377 if (effectiveMode === 'reference') {
378 // Template media first and in declared order: the adapter keeps the
379 // relative order of the parts within each modality, which is what the
380 // prompt's `@Video1` / `@Image1` ordinals are counting.
381 for (const media of templateMedia) {
382 parts.push(mediaUrlToPart(media.kind, media.url, { role: 'reference' }))
383 }
384 for (const reference of references) {
385 parts.push(toImagePart(reference, { role: 'reference' }))
386 }
387 }
388​
389 // Clamped as well as bounded on the input: a number field still accepts
390 // out-of-range values typed or pasted straight in, and Ark rejects a seed
391 // outside `[-1, 2^32-1]`.
392 const parsedSeed = seed.trim() === '' ? null : Number(seed)
393 const seedValue =
394 parsedSeed !== null && Number.isFinite(parsedSeed)
395 ? Math.min(MAX_SEED, Math.max(MIN_SEED, Math.trunc(parsedSeed)))
396 : null
397​
398 const jobSettings: JobSettings = {
399 model: activeModel,
400 ratio: effectiveRatio,
401 resolution: requestResolution,
402 duration: framesActive
403 ? null
404 : autoDurationActive
405 ? -1
406 : effectiveDuration,
407 frames: framesActive ? effectiveFrames : null,
408 seed: seedValue,
409 serviceTier: entry.extras.serviceTier
410 ? flexTier
411 ? 'flex'
412 : 'default'
413 : null,
414 }
415​
416 // Only fields the selected model accepts go on the wire — Ark 400s on the
417 // rest rather than ignoring them. A custom id accepts everything, and its
418 // sizing goes through the open `size` template because `resolution` is
419 // typed against the tiers this package knows.
420 const options: SeedanceJobOptions = {
421 ...(unknownMode
422 ? { size: `${effectiveRatio}_${requestResolution}` }
423 : { ratio: effectiveRatio, resolution: effectiveResolution }),
424 ...(framesActive
425 ? { frames: effectiveFrames }
426 : { duration: autoDurationActive ? -1 : effectiveDuration }),
427 ...(seedValue !== null && { seed: seedValue }),
428 watermark,
429 ...(entry.extras.generateAudio && { generateAudio }),
430 ...(entry.extras.cameraFixed && { cameraFixed }),
431 ...(entry.extras.serviceTier && {
432 serviceTier: flexTier ? 'flex' : 'default',
433 }),
434 ...(entry.extras.draft && { draft }),
435 ...(entry.extras.priority && { priority }),
436 }
437​
438 submissionRef.current = { model: activeModel, options }
439 setSettings(jobSettings)
440 setStartedAt(Date.now())
441 setFinishedAt(null)
442 setBilling(undefined)
443 await generate({
444 prompt: parts.length === 1 && !hasImageInput ? prompt : parts,
445 })
446 }
447​
448 const modeOptions: Array<{
449 value: SeedanceInputMode
450 label: string
451 enabled: boolean
452 hint: string
453 }> = [
454 { value: 'text', label: 'Text only', enabled: true, hint: 'Text-to-video' },
455 {
456 value: 'first-frame',
457 label: 'First frame',
458 enabled: true,
459 hint: 'Animate an opening frame',
460 },
461 {
462 value: 'first-last-frame',
463 label: 'First + last frame',
464 enabled: canLastFrame,
465 hint: canLastFrame
466 ? 'Pin both ends of the shot'
467 : 'This model has no closing-frame mode',
468 },
469 {
470 value: 'reference',
471 label: 'Reference images',
472 enabled: canReference,
473 hint: canReference
474 ? 'Subject and style references (Seedance 2.0)'
475 : 'Reference media is Seedance 2.0 only',
476 },
477 ]
478​
479 const modelSelectDisabled = isBusy || unknownMode
480​
481 // Reference images are capped across both sources: a template can bring one
482 // (templates 1 and 5 do), and it counts against the same budget as uploads.
483 const templateImageCount = templateMedia.filter(
484 (m) => m.kind === 'image',
485 ).length
486 const referenceImagesLeft = Math.max(
487 0,
488 MAX_REFERENCE_IMAGES - templateImageCount - references.length,
489 )
490 // Seedance rejects a reference audio that is the only reference — it needs
491 // something visual to attach to. Gating it here keeps the studio's promise
492 // that what the form lets you build is what the API accepts.
493 const referenceVisuals =
494 templateMedia.filter((m) => m.kind !== 'audio').length + references.length
495 const audioOnlyReferences =
496 effectiveMode === 'reference' &&
497 templateMedia.some((m) => m.kind === 'audio') &&
498 referenceVisuals === 0
499​
500 const readyToGenerate =
501 (prompt.trim().length > 0 || hasImageInput) &&
502 (effectiveMode !== 'first-frame' || firstFrame !== null) &&
503 (effectiveMode !== 'first-last-frame' ||
504 (firstFrame !== null && lastFrame !== null)) &&
505 (effectiveMode !== 'reference' ||
506 references.length + templateMedia.length > 0) &&
507 !audioOnlyReferences
508​
509 return (
510 <div className="space-y-6">
511 <section className="bg-gray-800/50 border border-gray-700 rounded-xl p-6 space-y-4">
512 <div>
513 <h2 className="text-lg font-medium text-white">Templates</h2>
514 <p className="text-sm text-gray-400">
515 The Ark playground's own presets — prompt, reference media and
516 settings in one click. All five need multimodal reference media, so
517 applying one switches the model to Seedance 2.0.
518 </p>
519 </div>
520 <div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
521 {SEEDANCE_TEMPLATES.map((template) => {
522 const applied = appliedTemplateId === template.id
523 return (
524 <button
525 key={template.id}
526 onClick={() => applyTemplate(template)}
527 disabled={isBusy}
528 className={`text-left rounded-lg border overflow-hidden transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${
529 applied
530 ? 'bg-blue-600/15 border-blue-500'
531 : 'bg-gray-800 border-gray-700 hover:border-gray-600'
532 }`}
533 >
534 {/* Hotlinked from Ark's public presets bucket — hovering plays
535 the sample rather than autoplaying five clips at once. The
536 bucket is in cn-beijing and slow to reach, so the label
537 below sits behind the video and shows through until the
538 `#t=0.1` seek paints its first frame. */}
539 <div className="relative w-full aspect-video bg-gray-900">
540 <div className="absolute inset-0 flex flex-col items-center justify-center gap-1 text-gray-600">
541 <Play className="w-6 h-6" />
542 <span className="text-[10px]">hover to preview</span>
543 </div>
544 <video
545 src={`${template.previewUrl}#t=0.1`}
546 muted
547 loop
548 playsInline
549 preload="metadata"
550 onMouseEnter={(e) => {
551 void e.currentTarget.play().catch(() => {})
552 }}
553 onMouseLeave={(e) => {
554 e.currentTarget.pause()
555 e.currentTarget.currentTime = 0
556 }}
557 className="relative w-full h-full object-cover"
558 />
559 </div>
560 <div className="p-3">
561 <div className="text-sm font-medium text-white">
562 {template.name}
563 </div>
564 <div className="text-xs text-gray-400 mt-0.5">
565 {template.blurb}
566 </div>
567 <div className="text-xs text-cyan-300 mt-1.5">
568 {template.media.map((m) => m.label).join(' · ')}
569 </div>
570 </div>
571 </button>
572 )
573 })}
574 </div>
575 </section>
576​
577 <section className="bg-gray-800/50 border border-gray-700 rounded-xl p-6 space-y-4">
578 <div className="flex items-center justify-between">
579 <h2 className="text-lg font-medium text-white">Prompt</h2>
580 <button
581 onClick={() =>
582 setPrompt(
583 getRandomVideoPrompt(
584 hasImageInput ? 'image-to-video' : 'text-to-video',
585 ),
586 )
587 }
588 disabled={isBusy}
589 className="flex items-center gap-1.5 px-3 py-1 text-xs font-medium text-blue-400 hover:text-blue-300 bg-blue-500/10 hover:bg-blue-500/20 rounded-md transition-colors disabled:opacity-50"
590 >
591 <Shuffle className="w-3.5 h-3.5" />
592 Shuffle
593 </button>
594 </div>
595 <textarea
596 value={prompt}
597 onChange={(e) => handlePromptChange(e.target.value)}
598 placeholder="Describe the shot — quote any dialogue you want in the audio track..."
599 rows={3}
600 disabled={isBusy}
601 className="w-full px-4 py-3 bg-gray-800 border border-gray-700 rounded-lg text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none disabled:opacity-50"
602 />
603​
604 <div>
605 <h3 className="text-sm font-medium text-gray-300 mb-2">
606 Image conditioning
607 </h3>
608 <div className="flex flex-wrap gap-2">
609 {modeOptions.map((option) => (
610 <button
611 key={option.value}
612 onClick={() => setInputMode(option.value)}
613 disabled={isBusy || !option.enabled}
614 title={option.hint}
615 className={`px-3 py-1.5 text-sm rounded-md transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${
616 effectiveMode === option.value
617 ? 'bg-blue-600 text-white'
618 : 'bg-gray-700 text-gray-300 hover:bg-gray-600'
619 }`}
620 >
621 {option.label}
622 </button>
623 ))}
624 </div>
625 {/* Uploads are images only; reference video and audio reach the
626 request through the templates above, which carry remote URLs. */}
627 <p className="text-xs text-gray-500 mt-2">
628 Frame roles and reference roles are mutually exclusive modes on
629 Seedance, so the studio sends one or the other — never a mix.
630 </p>
631 </div>
632​
633 {(effectiveMode === 'first-frame' ||
634 effectiveMode === 'first-last-frame') && (
635 <div className="grid gap-4 sm:grid-cols-2">
636 <FramePicker
637 label="First frame"
638 media={firstFrame}
639 disabled={isBusy}
640 onPick={() => firstFrameInputRef.current?.click()}
641 onClear={() => setFirstFrame(null)}
642 />
643 {effectiveMode === 'first-last-frame' && (
644 <FramePicker
645 label="Last frame"
646 media={lastFrame}
647 disabled={isBusy}
648 onPick={() => lastFrameInputRef.current?.click()}
649 onClear={() => setLastFrame(null)}
650 />
651 )}
652 </div>
653 )}
654​
655 {effectiveMode === 'reference' && templateMedia.length > 0 && (
656 <div>
657 <div className="flex items-center justify-between mb-2">
658 <label className="text-sm font-medium text-gray-300">
659 Template media{' '}
660 <span className="text-gray-500 font-normal">
661 (sent in this order — the prompt's @-tokens count them)
662 </span>
663 </label>
664 <button
665 onClick={clearTemplate}
666 disabled={isBusy}
667 className="text-xs text-gray-400 hover:text-white underline disabled:opacity-50"
668 >
669 Remove all
670 </button>
671 </div>
672 <div className="flex flex-wrap gap-2">
673 {templateMedia.map((media) => (
674 <div
675 key={media.url}
676 className="flex items-center gap-2 pl-1.5 pr-2 py-1.5 bg-gray-800 border border-gray-600 rounded-lg"
677 >
678 {media.kind === 'image' ? (
679 <img
680 src={media.url}
681 alt={media.label}
682 className="w-10 h-10 object-cover rounded"
683 />
684 ) : media.kind === 'video' ? (
685 <video
686 src={media.url}
687 muted
688 preload="metadata"
689 className="w-10 h-10 object-cover rounded bg-gray-900"
690 />
691 ) : (
692 <span className="flex items-center justify-center w-10 h-10 rounded bg-gray-900">
693 <Music className="w-4 h-4 text-gray-400" />
694 </span>
695 )}
696 <span className="text-xs text-gray-300 font-mono">
697 {media.label}
698 </span>
699 <button
700 onClick={() => removeTemplateMedia(media.url)}
701 disabled={isBusy}
702 className="p-0.5 text-gray-500 hover:text-white disabled:opacity-50"
703 >
704 <X className="w-3.5 h-3.5" />
705 </button>
706 </div>
707 ))}
708 </div>
709 </div>
710 )}
711​
712 {effectiveMode === 'reference' && (
713 <div>
714 <label className="block text-sm font-medium text-gray-300 mb-2">
715 Reference images{' '}
716 <span className="text-gray-500 font-normal">
717 (subject and style, {referenceImagesLeft} of{' '}
718 {MAX_REFERENCE_IMAGES} slots left)
719 </span>
720 </label>
721 <div className="flex flex-wrap gap-2">
722 {references.map((reference) => (
723 <div key={reference.id} className="relative">
724 <img
725 src={reference.dataUrl}
726 alt={reference.name}
727 className="w-20 h-20 object-cover rounded-lg border border-gray-600"
728 />
729 <button
730 onClick={() =>
731 setReferences((prev) =>
732 prev.filter((m) => m.id !== reference.id),
733 )
734 }
735 disabled={isBusy}
736 className="absolute -top-1.5 -right-1.5 p-0.5 bg-gray-900 hover:bg-gray-700 rounded-full text-white border border-gray-600 disabled:opacity-50"
737 >
738 <X className="w-3 h-3" />
739 </button>
740 </div>
741 ))}
742 {referenceImagesLeft > 0 && (
743 <button
744 onClick={() => referenceInputRef.current?.click()}
745 disabled={isBusy}
746 className="flex flex-col items-center justify-center w-20 h-20 border-2 border-dashed border-gray-600 hover:border-gray-500 rounded-lg text-gray-500 hover:text-gray-400 transition-colors disabled:opacity-50"
747 >
748 <Upload className="w-4 h-4" />
749 <span className="text-[10px] mt-0.5">Add</span>
750 </button>
751 )}
752 </div>
753 </div>
754 )}
755​
756 {attachError && (
757 <p
758 role="alert"
759 className="text-sm text-red-400 bg-red-950/40 border border-red-900/60 rounded-lg px-3 py-2"
760 >
761 {attachError}
762 </p>
763 )}
764​
765 <input
766 ref={firstFrameInputRef}
767 type="file"
768 accept="image/*"
769 className="hidden"
770 onChange={(e) => attachFile(e, setFirstFrame)}
771 />
772 <input
773 ref={lastFrameInputRef}
774 type="file"
775 accept="image/*"
776 className="hidden"
777 onChange={(e) => attachFile(e, setLastFrame)}
778 />
779 <input
780 ref={referenceInputRef}
781 type="file"
782 accept="image/*"
783 className="hidden"
784 onChange={(e) =>
785 attachFile(e, (media) =>
786 setReferences((prev) =>
787 // The template's own reference images share this budget.
788 [...prev, media].slice(
789 0,
790 MAX_REFERENCE_IMAGES - templateImageCount,
791 ),
792 ),
793 )
794 }
795 />
796 </section>
797​
798 <section className="bg-gray-800/50 border border-gray-700 rounded-xl p-6 space-y-4">
799 <div>
800 <h2 className="text-lg font-medium text-white">Model</h2>
801 <p className="text-sm text-gray-400">
802 Each model exposes a different slice of the Seedance request — the
803 image-conditioning modes above and the output controls below both
804 follow the one you pick.
805 </p>
806 </div>
807 <div className="space-y-3">
808 <select
809 value={unknownMode ? '' : modelId}
810 onChange={(e) => {
811 const picked = SEEDANCE_MODELS.find(
812 (model) => model.id === e.target.value,
813 )
814 if (picked) setModelId(picked.id)
815 }}
816 disabled={modelSelectDisabled}
817 className="w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm text-white focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:opacity-50 disabled:cursor-not-allowed"
818 >
819 {unknownMode && (
820 <option value="">Custom model id: {activeModel}</option>
821 )}
822 {SEEDANCE_MODELS.map((model) => (
823 <option key={model.id} value={model.id}>
824 {model.name} ({model.id})
825 </option>
826 ))}
827 </select>
828 {catalogEntry && !unknownMode && (
829 <div className="p-3 bg-gray-800 border border-gray-700 rounded-lg">
830 <div className="text-xs text-cyan-300">
831 {describeSeedanceModel(
832 catalogEntry,
833 capabilities.find((c) => c.model === catalogEntry.id),
834 )}
835 </div>
836 <div className="text-xs text-gray-400 mt-1">
837 {catalogEntry.blurb}
838 </div>
839 </div>
840 )}
841 </div>
842​
843 <div className="pt-2 border-t border-gray-700">
844 <button
845 onClick={() => setShowAdvanced((prev) => !prev)}
846 disabled={isBusy}
847 className="flex items-center gap-1.5 text-sm text-gray-400 hover:text-gray-200 transition-colors disabled:opacity-50"
848 >
849 {showAdvanced ? (
850 <ChevronDown className="w-4 h-4" />
851 ) : (
852 <ChevronRight className="w-4 h-4" />
853 )}
854 Advanced: custom model id
855 </button>
856​
857 {showAdvanced && (
858 <div className="mt-3 space-y-3">
859 <input
860 type="text"
861 value={customModelId}
862 onChange={(e) => setCustomModelId(e.target.value)}
863 placeholder={SEEDANCE_CUSTOM_MODEL_PLACEHOLDER}
864 disabled={isBusy}
865 spellCheck={false}
866 className="w-full px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg text-sm font-mono text-white placeholder-gray-600 focus:outline-none focus:ring-2 focus:ring-amber-500 focus:border-transparent disabled:opacity-50"
867 />
868 <p className="text-xs text-gray-500">
869 For a Seedance model BytePlus ships between releases of{' '}
870 <code className="text-gray-400">@tanstack/ai-byteplus</code>.
871 Leave it empty to go back to the picker.
872 </p>
873 {unknownMode && (
874 <div className="flex items-start gap-3 p-3 bg-amber-500/10 border border-amber-500/30 rounded-lg">
875 <AlertTriangle className="w-4 h-4 text-amber-400 shrink-0 mt-0.5" />
876 <p className="text-xs text-amber-200/90">
877 Capabilities unverified — every option below is enabled and
878 the API validates the request, because the adapter switches
879 its per-model guards off for an id it has no table for. A
880 model that is not activated on your Ark account returns 404{' '}
881 <code className="text-amber-300">ModelNotOpen</code>.
882 </p>
883 </div>
884 )}
885 </div>
886 )}
887 </div>
888 </section>
889​
890 <section className="bg-gray-800/50 border border-gray-700 rounded-xl p-6 space-y-5">
891 <h2 className="text-lg font-medium text-white">Output</h2>
892​
893 <Control label="Aspect ratio">
894 <div className="flex flex-wrap gap-1">
895 {SEEDANCE_RATIOS.map((option) => (
896 <ChoiceButton
897 key={option}
898 selected={effectiveRatio === option}
899 disabled={isBusy}
900 onClick={() => setRatio(option)}
901 >
902 {option}
903 </ChoiceButton>
904 ))}
905 {hasImageInput && (
906 <ChoiceButton
907 selected={effectiveRatio === 'adaptive'}
908 disabled={isBusy}
909 onClick={() => setRatio('adaptive')}
910 >
911 adaptive
912 </ChoiceButton>
913 )}
914 </div>
915 </Control>
916​
917 <Control
918 label="Resolution"
919 hint={
920 unknownMode
921 ? `sent as "${effectiveRatio}_${requestResolution}" — tiers this package knows, or type your own`
922 : `${entry.name} accepts ${resolutions.join(', ')}`
923 }
924 >
925 <div className="flex flex-wrap items-center gap-1">
926 {resolutions.map((option) => (
927 <ChoiceButton
928 key={option}
929 selected={
930 requestResolution === option && effectiveResolution === option
931 }
932 disabled={isBusy}
933 onClick={() => {
934 setResolution(option)
935 setCustomResolution('')
936 }}
937 >
938 {option}
939 </ChoiceButton>
940 ))}
941 {unknownMode && (
942 <input
943 type="text"
944 value={customResolution}
945 onChange={(e) => setCustomResolution(e.target.value)}
946 placeholder="custom tier"
947 disabled={isBusy}
948 spellCheck={false}
949 className="w-32 px-3 py-1 bg-gray-800 border border-gray-700 rounded-md text-sm text-white placeholder-gray-600 focus:outline-none focus:ring-2 focus:ring-amber-500 disabled:opacity-50"
950 />
951 )}
952 </div>
953 </Control>
954​
955 <Control
956 label="Length"
957 hint={
958 framesActive
959 ? `${effectiveFrames} frames ≈ ${(effectiveFrames / SEEDANCE_FPS).toFixed(2)}s at ${SEEDANCE_FPS} fps`
960 : unknownMode
961 ? 'whole seconds, sent verbatim — no range is assumed for a model this package has no table for'
962 : `${durationRange.min}-${durationRange.max}s, whole seconds`
963 }
964 >
965 <div className="space-y-2">
966 {framesActive ? (
967 <div className="flex items-center gap-3">
968 <input
969 type="range"
970 min={SEEDANCE_MIN_FRAMES}
971 max={SEEDANCE_MAX_FRAMES}
972 step={4}
973 value={effectiveFrames}
974 disabled={isBusy}
975 onChange={(e) => setFrames(Number(e.target.value))}
976 className="w-48 accent-blue-500"
977 />
978 <span className="text-sm text-gray-300 w-24">
979 {effectiveFrames} frames
980 </span>
981 </div>
982 ) : unknownMode ? (
983 <div className="flex items-center gap-3">
984 <input
985 type="number"
986 min={1}
987 step={1}
988 value={effectiveDuration}
989 disabled={isBusy || autoDurationActive}
990 onChange={(e) => setDuration(Number(e.target.value))}
991 className="w-28 px-3 py-1.5 bg-gray-800 border border-gray-700 rounded-lg text-sm text-white focus:outline-none focus:ring-2 focus:ring-amber-500 disabled:opacity-50"
992 />
993 <span className="text-sm text-gray-300">
994 {autoDurationActive ? 'model picks' : 'seconds'}
995 </span>
996 </div>
997 ) : (
998 <div className="flex items-center gap-3">
999 <input
1000 type="range"
1001 min={durationRange.min}
1002 max={durationRange.max}
1003 step={durationRange.step}
1004 value={effectiveDuration}
1005 disabled={isBusy || autoDurationActive}
1006 onChange={(e) => setDuration(Number(e.target.value))}
1007 className="w-48 accent-blue-500 disabled:opacity-50"
1008 />
1009 <span className="text-sm text-gray-300 w-24">
1010 {autoDurationActive ? 'model picks' : `${effectiveDuration}s`}
1011 </span>
1012 </div>
1013 )}
1014 <div className="flex flex-wrap gap-4">
1015 {entry.extras.autoDuration && (
1016 <Toggle
1017 label="Let the model choose the length"
1018 hint="Sends duration: -1 (Seedance 2.0 and 1.5-pro only)"
1019 checked={autoDurationActive}
1020 // No catalog model offers both a frame count and a
1021 // model-chosen length, but a custom id offers everything —
1022 // and `frames` wins over `duration` server-side, so the two
1023 // must not read as simultaneously on.
1024 disabled={isBusy || framesActive}
1025 onChange={setAutoDuration}
1026 />
1027 )}
1028 {entry.extras.frames && (
1029 <Toggle
1030 label="Use a frame count instead"
1031 hint={`Fractional-second output on the 25 + 4n grid, ${SEEDANCE_FPS} fps`}
1032 checked={framesActive}
1033 disabled={isBusy}
1034 onChange={setUseFrames}
1035 />
1036 )}
1037 </div>
1038 </div>
1039 </Control>
1040​
1041 <Control label="Seed" hint="-1 or empty leaves generation unseeded">
1042 <div className="flex items-center gap-2">
1043 <input
1044 type="number"
1045 min={MIN_SEED}
1046 max={MAX_SEED}
1047 step={1}
1048 value={seed}
1049 onChange={(e) => setSeed(e.target.value)}
1050 placeholder="unseeded"
1051 disabled={isBusy}
1052 className="w-40 px-3 py-1.5 bg-gray-800 border border-gray-700 rounded-lg text-sm text-white placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-50"
1053 />
1054 <button
1055 onClick={() =>
1056 setSeed(String(Math.floor(Math.random() * 2 ** 32)))
1058 disabled={isBusy}
1059 className="flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-blue-400 hover:text-blue-300 bg-blue-500/10 hover:bg-blue-500/20 rounded-md transition-colors disabled:opacity-50"
1061 <Dices className="w-3.5 h-3.5" />
1062 Random
1063 </button>
1064 </div>
1065 </Control>
1066​
1067 <div className="grid gap-3 sm:grid-cols-2 pt-2 border-t border-gray-700">
1068 <Toggle
1069 label="Watermark"
1070 hint="Burn a watermark into the output"
1071 checked={watermark}
1072 disabled={isBusy}
1073 onChange={setWatermark}
1074 />
1075 {/* No `return_last_frame` control: its PNG comes back on the task as
1076 `content.last_frame_url`, which neither the adapter's
1077 `getVideoUrl` nor core's `VideoUrlResult` carries, so the studio
1078 could offer the toggle but never show you the frame. */}
1079 {entry.extras.generateAudio && (
1080 <Toggle
1081 label="Generate audio"
1082 hint="Dialogue, effects and score inferred from the prompt"
1083 checked={generateAudio}
1084 disabled={isBusy}
1085 onChange={setGenerateAudio}
1086 />
1087 )}
1088 {entry.extras.cameraFixed && (
1089 <Toggle
1090 label="Fixed camera"
1091 hint="Best-effort 'hold the camera still' instruction (Seedance 1.x)"
1092 checked={cameraFixed}
1093 disabled={isBusy}
1094 onChange={setCameraFixed}
1095 />
1096 )}
1097 {entry.extras.serviceTier && (
1098 <Toggle
1099 label="Flex tier"
1100 hint="Offline batch queue: half price, no latency guarantee — expect a long wait"
1101 checked={flexTier}
1102 disabled={isBusy}
1103 onChange={setFlexTier}
1104 />
1105 )}
1106 {entry.extras.draft && (
1107 <Toggle
1108 label="Draft render"
1109 hint="Cheap low-fidelity preview to check staging (Seedance 1.5-pro)"
1110 checked={draft}
1111 disabled={isBusy}
1112 onChange={setDraft}
1113 />
1114 )}
1115 </div>
1116​
1117 {entry.extras.priority && (
1118 <Control label="Queue priority" hint="0-9, Seedance 2.5 / 2.0 family">
1119 <div className="flex items-center gap-3">
1120 <input
1121 type="range"
1122 min={0}
1123 max={9}
1124 step={1}
1125 value={priority}
1126 disabled={isBusy}
1127 onChange={(e) => setPriority(Number(e.target.value))}
1128 className="w-48 accent-blue-500"
1129 />
1130 <span className="text-sm text-gray-300 w-8">{priority}</span>
1131 </div>
1132 </Control>
1133 )}
1134 </section>
1135​
1136 <div className="space-y-2">
1137 <button
1138 onClick={handleGenerate}
1139 disabled={isBusy || !readyToGenerate}
1140 className="w-full px-6 py-3 bg-blue-600 hover:bg-blue-700 disabled:bg-gray-700 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors flex items-center justify-center gap-2"
1142 {isBusy ? (
1143 <>
1144 <Loader2 className="w-5 h-5 animate-spin" />
1145 Generating...
1146 </>
1147 ) : (
1148 <>
1149 <Film className="w-5 h-5" />
1150 Generate with {entry.name}
1151 </>
1152 )}
1153 </button>
1154 {audioOnlyReferences && (
1155 <p className="text-xs text-amber-400/80 text-center">
1156 Reference audio can't be the only reference — pair it with a
1157 reference image or video.
1158 </p>
1159 )}
1160 </div>
1161​
1162 {(isBusy || error || result) && (
1163 <section className="bg-gray-800/50 border border-gray-700 rounded-xl p-6 space-y-4">
1164 {isBusy && !jobId && (
1165 <div className="flex items-center gap-2 text-gray-400">
1166 <Loader2 className="w-5 h-5 animate-spin text-blue-400" />
1167 Submitting the task...
1168 </div>
1169 )}
1170​
1171 {isBusy && jobId && (
1172 <div className="space-y-2">
1173 <div className="flex items-center gap-2 text-gray-300">
1174 <Loader2 className="w-5 h-5 animate-spin text-blue-400" />
1175 <span className="font-medium">
1176 {videoStatus?.status === 'processing'
1177 ? 'Processing'
1178 : 'Queued'}
1179 </span>
1180 <span className="flex items-center gap-1 text-sm text-gray-500">
1181 <Clock className="w-3.5 h-3.5" />
1182 {formatElapsed(now - (startedAt ?? now))}
1183 </span>
1184 </div>
1185 <p className="text-xs text-gray-500 font-mono">{jobId}</p>
1186 {settings?.serviceTier === 'flex' && (
1187 <p className="text-xs text-amber-400/80">
1188 Flex is the offline batch queue — tasks routinely sit here for
1189 many minutes before they start.
1190 </p>
1191 )}
1192 </div>
1193 )}
1194​
1195 {error && !isBusy && (
1196 <div className="p-4 bg-red-500/10 border border-red-500/20 rounded-lg text-red-400 text-sm">
1197 {error.message}
1198 </div>
1199 )}
1200​
1201 {/* `!error`: a failed task keeps the previous result on the hook,
1202 and it must not render underneath the new error. */}
1203 {result && !isBusy && !error && settings && (
1204 <div className="space-y-3">
1205 <div className="rounded-lg overflow-hidden border border-gray-700">
1206 <video
1207 src={result.url}
1208 controls
1209 autoPlay
1210 loop
1211 className="w-full h-auto"
1212 />
1213 </div>
1214 <dl className="grid grid-cols-2 sm:grid-cols-3 gap-x-4 gap-y-2 text-xs">
1215 <Meta label="Model" value={settings.model} />
1216 <Meta
1217 label="Output"
1218 value={`${settings.ratio} · ${settings.resolution}`}
1219 />
1220 <Meta
1221 label="Length"
1222 value={
1223 settings.frames !== null
1224 ? `${settings.frames} frames @ ${SEEDANCE_FPS} fps`
1225 : settings.duration === -1
1226 ? 'model-chosen'
1227 : `${settings.duration}s`
1229 />
1230 <Meta
1231 label="Seed"
1232 value={
1233 settings.seed === null || settings.seed === -1
1234 ? 'unseeded'
1235 : String(settings.seed)
1237 />
1238 {settings.serviceTier && (
1239 <Meta label="Tier" value={settings.serviceTier} />
1240 )}
1241 {startedAt !== null && finishedAt !== null && (
1242 <Meta
1243 label="Wall clock"
1244 value={formatElapsed(finishedAt - startedAt)}
1245 />
1246 )}
1247 {billing?.totalTokens != null && (
1248 <Meta
1249 label="Billed tokens"
1250 value={`${billing.totalTokens}`}
1251 />
1252 )}
1253 </dl>
1254 <div className="flex items-center justify-between gap-4">
1255 <a
1256 href={result.url}
1257 download
1258 target="_blank"
1259 rel="noreferrer"
1260 className="flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-blue-400 hover:text-blue-300 bg-blue-500/10 hover:bg-blue-500/20 rounded-md transition-colors"
1262 <Download className="w-4 h-4" />
1263 Download
1264 </a>
1265 <p className="text-xs text-amber-400/80 text-right">
1266 BytePlus deletes this URL 24 hours after the task finishes
1267 {/* Typed `Date`, but it crosses the wire as an ISO string —
1268 `new Date` takes either. */}
1269 {result.expiresAt
1270 ? ` — ${new Date(result.expiresAt).toLocaleString()}`
1271 : ''}
1272 . Download anything you want to keep.
1273 </p>
1274 </div>
1275 </div>
1276 )}
1277 </section>
1278 )}
1279 </div>
1282​
1283function Control({
1284 label,
1285 hint,
1286 children,
1287}: {
1288 label: string
1289 hint?: string
1290 children: React.ReactNode
1291}) {
1292 return (
1293 <div className="space-y-1.5">
1294 <div className="flex flex-wrap items-baseline gap-2">
1295 <span className="text-sm font-medium text-gray-300">{label}</span>
1296 {hint && <span className="text-xs text-gray-500">{hint}</span>}
1297 </div>
1298 {children}
1299 </div>
1302​
1303function ChoiceButton({
1304 selected,
1305 disabled,
1306 onClick,
1307 children,
1308}: {
1309 selected: boolean
1310 disabled: boolean
1311 onClick: () => void
1312 children: React.ReactNode
1313}) {
1314 return (
1315 <button
1316 onClick={onClick}
1317 disabled={disabled}
1318 className={`px-3 py-1 text-sm rounded-md transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${
1319 selected
1320 ? 'bg-blue-600 text-white'
1321 : 'bg-gray-700 text-gray-300 hover:bg-gray-600'
1322 }`}
1324 {children}
1325 </button>
1328​
1329function Toggle({
1330 label,
1331 hint,
1332 checked,
1333 disabled,
1334 onChange,
1335}: {
1336 label: string
1337 hint: string
1338 checked: boolean
1339 disabled: boolean
1340 onChange: (value: boolean) => void
1341}) {
1342 return (
1343 <label
1344 title={hint}
1345 className={`flex items-start gap-2 text-sm ${
1346 disabled ? 'opacity-50' : 'cursor-pointer'
1347 }`}
1349 <input
1350 type="checkbox"
1351 checked={checked}
1352 disabled={disabled}
1353 onChange={(e) => onChange(e.target.checked)}
1354 className="mt-0.5 accent-blue-500"
1355 />
1356 <span>
1357 <span className="text-gray-300">{label}</span>
1358 <span className="block text-xs text-gray-500">{hint}</span>
1359 </span>
1360 </label>
1363​
1364function Meta({ label, value }: { label: string; value: string }) {
1365 return (
1366 <div>
1367 <dt className="text-gray-500">{label}</dt>
1368 <dd className="text-gray-300 break-all">{value}</dd>
1369 </div>
1372​
1373function FramePicker({
1374 label,
1375 media,
1376 disabled,
1377 onPick,
1378 onClear,
1379}: {
1380 label: string
1381 media: AttachedMedia | null
1382 disabled: boolean
1383 onPick: () => void
1384 onClear: () => void
1385}) {
1386 return (
1387 <div>
1388 <label className="block text-sm font-medium text-gray-300 mb-2">
1389 {label}
1390 </label>
1391 {media ? (
1392 <div className="relative">
1393 <img
1394 src={media.dataUrl}
1395 alt={label}
1396 className="w-full max-h-48 object-contain rounded-lg border border-gray-700"
1397 />
1398 <button
1399 onClick={onClear}
1400 disabled={disabled}
1401 className="absolute top-2 right-2 p-1 bg-gray-900/80 hover:bg-gray-800 rounded-full text-white disabled:opacity-50"
1403 <X className="w-4 h-4" />
1404 </button>
1405 </div>
1406 ) : (
1407 <button
1408 onClick={onPick}
1409 disabled={disabled}
1410 className="w-full p-6 border-2 border-dashed border-gray-600 hover:border-gray-500 rounded-lg text-gray-400 hover:text-gray-300 transition-colors flex flex-col items-center gap-2 disabled:opacity-50"
1412 <Upload className="w-6 h-6" />
1413 <span className="text-sm">Upload an image</span>
1414 </button>
1415 )}
1416 </div>