Spaces:
Running
Running
Update js/iaConfigModule.js
Browse files- js/iaConfigModule.js +78 -28
js/iaConfigModule.js
CHANGED
|
@@ -18,14 +18,18 @@ export const llmProviders = [
|
|
| 18 |
name: "OpenAI",
|
| 19 |
value: "openai",
|
| 20 |
models: [
|
| 21 |
-
|
| 22 |
-
"gpt-5
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
"gpt-4o-mini-2024-07-18",
|
| 24 |
"chatgpt-4o-latest",
|
| 25 |
"o1-mini-2024-09-12",
|
| 26 |
"o4-mini-2025-04-16"
|
| 27 |
-
],
|
| 28 |
-
url: "https://api.openai.com"
|
| 29 |
},
|
| 30 |
{
|
| 31 |
name: "DeepSeek",
|
|
@@ -34,6 +38,7 @@ export const llmProviders = [
|
|
| 34 |
url: "https://api.deepseek.com"
|
| 35 |
}
|
| 36 |
];
|
|
|
|
| 37 |
export const transcriptionProviders = [
|
| 38 |
{ name: "OpenAI Whisper", value: "openai", models: ["whisper-1"], url: "https://api.openai.com" },
|
| 39 |
{ name: "Deepgram", value: "deepgram", models: ["nova-2", "whisper-large"], url: "https://api.deepgram.com" }
|
|
@@ -42,8 +47,10 @@ export const transcriptionProviders = [
|
|
| 42 |
function saveConfig(config) {
|
| 43 |
localStorage.setItem("iaConfig", JSON.stringify(config));
|
| 44 |
}
|
|
|
|
| 45 |
function loadConfig() {
|
| 46 |
-
const config = JSON.parse(localStorage.getItem("iaConfig")) || defaultConfig;
|
|
|
|
| 47 |
// Migrar configuración antigua de transcription
|
| 48 |
if (config.transcription.apiKey !== undefined) {
|
| 49 |
const oldKey = config.transcription.apiKey;
|
|
@@ -54,6 +61,7 @@ function loadConfig() {
|
|
| 54 |
delete config.transcription.model;
|
| 55 |
saveConfig(config);
|
| 56 |
}
|
|
|
|
| 57 |
// Migrar configuración antigua de LLM apiKey a apiKeys
|
| 58 |
if (config.llm.apiKey !== undefined) {
|
| 59 |
const old = config.llm.apiKey;
|
|
@@ -61,14 +69,24 @@ function loadConfig() {
|
|
| 61 |
delete config.llm.apiKey;
|
| 62 |
saveConfig(config);
|
| 63 |
}
|
|
|
|
| 64 |
// Migrar modelos obsoletos de DeepSeek a 'deepseek-chat'
|
| 65 |
-
if (config.llm.provider ===
|
| 66 |
-
config.llm.model =
|
| 67 |
-
console.log(
|
| 68 |
saveConfig(config);
|
| 69 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
return config;
|
| 71 |
}
|
|
|
|
| 72 |
export function getIaConfig() {
|
| 73 |
return loadConfig();
|
| 74 |
}
|
|
@@ -78,14 +96,17 @@ export function renderIaConfigForm(containerId) {
|
|
| 78 |
const container = document.getElementById(containerId);
|
| 79 |
if (!container) {
|
| 80 |
console.error(`[iaConfigModule] No se encontró el contenedor '${containerId}'`);
|
| 81 |
-
document.body.insertAdjacentHTML(
|
|
|
|
|
|
|
|
|
|
| 82 |
return;
|
| 83 |
}
|
| 84 |
|
| 85 |
function maskApiKey(key) {
|
| 86 |
-
if (!key) return
|
| 87 |
-
if (key.length <= 8) return
|
| 88 |
-
return key.substring(0, 3) +
|
| 89 |
}
|
| 90 |
|
| 91 |
container.innerHTML = `
|
|
@@ -141,9 +162,9 @@ export function renderIaConfigForm(containerId) {
|
|
| 141 |
|
| 142 |
// Set initial values
|
| 143 |
document.getElementById("llmProvider").value = config.llm.provider;
|
| 144 |
-
document.getElementById("llmApiKey").value = maskApiKey(config.llm.apiKeys[config.llm.provider] ||
|
| 145 |
document.getElementById("transProvider").value = config.transcription.provider;
|
| 146 |
-
document.getElementById("transApiKey").value = maskApiKey(config.transcription.apiKeys[config.transcription.provider] ||
|
| 147 |
|
| 148 |
// API Key toggle (ver/ocultar)
|
| 149 |
document.getElementById("toggleLlmApiKey").addEventListener("click", () => {
|
|
@@ -162,8 +183,15 @@ export function renderIaConfigForm(containerId) {
|
|
| 162 |
const models = providerObj.models;
|
| 163 |
const sel = document.getElementById("llmModel");
|
| 164 |
sel.innerHTML = models.map(m => `<option value="${m}">${m}</option>`).join("");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
sel.value = config.llm.model;
|
| 166 |
}
|
|
|
|
| 167 |
function updateTransModels() {
|
| 168 |
const prov = document.getElementById("transProvider").value;
|
| 169 |
const providerObj = transcriptionProviders.find(p => p.value === prov);
|
|
@@ -171,56 +199,78 @@ export function renderIaConfigForm(containerId) {
|
|
| 171 |
const sel = document.getElementById("transModel");
|
| 172 |
sel.innerHTML = models.map(m => `<option value="${m}">${m}</option>`).join("");
|
| 173 |
sel.value = config.transcription.models[prov] || models[0];
|
| 174 |
-
|
|
|
|
| 175 |
}
|
|
|
|
| 176 |
document.getElementById("llmProvider").addEventListener("change", () => {
|
| 177 |
const p = document.getElementById("llmProvider").value;
|
| 178 |
updateLlmModels();
|
|
|
|
| 179 |
const fresh = loadConfig();
|
| 180 |
const keyEl = document.getElementById("llmApiKey");
|
| 181 |
-
if (keyEl) keyEl.value = maskApiKey(fresh.llm.apiKeys[p] ||
|
| 182 |
});
|
|
|
|
| 183 |
document.getElementById("transProvider").addEventListener("change", updateTransModels);
|
|
|
|
| 184 |
updateLlmModels();
|
| 185 |
updateTransModels();
|
| 186 |
|
| 187 |
// Save on submit
|
| 188 |
document.getElementById("iaConfigForm").addEventListener("submit", e => {
|
| 189 |
e.preventDefault();
|
|
|
|
| 190 |
const prev = config;
|
| 191 |
const newConfig = { ...prev };
|
|
|
|
|
|
|
| 192 |
const llProv = document.getElementById("llmProvider").value;
|
| 193 |
const rawKey = document.getElementById("llmApiKey").value;
|
| 194 |
-
const oldKey = prev.llm.apiKeys[llProv] ||
|
| 195 |
const newKey = rawKey === maskApiKey(oldKey) ? oldKey : rawKey;
|
|
|
|
| 196 |
newConfig.llm = { ...prev.llm, provider: llProv, model: document.getElementById("llmModel").value };
|
| 197 |
newConfig.llm.apiKeys = { ...prev.llm.apiKeys, [llProv]: newKey };
|
|
|
|
|
|
|
| 198 |
const tp = document.getElementById("transProvider").value;
|
| 199 |
const rawKeyTrans = document.getElementById("transApiKey").value;
|
| 200 |
-
const existingKeyTrans = prev.transcription.apiKeys[tp] ||
|
| 201 |
const actualKeyTrans = rawKeyTrans === maskApiKey(existingKeyTrans) ? existingKeyTrans : rawKeyTrans;
|
|
|
|
| 202 |
newConfig.transcription.provider = tp;
|
| 203 |
newConfig.transcription.apiKeys = { ...prev.transcription.apiKeys, [tp]: actualKeyTrans };
|
| 204 |
newConfig.transcription.models = { ...prev.transcription.models, [tp]: document.getElementById("transModel").value };
|
| 205 |
-
|
|
|
|
| 206 |
saveConfig(newConfig);
|
|
|
|
| 207 |
config = newConfig;
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
document.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
document.getElementById("llmApiKey").type = "password";
|
| 212 |
document.getElementById("transApiKey").type = "password";
|
| 213 |
-
|
|
|
|
|
|
|
| 214 |
if (!msg) {
|
| 215 |
-
msg = document.createElement(
|
| 216 |
-
msg.id =
|
| 217 |
-
msg.className =
|
| 218 |
msg.innerHTML = '<i class="fas fa-check-circle mr-2"></i>¡Configuración guardada!';
|
| 219 |
document.body.appendChild(msg);
|
| 220 |
} else {
|
| 221 |
-
msg.style.display =
|
| 222 |
}
|
| 223 |
-
setTimeout(() => { msg.style.display =
|
|
|
|
|
|
|
| 224 |
const modal = document.getElementById("configModal");
|
| 225 |
if (modal) modal.classList.remove("active");
|
| 226 |
});
|
|
|
|
| 18 |
name: "OpenAI",
|
| 19 |
value: "openai",
|
| 20 |
models: [
|
| 21 |
+
// GPT-5 (IDs reales de la API)
|
| 22 |
+
"gpt-5",
|
| 23 |
+
"gpt-5-mini",
|
| 24 |
+
"gpt-5-nano",
|
| 25 |
+
"gpt-5-chat-latest", // versión no-razonadora usada en ChatGPT
|
| 26 |
+
// Otros modelos aún comunes/compatibles en muchas cuentas
|
| 27 |
"gpt-4o-mini-2024-07-18",
|
| 28 |
"chatgpt-4o-latest",
|
| 29 |
"o1-mini-2024-09-12",
|
| 30 |
"o4-mini-2025-04-16"
|
| 31 |
+
],
|
| 32 |
+
url: "https://api.openai.com"
|
| 33 |
},
|
| 34 |
{
|
| 35 |
name: "DeepSeek",
|
|
|
|
| 38 |
url: "https://api.deepseek.com"
|
| 39 |
}
|
| 40 |
];
|
| 41 |
+
|
| 42 |
export const transcriptionProviders = [
|
| 43 |
{ name: "OpenAI Whisper", value: "openai", models: ["whisper-1"], url: "https://api.openai.com" },
|
| 44 |
{ name: "Deepgram", value: "deepgram", models: ["nova-2", "whisper-large"], url: "https://api.deepgram.com" }
|
|
|
|
| 47 |
function saveConfig(config) {
|
| 48 |
localStorage.setItem("iaConfig", JSON.stringify(config));
|
| 49 |
}
|
| 50 |
+
|
| 51 |
function loadConfig() {
|
| 52 |
+
const config = JSON.parse(localStorage.getItem("iaConfig")) || structuredClone(defaultConfig);
|
| 53 |
+
|
| 54 |
// Migrar configuración antigua de transcription
|
| 55 |
if (config.transcription.apiKey !== undefined) {
|
| 56 |
const oldKey = config.transcription.apiKey;
|
|
|
|
| 61 |
delete config.transcription.model;
|
| 62 |
saveConfig(config);
|
| 63 |
}
|
| 64 |
+
|
| 65 |
// Migrar configuración antigua de LLM apiKey a apiKeys
|
| 66 |
if (config.llm.apiKey !== undefined) {
|
| 67 |
const old = config.llm.apiKey;
|
|
|
|
| 69 |
delete config.llm.apiKey;
|
| 70 |
saveConfig(config);
|
| 71 |
}
|
| 72 |
+
|
| 73 |
// Migrar modelos obsoletos de DeepSeek a 'deepseek-chat'
|
| 74 |
+
if (config.llm.provider === "deepseek" && (config.llm.model === "deepseek-v3" || config.llm.model === "deepseek-llm")) {
|
| 75 |
+
config.llm.model = "deepseek-chat";
|
| 76 |
+
console.log("[iaConfigModule] Migrado modelo DeepSeek a deepseek-chat");
|
| 77 |
saveConfig(config);
|
| 78 |
}
|
| 79 |
+
|
| 80 |
+
// ✅ Migrar IDs inventados de GPT-5 a los oficiales
|
| 81 |
+
if (config.llm.provider === "openai") {
|
| 82 |
+
if (config.llm.model === "gpt-5-2025-05-01") config.llm.model = "gpt-5";
|
| 83 |
+
if (config.llm.model === "gpt-5-mini-2025-05-01") config.llm.model = "gpt-5-mini";
|
| 84 |
+
saveConfig(config);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
return config;
|
| 88 |
}
|
| 89 |
+
|
| 90 |
export function getIaConfig() {
|
| 91 |
return loadConfig();
|
| 92 |
}
|
|
|
|
| 96 |
const container = document.getElementById(containerId);
|
| 97 |
if (!container) {
|
| 98 |
console.error(`[iaConfigModule] No se encontró el contenedor '${containerId}'`);
|
| 99 |
+
document.body.insertAdjacentHTML(
|
| 100 |
+
"beforeend",
|
| 101 |
+
`<div style='color:red'>[Error] No se encontró el contenedor '${containerId}' para la configuración IA.</div>`
|
| 102 |
+
);
|
| 103 |
return;
|
| 104 |
}
|
| 105 |
|
| 106 |
function maskApiKey(key) {
|
| 107 |
+
if (!key) return "";
|
| 108 |
+
if (key.length <= 8) return "*".repeat(key.length);
|
| 109 |
+
return key.substring(0, 3) + "-****" + key.slice(-4);
|
| 110 |
}
|
| 111 |
|
| 112 |
container.innerHTML = `
|
|
|
|
| 162 |
|
| 163 |
// Set initial values
|
| 164 |
document.getElementById("llmProvider").value = config.llm.provider;
|
| 165 |
+
document.getElementById("llmApiKey").value = maskApiKey(config.llm.apiKeys[config.llm.provider] || "");
|
| 166 |
document.getElementById("transProvider").value = config.transcription.provider;
|
| 167 |
+
document.getElementById("transApiKey").value = maskApiKey(config.transcription.apiKeys[config.transcription.provider] || "");
|
| 168 |
|
| 169 |
// API Key toggle (ver/ocultar)
|
| 170 |
document.getElementById("toggleLlmApiKey").addEventListener("click", () => {
|
|
|
|
| 183 |
const models = providerObj.models;
|
| 184 |
const sel = document.getElementById("llmModel");
|
| 185 |
sel.innerHTML = models.map(m => `<option value="${m}">${m}</option>`).join("");
|
| 186 |
+
|
| 187 |
+
// Si el modelo guardado no está en la lista del proveedor, usar el primero y persistir
|
| 188 |
+
if (!models.includes(config.llm.model)) {
|
| 189 |
+
config.llm.model = models[0];
|
| 190 |
+
saveConfig(config);
|
| 191 |
+
}
|
| 192 |
sel.value = config.llm.model;
|
| 193 |
}
|
| 194 |
+
|
| 195 |
function updateTransModels() {
|
| 196 |
const prov = document.getElementById("transProvider").value;
|
| 197 |
const providerObj = transcriptionProviders.find(p => p.value === prov);
|
|
|
|
| 199 |
const sel = document.getElementById("transModel");
|
| 200 |
sel.innerHTML = models.map(m => `<option value="${m}">${m}</option>`).join("");
|
| 201 |
sel.value = config.transcription.models[prov] || models[0];
|
| 202 |
+
// Actualizar API Key input al cambiar proveedor
|
| 203 |
+
document.getElementById("transApiKey").value = maskApiKey(config.transcription.apiKeys[prov] || "");
|
| 204 |
}
|
| 205 |
+
|
| 206 |
document.getElementById("llmProvider").addEventListener("change", () => {
|
| 207 |
const p = document.getElementById("llmProvider").value;
|
| 208 |
updateLlmModels();
|
| 209 |
+
// Refrescar config con todas las llaves y mostrar la del proveedor seleccionado
|
| 210 |
const fresh = loadConfig();
|
| 211 |
const keyEl = document.getElementById("llmApiKey");
|
| 212 |
+
if (keyEl) keyEl.value = maskApiKey(fresh.llm.apiKeys[p] || "");
|
| 213 |
});
|
| 214 |
+
|
| 215 |
document.getElementById("transProvider").addEventListener("change", updateTransModels);
|
| 216 |
+
|
| 217 |
updateLlmModels();
|
| 218 |
updateTransModels();
|
| 219 |
|
| 220 |
// Save on submit
|
| 221 |
document.getElementById("iaConfigForm").addEventListener("submit", e => {
|
| 222 |
e.preventDefault();
|
| 223 |
+
// Persistir configuración por proveedor
|
| 224 |
const prev = config;
|
| 225 |
const newConfig = { ...prev };
|
| 226 |
+
|
| 227 |
+
// LLM: provider, apiKeys y model
|
| 228 |
const llProv = document.getElementById("llmProvider").value;
|
| 229 |
const rawKey = document.getElementById("llmApiKey").value;
|
| 230 |
+
const oldKey = prev.llm.apiKeys[llProv] || "";
|
| 231 |
const newKey = rawKey === maskApiKey(oldKey) ? oldKey : rawKey;
|
| 232 |
+
|
| 233 |
newConfig.llm = { ...prev.llm, provider: llProv, model: document.getElementById("llmModel").value };
|
| 234 |
newConfig.llm.apiKeys = { ...prev.llm.apiKeys, [llProv]: newKey };
|
| 235 |
+
|
| 236 |
+
// Transcription: provider, apiKeys y models por proveedor
|
| 237 |
const tp = document.getElementById("transProvider").value;
|
| 238 |
const rawKeyTrans = document.getElementById("transApiKey").value;
|
| 239 |
+
const existingKeyTrans = prev.transcription.apiKeys[tp] || "";
|
| 240 |
const actualKeyTrans = rawKeyTrans === maskApiKey(existingKeyTrans) ? existingKeyTrans : rawKeyTrans;
|
| 241 |
+
|
| 242 |
newConfig.transcription.provider = tp;
|
| 243 |
newConfig.transcription.apiKeys = { ...prev.transcription.apiKeys, [tp]: actualKeyTrans };
|
| 244 |
newConfig.transcription.models = { ...prev.transcription.models, [tp]: document.getElementById("transModel").value };
|
| 245 |
+
|
| 246 |
+
console.log("[iaConfigModule] Configuración guardada:", newConfig);
|
| 247 |
saveConfig(newConfig);
|
| 248 |
+
// Actualizar config local después de guardar
|
| 249 |
config = newConfig;
|
| 250 |
+
|
| 251 |
+
// Notificar cambio
|
| 252 |
+
document.dispatchEvent(new CustomEvent("iaConfigChanged"));
|
| 253 |
+
|
| 254 |
+
// Ofuscar de nuevo las API keys en UI
|
| 255 |
+
document.getElementById("llmApiKey").value = maskApiKey(newConfig.llm.apiKeys[newConfig.llm.provider] || "");
|
| 256 |
+
document.getElementById("transApiKey").value = maskApiKey(newConfig.transcription.apiKeys[tp] || "");
|
| 257 |
document.getElementById("llmApiKey").type = "password";
|
| 258 |
document.getElementById("transApiKey").type = "password";
|
| 259 |
+
|
| 260 |
+
// Mensaje de éxito discreto
|
| 261 |
+
let msg = document.getElementById("iaConfigSavedMsg");
|
| 262 |
if (!msg) {
|
| 263 |
+
msg = document.createElement("div");
|
| 264 |
+
msg.id = "iaConfigSavedMsg";
|
| 265 |
+
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";
|
| 266 |
msg.innerHTML = '<i class="fas fa-check-circle mr-2"></i>¡Configuración guardada!';
|
| 267 |
document.body.appendChild(msg);
|
| 268 |
} else {
|
| 269 |
+
msg.style.display = "block";
|
| 270 |
}
|
| 271 |
+
setTimeout(() => { msg.style.display = "none"; }, 2000);
|
| 272 |
+
|
| 273 |
+
// Cierra el modal
|
| 274 |
const modal = document.getElementById("configModal");
|
| 275 |
if (modal) modal.classList.remove("active");
|
| 276 |
});
|