From d1749209a0fd4cf21b76fbcc60ea38c8579ec8a5 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Mon, 10 Nov 2025 05:51:20 -0500 Subject: [PATCH] Fix voices API parsing - use correct data.data format with model.voices arrays --- public/src/uncloseai-embed-modal.js | 32 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/public/src/uncloseai-embed-modal.js b/public/src/uncloseai-embed-modal.js index ec30f38..02c06c4 100644 --- a/public/src/uncloseai-embed-modal.js +++ b/public/src/uncloseai-embed-modal.js @@ -371,34 +371,32 @@ async function openUncloseaiEmbeddedModalNew() { } const data = await response.json(); - const voices = data.voices || []; + const models = data.data || []; - if (voices.length === 0) { - throw new Error("No voices in API response"); + if (models.length === 0) { + throw new Error("No models in API response"); } voiceSelect.innerHTML = ''; // Clear existing options - loadedVoicesCount = voices.length; - // Group voices by model - const groupedVoices = {}; - voices.forEach(v => { - if (!groupedVoices[v.model]) { - groupedVoices[v.model] = []; - } - groupedVoices[v.model].push(v.voice); - }); + // Count total voices across all models + loadedVoicesCount = models.reduce((sum, model) => sum + (model.voices?.length || 0), 0); // Add options grouped by model - Object.keys(groupedVoices).sort().forEach(model => { + models.forEach(model => { + const voices = model.voices || []; + if (voices.length === 0) return; + const optgroup = document.createElement("optgroup"); - optgroup.label = model; - groupedVoices[model].forEach(voice => { + optgroup.label = model.id; + + voices.forEach(voice => { const option = document.createElement("option"); - option.value = `${model}:${voice}`; // Store model:voice format + option.value = `${model.id}:${voice}`; // Store model:voice format option.textContent = voice.charAt(0).toUpperCase() + voice.slice(1); optgroup.appendChild(option); }); + voiceSelect.appendChild(optgroup); }); @@ -408,7 +406,7 @@ async function openUncloseaiEmbeddedModalNew() { voiceSelect.value = savedVoice; } - console.log("Voices loaded:", voices.length, "voices from API"); + console.log("Voices loaded:", loadedVoicesCount, "voices from", models.length, "models"); }; // Save voice selection to localStorage when changed