Spaces:
Running
Running
Update js/iaConfigModule.js
Browse files- js/iaConfigModule.js +125 -141
js/iaConfigModule.js
CHANGED
|
@@ -12,28 +12,25 @@ const defaultConfig = {
|
|
| 12 |
}
|
| 13 |
};
|
| 14 |
|
| 15 |
-
// Lista de modelos actualizada
|
| 16 |
export const llmProviders = [
|
| 17 |
-
{
|
| 18 |
-
name: "OpenAI",
|
| 19 |
-
value: "openai",
|
| 20 |
models: [
|
|
|
|
| 21 |
"gpt-5",
|
| 22 |
-
"gpt-5-mini",
|
| 23 |
-
"gpt-
|
| 24 |
-
"gpt-
|
| 25 |
-
"gpt-4o-mini-2024-07-18",
|
| 26 |
-
"chatgpt-4o-latest",
|
| 27 |
-
"o1-mini-2024-09-12",
|
| 28 |
-
"o4-mini-2025-04-16"
|
| 29 |
],
|
| 30 |
url: "https://api.openai.com"
|
| 31 |
},
|
| 32 |
-
{
|
| 33 |
-
name: "DeepSeek",
|
| 34 |
-
value: "deepseek",
|
| 35 |
-
models: ["deepseek-chat", "deepseek-reasoner"],
|
| 36 |
-
url: "https://api.deepseek.com"
|
| 37 |
}
|
| 38 |
];
|
| 39 |
|
|
@@ -62,36 +59,39 @@ function loadConfig() {
|
|
| 62 |
config = clone(defaultConfig);
|
| 63 |
}
|
| 64 |
|
| 65 |
-
//
|
|
|
|
|
|
|
| 66 |
if (config.transcription.apiKey !== undefined) {
|
|
|
|
| 67 |
const oldKey = config.transcription.apiKey;
|
| 68 |
const oldModel = config.transcription.model;
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
delete config.transcription.apiKey;
|
| 72 |
delete config.transcription.model;
|
| 73 |
saveConfig(config);
|
| 74 |
}
|
| 75 |
|
| 76 |
-
// Migraci贸n LLM apiKey -> apiKeys
|
| 77 |
if (config.llm.apiKey !== undefined) {
|
|
|
|
| 78 |
const old = config.llm.apiKey;
|
| 79 |
config.llm.apiKeys = { ...defaultConfig.llm.apiKeys, [config.llm.provider]: old };
|
| 80 |
delete config.llm.apiKey;
|
| 81 |
saveConfig(config);
|
| 82 |
}
|
| 83 |
|
| 84 |
-
//
|
| 85 |
if (config.llm.provider === "deepseek" && (config.llm.model === "deepseek-v3" || config.llm.model === "deepseek-llm")) {
|
| 86 |
config.llm.model = "deepseek-chat";
|
| 87 |
-
console.log("[iaConfigModule] Migrado modelo DeepSeek a deepseek-chat");
|
| 88 |
saveConfig(config);
|
| 89 |
}
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
if (config.llm.provider === "openai") {
|
| 93 |
-
if (config.llm.model === "gpt-5-2025-05-01") config.llm.model = "gpt-5";
|
| 94 |
-
if (config.llm.model === "gpt-5-mini-2025-05-01") config.llm.model = "gpt-5-mini";
|
| 95 |
saveConfig(config);
|
| 96 |
}
|
| 97 |
|
|
@@ -106,164 +106,148 @@ export function renderIaConfigForm(containerId) {
|
|
| 106 |
const container = document.getElementById(containerId);
|
| 107 |
if (!container) {
|
| 108 |
console.error(`[iaConfigModule] No se encontr贸 el contenedor '${containerId}'`);
|
| 109 |
-
document.body.insertAdjacentHTML(
|
| 110 |
-
"beforeend",
|
| 111 |
-
`<div style='color:red'>[Error] No se encontr贸 el contenedor '${containerId}' para la configuraci贸n IA.</div>`
|
| 112 |
-
);
|
| 113 |
return;
|
| 114 |
}
|
| 115 |
|
| 116 |
function maskApiKey(key) {
|
| 117 |
if (!key) return "";
|
| 118 |
if (key.length <= 8) return "*".repeat(key.length);
|
| 119 |
-
return key.substring(0, 3)
|
| 120 |
}
|
| 121 |
|
| 122 |
container.innerHTML = `
|
| 123 |
<div class="flex justify-between items-center mb-6 border-b pb-2 border-blue-100">
|
| 124 |
-
<h2 class="text-xl font-bold text-blue-700 flex items-center">
|
| 125 |
-
|
| 126 |
-
</h2>
|
| 127 |
-
<button id="btnCloseConfig" type="button" class="text-gray-500 hover:text-blue-600 text-2xl focus:outline-none" aria-label="Cerrar">
|
| 128 |
-
<i class="fas fa-times"></i>
|
| 129 |
-
</button>
|
| 130 |
</div>
|
| 131 |
<form id="iaConfigForm" class="space-y-6">
|
| 132 |
-
<div class="bg-blue-50 p-4 rounded-lg border border-blue-100
|
| 133 |
<label class="block font-semibold text-blue-800 mb-2">Proveedor LLM</label>
|
| 134 |
-
<select id="llmProvider" class="w-full mb-3 p-2 rounded border border-gray-300 focus:ring-2 focus:ring-blue-300">
|
| 135 |
-
${llmProviders.map(p => `<option value="${p.value}">${p.name}</option>`).join("")}
|
| 136 |
-
</select>
|
| 137 |
<div class="flex items-center mb-3">
|
| 138 |
<input type="password" id="llmApiKey" class="flex-1 p-2 rounded border border-gray-300 mr-2 bg-gray-100" placeholder="API Key LLM" autocomplete="off">
|
| 139 |
-
<button class="text-blue-700 hover:text-blue-900 px-3 py-2 rounded focus:outline-none border border-blue-200 bg-white" type="button" id="toggleLlmApiKey">
|
| 140 |
-
<i class="fas fa-eye"></i>
|
| 141 |
-
</button>
|
| 142 |
</div>
|
| 143 |
<select id="llmModel" class="w-full p-2 rounded border border-gray-300 focus:ring-2 focus:ring-blue-300"></select>
|
| 144 |
</div>
|
| 145 |
-
<div class="bg-purple-50 p-4 rounded-lg border border-purple-100
|
| 146 |
<label class="block font-semibold text-purple-800 mb-2">Proveedor Transcripci贸n</label>
|
| 147 |
-
<select id="transProvider" class="w-full mb-3 p-2 rounded border border-gray-300 focus:ring-2 focus:ring-purple-300">
|
| 148 |
-
${transcriptionProviders.map(p => `<option value="${p.value}">${p.name}</option>`).join("")}
|
| 149 |
-
</select>
|
| 150 |
<div class="flex items-center mb-3">
|
| 151 |
<input type="password" id="transApiKey" class="flex-1 p-2 rounded border border-gray-300 mr-2 bg-gray-100" placeholder="API Key Transcripci贸n" autocomplete="off">
|
| 152 |
-
<button class="text-purple-700 hover:text-purple-900 px-3 py-2 rounded focus:outline-none border border-purple-200 bg-white" type="button" id="toggleTransApiKey">
|
| 153 |
-
<i class="fas fa-eye"></i>
|
| 154 |
-
</button>
|
| 155 |
</div>
|
| 156 |
<select id="transModel" class="w-full p-2 rounded border border-gray-300 focus:ring-2 focus:ring-purple-300"></select>
|
| 157 |
</div>
|
| 158 |
-
<button type="submit" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-semibold py-3 rounded-lg shadow transition-colors flex items-center justify-center text-lg">
|
| 159 |
-
|
| 160 |
-
</button>
|
| 161 |
-
</form>
|
| 162 |
-
`;
|
| 163 |
|
| 164 |
const closeBtn = document.getElementById("btnCloseConfig");
|
| 165 |
if (closeBtn) {
|
| 166 |
-
closeBtn.addEventListener("click", () =>
|
| 167 |
-
const modal = document.getElementById("configModal");
|
| 168 |
-
if (modal) modal.classList.remove("active");
|
| 169 |
-
});
|
| 170 |
}
|
| 171 |
|
| 172 |
-
|
| 173 |
-
document.getElementById("
|
| 174 |
-
document.getElementById("llmApiKey")
|
| 175 |
-
document.getElementById("transProvider")
|
| 176 |
-
document.getElementById("
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
if (!models.includes(config.llm.model)) {
|
| 196 |
-
config.llm.model = models[0];
|
| 197 |
-
saveConfig(config);
|
| 198 |
}
|
| 199 |
-
|
| 200 |
}
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
const
|
| 204 |
-
const
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
document.getElementById("transApiKey").value = maskApiKey(config.transcription.apiKeys[prov] || "");
|
| 209 |
}
|
| 210 |
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
const fresh = loadConfig();
|
| 215 |
-
const keyEl = document.getElementById("llmApiKey");
|
| 216 |
-
if (keyEl) keyEl.value = maskApiKey(fresh.llm.apiKeys[p] || "");
|
| 217 |
-
});
|
| 218 |
-
document.getElementById("transProvider").addEventListener("change", updateTransModels);
|
| 219 |
|
| 220 |
-
|
| 221 |
-
|
|
|
|
|
|
|
| 222 |
|
|
|
|
|
|
|
| 223 |
document.getElementById("iaConfigForm").addEventListener("submit", e => {
|
| 224 |
e.preventDefault();
|
| 225 |
-
const
|
| 226 |
-
const newConfig = clone(
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
const
|
| 230 |
-
const
|
| 231 |
-
const
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
newConfig.llm
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
saveConfig(newConfig);
|
| 246 |
-
config = newConfig;
|
| 247 |
document.dispatchEvent(new CustomEvent("iaConfigChanged"));
|
| 248 |
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
|
|
|
| 253 |
|
| 254 |
-
|
| 255 |
-
if (!msg) {
|
| 256 |
-
msg = document.createElement('div');
|
| 257 |
msg.id = 'iaConfigSavedMsg';
|
| 258 |
-
msg.className = 'fixed left-1/2 top-6 -translate-x-1/2 bg-green-500 text-white px-6 py-3 rounded shadow text-lg z-50';
|
| 259 |
msg.innerHTML = '<i class="fas fa-check-circle mr-2"></i>隆Configuraci贸n guardada!';
|
| 260 |
document.body.appendChild(msg);
|
| 261 |
-
} else {
|
| 262 |
-
msg.style.display = 'block';
|
| 263 |
}
|
| 264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
-
|
| 267 |
-
if (modal) modal.classList.remove("active");
|
| 268 |
});
|
| 269 |
-
}
|
|
|
|
| 12 |
}
|
| 13 |
};
|
| 14 |
|
| 15 |
+
// CORRECCI脫N: Lista de modelos de IA actualizada a nombres de API realistas para 2025.
|
| 16 |
export const llmProviders = [
|
| 17 |
+
{
|
| 18 |
+
name: "OpenAI",
|
| 19 |
+
value: "openai",
|
| 20 |
models: [
|
| 21 |
+
"gpt-5-pro",
|
| 22 |
"gpt-5",
|
| 23 |
+
"gpt-5-mini", // Nombres plausibles para la serie GPT-5
|
| 24 |
+
"gpt-4o",
|
| 25 |
+
"gpt-4o-mini"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
],
|
| 27 |
url: "https://api.openai.com"
|
| 28 |
},
|
| 29 |
+
{
|
| 30 |
+
name: "DeepSeek",
|
| 31 |
+
value: "deepseek",
|
| 32 |
+
models: ["deepseek-chat", "deepseek-reasoner"],
|
| 33 |
+
url: "https://api.deepseek.com"
|
| 34 |
}
|
| 35 |
];
|
| 36 |
|
|
|
|
| 59 |
config = clone(defaultConfig);
|
| 60 |
}
|
| 61 |
|
| 62 |
+
// CORRECCI脫N: La l贸gica de migraci贸n para la transcripci贸n era defectuosa.
|
| 63 |
+
// No preservaba la API key existente si el proveedor era Deepgram.
|
| 64 |
+
// Ahora usa el mismo patr贸n robusto que la migraci贸n de LLM.
|
| 65 |
if (config.transcription.apiKey !== undefined) {
|
| 66 |
+
console.log("[iaConfigModule] Migrando configuraci贸n de transcripci贸n antigua...");
|
| 67 |
const oldKey = config.transcription.apiKey;
|
| 68 |
const oldModel = config.transcription.model;
|
| 69 |
+
const oldProvider = config.transcription.provider;
|
| 70 |
+
|
| 71 |
+
config.transcription.apiKeys = { ...defaultConfig.transcription.apiKeys, [oldProvider]: oldKey };
|
| 72 |
+
config.transcription.models = { ...defaultConfig.transcription.models, [oldProvider]: oldModel };
|
| 73 |
+
|
| 74 |
delete config.transcription.apiKey;
|
| 75 |
delete config.transcription.model;
|
| 76 |
saveConfig(config);
|
| 77 |
}
|
| 78 |
|
| 79 |
+
// Migraci贸n LLM apiKey -> apiKeys (esta parte estaba bien)
|
| 80 |
if (config.llm.apiKey !== undefined) {
|
| 81 |
+
console.log("[iaConfigModule] Migrando configuraci贸n de LLM antigua...");
|
| 82 |
const old = config.llm.apiKey;
|
| 83 |
config.llm.apiKeys = { ...defaultConfig.llm.apiKeys, [config.llm.provider]: old };
|
| 84 |
delete config.llm.apiKey;
|
| 85 |
saveConfig(config);
|
| 86 |
}
|
| 87 |
|
| 88 |
+
// Migraciones de modelos obsoletos (estas partes estaban bien)
|
| 89 |
if (config.llm.provider === "deepseek" && (config.llm.model === "deepseek-v3" || config.llm.model === "deepseek-llm")) {
|
| 90 |
config.llm.model = "deepseek-chat";
|
|
|
|
| 91 |
saveConfig(config);
|
| 92 |
}
|
| 93 |
+
if (config.llm.provider === "openai" && /gpt-5.*2025/.test(config.llm.model)) {
|
| 94 |
+
config.llm.model = config.llm.model.replace(/-2025-\d{2}-\d{2}/, "");
|
|
|
|
|
|
|
|
|
|
| 95 |
saveConfig(config);
|
| 96 |
}
|
| 97 |
|
|
|
|
| 106 |
const container = document.getElementById(containerId);
|
| 107 |
if (!container) {
|
| 108 |
console.error(`[iaConfigModule] No se encontr贸 el contenedor '${containerId}'`);
|
| 109 |
+
document.body.insertAdjacentHTML("beforeend", `<div style='color:red'>[Error] No se encontr贸 el contenedor '${containerId}'.</div>`);
|
|
|
|
|
|
|
|
|
|
| 110 |
return;
|
| 111 |
}
|
| 112 |
|
| 113 |
function maskApiKey(key) {
|
| 114 |
if (!key) return "";
|
| 115 |
if (key.length <= 8) return "*".repeat(key.length);
|
| 116 |
+
return `${key.substring(0, 3)}-****-${key.slice(-4)}`;
|
| 117 |
}
|
| 118 |
|
| 119 |
container.innerHTML = `
|
| 120 |
<div class="flex justify-between items-center mb-6 border-b pb-2 border-blue-100">
|
| 121 |
+
<h2 class="text-xl font-bold text-blue-700 flex items-center"><i class='fas fa-cogs mr-2'></i>Configurar Proveedores IA</h2>
|
| 122 |
+
<button id="btnCloseConfig" type="button" class="text-gray-500 hover:text-blue-600 text-2xl focus:outline-none" aria-label="Cerrar"><i class="fas fa-times"></i></button>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
</div>
|
| 124 |
<form id="iaConfigForm" class="space-y-6">
|
| 125 |
+
<div class="bg-blue-50 p-4 rounded-lg border border-blue-100">
|
| 126 |
<label class="block font-semibold text-blue-800 mb-2">Proveedor LLM</label>
|
| 127 |
+
<select id="llmProvider" class="w-full mb-3 p-2 rounded border border-gray-300 focus:ring-2 focus:ring-blue-300">${llmProviders.map(p => `<option value="${p.value}">${p.name}</option>`).join("")}</select>
|
|
|
|
|
|
|
| 128 |
<div class="flex items-center mb-3">
|
| 129 |
<input type="password" id="llmApiKey" class="flex-1 p-2 rounded border border-gray-300 mr-2 bg-gray-100" placeholder="API Key LLM" autocomplete="off">
|
| 130 |
+
<button class="text-blue-700 hover:text-blue-900 px-3 py-2 rounded focus:outline-none border border-blue-200 bg-white" type="button" id="toggleLlmApiKey"><i class="fas fa-eye"></i></button>
|
|
|
|
|
|
|
| 131 |
</div>
|
| 132 |
<select id="llmModel" class="w-full p-2 rounded border border-gray-300 focus:ring-2 focus:ring-blue-300"></select>
|
| 133 |
</div>
|
| 134 |
+
<div class="bg-purple-50 p-4 rounded-lg border border-purple-100">
|
| 135 |
<label class="block font-semibold text-purple-800 mb-2">Proveedor Transcripci贸n</label>
|
| 136 |
+
<select id="transProvider" class="w-full mb-3 p-2 rounded border border-gray-300 focus:ring-2 focus:ring-purple-300">${transcriptionProviders.map(p => `<option value="${p.value}">${p.name}</option>`).join("")}</select>
|
|
|
|
|
|
|
| 137 |
<div class="flex items-center mb-3">
|
| 138 |
<input type="password" id="transApiKey" class="flex-1 p-2 rounded border border-gray-300 mr-2 bg-gray-100" placeholder="API Key Transcripci贸n" autocomplete="off">
|
| 139 |
+
<button class="text-purple-700 hover:text-purple-900 px-3 py-2 rounded focus:outline-none border border-purple-200 bg-white" type="button" id="toggleTransApiKey"><i class="fas fa-eye"></i></button>
|
|
|
|
|
|
|
| 140 |
</div>
|
| 141 |
<select id="transModel" class="w-full p-2 rounded border border-gray-300 focus:ring-2 focus:ring-purple-300"></select>
|
| 142 |
</div>
|
| 143 |
+
<button type="submit" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-semibold py-3 rounded-lg shadow transition-colors flex items-center justify-center text-lg"><i class="fas fa-save mr-2"></i>Guardar configuraci贸n</button>
|
| 144 |
+
</form>`;
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
const closeBtn = document.getElementById("btnCloseConfig");
|
| 147 |
if (closeBtn) {
|
| 148 |
+
closeBtn.addEventListener("click", () => document.getElementById("configModal")?.classList.remove("active"));
|
|
|
|
|
|
|
|
|
|
| 149 |
}
|
| 150 |
|
| 151 |
+
const llmProviderSelect = document.getElementById("llmProvider");
|
| 152 |
+
const llmModelSelect = document.getElementById("llmModel");
|
| 153 |
+
const llmApiKeyInput = document.getElementById("llmApiKey");
|
| 154 |
+
const transProviderSelect = document.getElementById("transProvider");
|
| 155 |
+
const transModelSelect = document.getElementById("transModel");
|
| 156 |
+
const transApiKeyInput = document.getElementById("transApiKey");
|
| 157 |
+
|
| 158 |
+
// Toggle visibilidad de API keys
|
| 159 |
+
document.getElementById("toggleLlmApiKey").addEventListener("click", () => { llmApiKeyInput.type = llmApiKeyInput.type === "password" ? "text" : "password"; });
|
| 160 |
+
document.getElementById("toggleTransApiKey").addEventListener("click", () => { transApiKeyInput.type = transApiKeyInput.type === "password" ? "text" : "password"; });
|
| 161 |
+
|
| 162 |
+
// MEJORA: Funciones de actualizaci贸n de UI m谩s seguras y claras.
|
| 163 |
+
// No modifican el objeto 'config' en memoria, solo leen de 茅l.
|
| 164 |
+
function updateLlmUI() {
|
| 165 |
+
const selectedProvider = llmProviderSelect.value;
|
| 166 |
+
const providerObj = llmProviders.find(p => p.value === selectedProvider);
|
| 167 |
+
llmModelSelect.innerHTML = providerObj.models.map(m => `<option value="${m}">${m}</option>`).join("");
|
| 168 |
+
|
| 169 |
+
if (selectedProvider === config.llm.provider && providerObj.models.includes(config.llm.model)) {
|
| 170 |
+
llmModelSelect.value = config.llm.model;
|
| 171 |
+
} else {
|
| 172 |
+
llmModelSelect.value = providerObj.models[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
}
|
| 174 |
+
llmApiKeyInput.value = maskApiKey(config.llm.apiKeys[selectedProvider] || "");
|
| 175 |
}
|
| 176 |
+
|
| 177 |
+
function updateTransUI() {
|
| 178 |
+
const selectedProvider = transProviderSelect.value;
|
| 179 |
+
const providerObj = transcriptionProviders.find(p => p.value === selectedProvider);
|
| 180 |
+
transModelSelect.innerHTML = providerObj.models.map(m => `<option value="${m}">${m}</option>`).join("");
|
| 181 |
+
transModelSelect.value = config.transcription.models[selectedProvider] || providerObj.models[0];
|
| 182 |
+
transApiKeyInput.value = maskApiKey(config.transcription.apiKeys[selectedProvider] || "");
|
|
|
|
| 183 |
}
|
| 184 |
|
| 185 |
+
// Asignar listeners y estado inicial
|
| 186 |
+
llmProviderSelect.addEventListener("change", updateLlmUI);
|
| 187 |
+
transProviderSelect.addEventListener("change", updateTransUI);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
+
llmProviderSelect.value = config.llm.provider;
|
| 190 |
+
transProviderSelect.value = config.transcription.provider;
|
| 191 |
+
updateLlmUI();
|
| 192 |
+
updateTransUI();
|
| 193 |
|
| 194 |
+
// MEJORA: La l贸gica de guardado es m谩s limpia, construyendo nuevos objetos
|
| 195 |
+
// de configuraci贸n con el operador 'spread' para evitar mutaciones inesperadas.
|
| 196 |
document.getElementById("iaConfigForm").addEventListener("submit", e => {
|
| 197 |
e.preventDefault();
|
| 198 |
+
const prevConfig = config;
|
| 199 |
+
const newConfig = clone(prevConfig);
|
| 200 |
+
|
| 201 |
+
// Proceso para LLM
|
| 202 |
+
const llmProv = llmProviderSelect.value;
|
| 203 |
+
const rawLlmKey = llmApiKeyInput.value;
|
| 204 |
+
const oldLlmKey = prevConfig.llm.apiKeys[llmProv] || "";
|
| 205 |
+
const actualLlmKey = rawLlmKey === maskApiKey(oldLlmKey) ? oldLlmKey : rawLlmKey;
|
| 206 |
+
|
| 207 |
+
newConfig.llm = {
|
| 208 |
+
...prevConfig.llm,
|
| 209 |
+
provider: llmProv,
|
| 210 |
+
model: llmModelSelect.value,
|
| 211 |
+
apiKeys: { ...prevConfig.llm.apiKeys, [llmProv]: actualLlmKey }
|
| 212 |
+
};
|
| 213 |
+
|
| 214 |
+
// Proceso para Transcripci贸n
|
| 215 |
+
const transProv = transProviderSelect.value;
|
| 216 |
+
const rawTransKey = transApiKeyInput.value;
|
| 217 |
+
const oldTransKey = prevConfig.transcription.apiKeys[transProv] || "";
|
| 218 |
+
const actualTransKey = rawTransKey === maskApiKey(oldTransKey) ? oldTransKey : rawTransKey;
|
| 219 |
+
|
| 220 |
+
newConfig.transcription = {
|
| 221 |
+
...prevConfig.transcription,
|
| 222 |
+
provider: transProv,
|
| 223 |
+
models: { ...prevConfig.transcription.models, [transProv]: transModelSelect.value },
|
| 224 |
+
apiKeys: { ...prevConfig.transcription.apiKeys, [transProv]: actualTransKey }
|
| 225 |
+
};
|
| 226 |
+
|
| 227 |
+
// Guardar y notificar
|
| 228 |
saveConfig(newConfig);
|
| 229 |
+
config = newConfig; // Actualizar el estado en memoria
|
| 230 |
document.dispatchEvent(new CustomEvent("iaConfigChanged"));
|
| 231 |
|
| 232 |
+
// Actualizar UI post-guardado
|
| 233 |
+
llmApiKeyInput.value = maskApiKey(newConfig.llm.apiKeys[newConfig.llm.provider] || "");
|
| 234 |
+
transApiKeyInput.value = maskApiKey(newConfig.transcription.apiKeys[newConfig.transcription.provider] || "");
|
| 235 |
+
llmApiKeyInput.type = "password";
|
| 236 |
+
transApiKeyInput.type = "password";
|
| 237 |
|
| 238 |
+
const msg = document.getElementById('iaConfigSavedMsg') || document.createElement('div');
|
| 239 |
+
if (!msg.id) {
|
|
|
|
| 240 |
msg.id = 'iaConfigSavedMsg';
|
| 241 |
+
msg.className = 'fixed left-1/2 top-6 -translate-x-1/2 bg-green-500 text-white px-6 py-3 rounded shadow-lg text-lg z-50 transition-opacity duration-300';
|
| 242 |
msg.innerHTML = '<i class="fas fa-check-circle mr-2"></i>隆Configuraci贸n guardada!';
|
| 243 |
document.body.appendChild(msg);
|
|
|
|
|
|
|
| 244 |
}
|
| 245 |
+
|
| 246 |
+
msg.style.opacity = '1';
|
| 247 |
+
msg.style.display = 'block';
|
| 248 |
+
setTimeout(() => { msg.style.opacity = '0'; }, 1600);
|
| 249 |
+
setTimeout(() => { if (msg.style.opacity === '0') msg.style.display = 'none'; }, 1900);
|
| 250 |
|
| 251 |
+
document.getElementById("configModal")?.classList.remove("active");
|
|
|
|
| 252 |
});
|
| 253 |
+
}
|