async function go(prompt) { const cont = document.getElementById('content'), choi = document.getElementById('choices'), imgBox = document.getElementById('image-container'), imgStatus = document.getElementById('img-status'); choi.innerHTML = 'Kirjoitetaan ja piirretään...'; imgBox.style.display = "flex"; imgStatus.style.display = "block"; const oldImg = imgBox.querySelector('img'); if(oldImg) oldImg.remove(); // 1. KUVA TAUSTALLA const imgPrompt = `${hero} ${pers} ${env} fairy tale illustration`; fetch(API_URL, { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({type: 'image', prompt: imgPrompt}) }).then(r => r.json()).then(d => { if(d.imageUrl) { const img = document.createElement('img'); img.src = d.imageUrl; img.onload = () => { imgStatus.style.display = 'none'; }; imgBox.appendChild(img); } }).catch(e => console.error("Kuva-virhe:", e)); // 2. TEKSTI history.push({role: 'user', content: prompt}); try { const data = await call(history); const storyText = data.text; history.push({role: 'assistant', content: storyText}); lueAaneen(storyText); typeOut(cont, storyText, async () => { // Jatkovalinnat haetaan tässä... }); } catch(e) { choi.innerHTML = "Virhe: " + e.message; } }