import React, { useEffect, useState } from "react"; /** * Regeneration options for adjusting story output. * * Allows users to refine output without re-prompting by selecting * predefined constraints like "More Romantic" or "Fade to Black". */ export function RegenerationOptions({ onSelect, currentPrompt }) { const [options, setOptions] = useState([]); const [loading, setLoading] = useState(false); const [selectedId, setSelectedId] = useState(null); useEffect(() => { fetch("/studio/regeneration-options") .then((r) => r.json()) .then((j) => setOptions(j.options || [])) .catch(() => { }); }, []); async function applyConstraint(constraintId) { setLoading(true); setSelectedId(constraintId); try { const r = await fetch("/studio/prompt/regenerate", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ prompt: currentPrompt, constraint_id: constraintId, }), }); const j = await r.json(); onSelect(constraintId, j.prompt); } catch (e) { console.error("Failed to apply constraint:", e); } finally { setLoading(false); } } if (!options.length) { return null; } return (