utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | e7ee0f72085fddde798722a5d13602a231a200fcd4be49f429019cf7f4470890 |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-10 16:27 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-11 14:15 +02:00 |
| Parents | 227590fdf25a |
5 files changed
added tests/settings-ux.mjs +99 −0
| @@ -0,0 +1,99 @@ | ||
| 1 | +// Ajustes: lo que ofrecen tiene que ser lo correcto, y usarse sin ratón. | |
| 2 | +// | |
| 3 | +// 1. Bridge para un Mac ARM: antes se ofrecía la versión Intel (todos los Mac | |
| 4 | +// dicen «MacIntel» en navigator.platform). Si no se puede saber la | |
| 5 | +// arquitectura, se ofrecen las dos versiones de Mac. | |
| 6 | +// 2. Token y carpeta del bridge con su etiqueta asociada; «Olvidar token» y | |
| 7 | +// «Desconectar» existen (antes no había forma). | |
| 8 | +// 3. El permiso dice lo que controla (ficheros), no «y comandos de terminal». | |
| 9 | +// 4. Los interruptores de proveedores externos tienen nombre accesible. | |
| 10 | +// 5. El punto del modelo dice con palabras qué modelo y en qué estado, y es | |
| 11 | +// un botón que lleva a Ajustes. | |
| 12 | +// 6. Al elegir un modelo, su tarjeta dice «cargando…» y, al terminar, queda | |
| 13 | +// resaltada (antes el resaltado se quedaba en el anterior). | |
| 14 | +// El modelo es de mentira: page.route sirve un providers/onnx.js propio. | |
| 15 | +// | |
| 16 | +// BASE=http://127.0.0.1:8898 node tests/settings-ux.mjs | |
| 17 | +import { chromium } from 'playwright'; | |
| 18 | +const BASE = process.env.BASE || 'http://localhost:8799'; | |
| 19 | +let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; }; | |
| 20 | + | |
| 21 | +const MAC_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36'; | |
| 22 | +const FALSO = `export const name = 'onnx falso'; export function configure() {} | |
| 23 | +export async function load(onProgress = () => {}) { onProgress('cargando falso'); await new Promise(r => setTimeout(r, 900)); } | |
| 24 | +export async function chat() { return 'hola'; }`; | |
| 25 | + | |
| 26 | +const b = await chromium.launch(); | |
| 27 | +const errs = []; | |
| 28 | +const abre = async (arch) => { | |
| 29 | + const ctx = await b.newContext({ locale: 'es-ES', userAgent: MAC_UA }); | |
| 30 | + await ctx.addInitScript((arch) => { | |
| 31 | + try { localStorage.setItem('elffusscode.model', 'rules'); localStorage.setItem('elffusscode.bridgeToken', 'tok-de-prueba'); } catch {} | |
| 32 | + const datos = arch === null ? undefined : { getHighEntropyValues: async () => ({ architecture: arch }) }; | |
| 33 | + Object.defineProperty(Navigator.prototype, 'userAgentData', { get: () => datos, configurable: true }); | |
| 34 | + }, arch); | |
| 35 | + const p = await ctx.newPage({ viewport: { width: 1400, height: 900 } }); | |
| 36 | + p.on('pageerror', e => errs.push(e.message.slice(0, 160))); | |
| 37 | + await p.route('**/js/providers/onnx.js*', r => r.fulfill({ status: 200, contentType: 'text/javascript', body: FALSO })); | |
| 38 | + await p.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' }); | |
| 39 | + await p.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 15000 }); | |
| 40 | + return { ctx, p }; | |
| 41 | +}; | |
| 42 | +const descargas = (p) => p.evaluate(() => [...document.querySelectorAll('#br-dl a')].map(a => a.dataset.file)); | |
| 43 | + | |
| 44 | +// 1 · Mac ARM | |
| 45 | +let { ctx, p } = await abre('arm'); | |
| 46 | +await p.click('#btn-settings'); | |
| 47 | +await p.waitForTimeout(500); | |
| 48 | +ok('1 · en un Mac ARM se ofrece la versión Apple Silicon', JSON.stringify(await descargas(p)) === '["elffuss-bridge-mac-arm64"]', JSON.stringify(await descargas(p))); | |
| 49 | + | |
| 50 | +// 2 · etiquetas, Olvidar token | |
| 51 | +const etiquetas = await p.evaluate(() => ['br-token', 'br-folder'].map(id => document.getElementById(id).labels?.length || 0)); | |
| 52 | +ok('2 · token y carpeta tienen su etiqueta asociada', etiquetas.every(n => n === 1), JSON.stringify(etiquetas)); | |
| 53 | +ok('2 · con un token guardado se ofrece «Olvidar token»', await p.locator('#br-forget').isVisible()); | |
| 54 | +await p.click('#br-forget'); | |
| 55 | +await p.waitForTimeout(150); | |
| 56 | +const olvido = await p.evaluate(() => ({ ls: localStorage.getItem('elffusscode.bridgeToken'), input: document.getElementById('br-token').value, msg: document.querySelector('.bridge-card .br-msg')?.textContent || '' })); | |
| 57 | +ok('2 · «Olvidar token» lo borra del navegador y lo dice', olvido.ls === null && olvido.input === '' && /olvidado/.test(olvido.msg), JSON.stringify(olvido)); | |
| 58 | +const disc = await p.evaluate(() => !!document.getElementById('br-disconnect')); | |
| 59 | +ok('2 · existe «Desconectar» (visible cuando el bridge está conectado)', disc); | |
| 60 | + | |
| 61 | +// 3 · permiso | |
| 62 | +const permiso = await p.evaluate(() => document.querySelector('#perm-autoedit').closest('label').textContent); | |
| 63 | +ok('3 · el permiso dice que controla escribir y editar ficheros', /Escribir y editar ficheros/.test(permiso) && !/comandos de terminal/.test(permiso), permiso); | |
| 64 | + | |
| 65 | +// 4 · proveedores | |
| 66 | +const nombres = await p.evaluate(() => [...document.querySelectorAll('#settings-panel .prov-head input[type=checkbox]')].map(c => c.getAttribute('aria-label'))); | |
| 67 | +ok('4 · cada interruptor de proveedor tiene nombre accesible', nombres.length >= 3 && nombres.every(n => /^Activar /.test(n || '')), JSON.stringify(nombres)); | |
| 68 | + | |
| 69 | +// 6 · tarjeta de modelo: cargando… y resaltada al terminar | |
| 70 | +const tarjetaQwen = p.locator('#settings-panel .model-card', { hasText: 'Qwen3.5-0.8B' }).first(); | |
| 71 | +await tarjetaQwen.click(); | |
| 72 | +await p.waitForTimeout(150); | |
| 73 | +const durante = await p.evaluate(() => { const c = [...document.querySelectorAll('#settings-panel .model-card')].find(x => /Qwen3.5-0.8B/.test(x.textContent)); return { busy: c?.getAttribute('aria-busy'), txt: c?.textContent }; }); | |
| 74 | +ok('6 · al elegir un modelo, su tarjeta dice «cargando…» (aria-busy)', durante.busy === 'true' && /cargando/.test(durante.txt), JSON.stringify(durante)); | |
| 75 | +await p.waitForTimeout(1500); | |
| 76 | +const tras = await p.evaluate(() => { const c = [...document.querySelectorAll('#settings-panel .model-card')].find(x => /Qwen3.5-0.8B/.test(x.textContent)); return { activa: c?.classList.contains('active'), pressed: c?.getAttribute('aria-pressed') }; }); | |
| 77 | +ok('6 · al terminar, la tarjeta del modelo cargado queda resaltada', tras.activa && tras.pressed === 'true', JSON.stringify(tras)); | |
| 78 | + | |
| 79 | +// 5 · el punto del modelo | |
| 80 | +await p.click('#btn-settings'); // cierra | |
| 81 | +const punto = await p.evaluate(() => { const d = document.getElementById('model-dot'); return { tag: d.tagName, aria: d.getAttribute('aria-label') }; }); | |
| 82 | +ok('5 · el punto del modelo es un botón que dice qué modelo y su estado', punto.tag === 'BUTTON' && /Qwen3.5-0.8B/.test(punto.aria) && /listo/.test(punto.aria), JSON.stringify(punto)); | |
| 83 | +await p.click('#model-dot'); | |
| 84 | +await p.waitForTimeout(300); | |
| 85 | +ok('5 · …y lleva a Ajustes', await p.evaluate(() => !document.getElementById('settings-panel').hidden && !!document.querySelector('#settings-panel .model-grid'))); | |
| 86 | +await ctx.close(); | |
| 87 | + | |
| 88 | +// 1 · Mac sin datos de arquitectura (Safari): las dos versiones | |
| 89 | +({ ctx, p } = await abre(null)); | |
| 90 | +await p.click('#btn-settings'); | |
| 91 | +await p.waitForTimeout(500); | |
| 92 | +ok('1 · si no se sabe la arquitectura del Mac, se ofrecen las dos versiones', JSON.stringify(await descargas(p)) === '["elffuss-bridge-mac-arm64","elffuss-bridge-mac-intel"]', JSON.stringify(await descargas(p))); | |
| 93 | +await ctx.close(); | |
| 94 | + | |
| 95 | +console.log('\n errores JS:', errs[0] || 'ninguno'); | |
| 96 | +ok('sin errores de página', errs.length === 0, errs.join(' | ')); | |
| 97 | +console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ AJUSTES: LO QUE OFRECEN ES LO CORRECTO'); | |
| 98 | +await b.close(); | |
| 99 | +process.exit(fails ? 1 : 0); |
modified web/css/code.css +5 −0
| @@ -72,6 +72,9 @@ | ||
| 72 | 72 | .controls { display: flex; align-items: center; gap: 8px; font-size: .9rem; } |
| 73 | 73 | select { background: var(--bg3); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; } |
| 74 | 74 | .dot { width: 9px; height: 9px; border-radius: 50%; } |
| 75 | +/* el punto del modelo es un botón (lleva a Ajustes → Cerebro) */ | |
| 76 | +button.dot { border: none; padding: 0; cursor: pointer; flex: 0 0 auto; } | |
| 77 | +button.dot:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; } | |
| 75 | 78 | .dot.off { background: #4a5062; } .dot.on { background: #3fb970; } |
| 76 | 79 | .dot.loading { background: #e5a53a; animation: pulse 1.2s infinite; } |
| 77 | 80 | @keyframes pulse { 50% { opacity: .35; } } |
| @@ -551,6 +554,8 @@ | ||
| 551 | 554 | button.wide { width: 100%; padding: 9px; border-radius: 8px; } |
| 552 | 555 | |
| 553 | 556 | .model-card.disabled { opacity: .5; cursor: not-allowed; } |
| 557 | +.model-card.loading { border-color: #e5a53a; } | |
| 558 | +.model-card:focus-visible { outline: 2px solid var(--accent2); outline-offset: 1px; } | |
| 554 | 559 | .model-card.disabled:hover { border-color: var(--line); } |
| 555 | 560 | |
| 556 | 561 | /* ---------- vistas Arquitectura / Ciudad 3D (overlay sobre el editor) ---------- */ |
modified web/index.html +1 −1
| @@ -70,7 +70,7 @@ | ||
| 70 | 70 | </nav> |
| 71 | 71 | <div class="controls"> |
| 72 | 72 | <button id="git-branch" class="chip" title="rama actual" hidden></button> |
| 73 | - <span id="model-dot" class="dot off" title="modelo"></span> | |
| 73 | + <button id="model-dot" type="button" class="dot off" title="modelo" aria-label="modelo"></button> | |
| 74 | 74 | <select id="model-select" hidden></select> |
| 75 | 75 | <button id="disk-chip" class="chip" hidden></button> |
| 76 | 76 | <button id="speed-chip" class="chip" hidden title="velocidad de esta máquina"></button> |
modified web/js/i18n.js +20 −0
| @@ -183,6 +183,16 @@ | ||
| 183 | 183 | avatarLabel: "Mente de Elffuss", |
| 184 | 184 | setTelSend: "Enviar", setTelSending: "Enviando…", |
| 185 | 185 | mLab: "Elffuss Lab (banco de pruebas)", |
| 186 | + // Ajustes: bridge, permisos, proveedores y modelo | |
| 187 | + setBridgeName: "Bridge local", setBridgeSource: "Código fuente del bridge", | |
| 188 | + setBridgeDisconnect: "Desconectar", setBridgeForget: "Olvidar token", | |
| 189 | + setBridgeDisconnectedMsg: "Desconectado. No se volverá a conectar solo hasta que pulses Conectar.", | |
| 190 | + setBridgeForgotMsg: "Token olvidado: este navegador ya no lo guarda.", | |
| 191 | + setPermLabel: "Escribir y editar ficheros sin pedir confirmación", | |
| 192 | + setPermNote: "Esto controla solo la escritura de ficheros (code.write / code.edit): desmárcalo si prefieres revisar cada cambio antes de aplicarlo. Los comandos del terminal (terminal.run) se ejecutan siempre sin preguntar.", | |
| 193 | + provToggle: "Activar {name}", setModelLoadingCard: "cargando…", | |
| 194 | + modelDot: "Modelo: {name} · {state} — clic para cambiarlo", modelDotBasic: "Modo básico, sin modelo de IA — clic para elegir uno", | |
| 195 | + modelState_off: "sin cargar", modelState_loading: "cargando…", modelState_on: "listo", modelState_error: "no se pudo cargar", | |
| 186 | 196 | clearModelsConfirm: "Vas a borrar {size} de modelos guardados en este navegador.\n\nNo se pierde nada tuyo: solo los pesos descargados. La próxima vez habrá que bajarlos otra vez.\n\n¿Seguir?", |
| 187 | 197 | clearModelsShared: "Ojo: el almacén compartido de Elffuss no se pudo consultar desde aquí; puede quedar algo guardado ahí.", |
| 188 | 198 | clearModelsDone: "💾 Liberados {size}.", clearModelsFailed: "No se pudo vaciar: {what}.", |
| @@ -367,6 +377,16 @@ | ||
| 367 | 377 | avatarLabel: "Elffuss Mind", |
| 368 | 378 | setTelSend: "Send", setTelSending: "Sending…", |
| 369 | 379 | mLab: "Elffuss Lab (test bench)", |
| 380 | + // Settings: bridge, permissions, providers and model | |
| 381 | + setBridgeName: "Local bridge", setBridgeSource: "Bridge source code", | |
| 382 | + setBridgeDisconnect: "Disconnect", setBridgeForget: "Forget token", | |
| 383 | + setBridgeDisconnectedMsg: "Disconnected. It won't reconnect by itself until you press Connect.", | |
| 384 | + setBridgeForgotMsg: "Token forgotten: this browser no longer stores it.", | |
| 385 | + setPermLabel: "Write and edit files without asking", | |
| 386 | + setPermNote: "This only controls writing files (code.write / code.edit): untick it if you prefer to review each change before it is applied. Terminal commands (terminal.run) always run without asking.", | |
| 387 | + provToggle: "Turn on {name}", setModelLoadingCard: "loading…", | |
| 388 | + modelDot: "Model: {name} · {state} — click to change it", modelDotBasic: "Basic mode, no AI model — click to pick one", | |
| 389 | + modelState_off: "not loaded", modelState_loading: "loading…", modelState_on: "ready", modelState_error: "couldn't load", | |
| 370 | 390 | clearModelsConfirm: "You are about to delete {size} of models stored in this browser.\n\nNothing of yours is lost: only the downloaded weights. Next time they will be downloaded again.\n\nContinue?", |
| 371 | 391 | clearModelsShared: "Note: Elffuss's shared store could not be checked from here; something may remain stored there.", |
| 372 | 392 | clearModelsDone: "💾 Freed {size}.", clearModelsFailed: "Couldn't clear: {what}.", |
modified web/js/main.js +112 −32
| @@ -617,18 +617,31 @@ | ||
| 617 | 617 | } |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | +// El punto de estado del modelo dice con palabras qué modelo es y cómo está | |
| 621 | +// (antes era solo un color, con el título «modelo» siempre), y es un botón que | |
| 622 | +// lleva a Ajustes → Cerebro. | |
| 623 | +function pintaDot(estado, id) { | |
| 624 | + const d = $('model-dot'); | |
| 625 | + if (!d) return; | |
| 626 | + d.className = 'dot ' + (estado === 'error' ? 'off' : estado); | |
| 627 | + const nombre = (modelOptions().find(o => o.id === id)?.label || id || '').replace(/\s*★$/, ''); | |
| 628 | + const txt = id === 'rules' ? t('modelDotBasic') : t('modelDot', { name: nombre, state: t('modelState_' + estado) }); | |
| 629 | + d.title = txt; | |
| 630 | + d.setAttribute('aria-label', txt); | |
| 631 | +} | |
| 632 | + | |
| 620 | 633 | let loadingId = null; |
| 621 | 634 | async function changeModel(id) { |
| 622 | 635 | if (id === 'rules') { |
| 623 | 636 | conv.setProvider(rules); |
| 624 | 637 | activeModel = 'rules'; |
| 625 | 638 | guardaPref('elffusscode.model', 'rules'); |
| 626 | - $('model-dot').className = 'dot off'; | |
| 639 | + pintaDot('off', 'rules'); | |
| 627 | 640 | return true; |
| 628 | 641 | } |
| 629 | 642 | if (loadingId === id || activeModel === id) return true; // un solo modelo, una sola carga |
| 630 | 643 | loadingId = id; |
| 631 | - $('model-dot').className = 'dot loading'; | |
| 644 | + pintaDot('loading', id); | |
| 632 | 645 | showModelProgress(t("stModelLoadingAI"), 4); |
| 633 | 646 | try { |
| 634 | 647 | const mod = await resolveProvider(id); |
| @@ -661,7 +674,7 @@ | ||
| 661 | 674 | catch { /* el medidor no vale un fallo de carga */ } |
| 662 | 675 | activeModel = id; |
| 663 | 676 | guardaPref('elffusscode.model', id); |
| 664 | - $('model-dot').className = 'dot on'; | |
| 677 | + pintaDot('on', id); | |
| 665 | 678 | showModelProgress(t('modelReadyBadge'), 100); |
| 666 | 679 | setTimeout(() => showModelProgress(null), 2500); |
| 667 | 680 | $('statusbar').textContent = t('modelReady'); |
| @@ -681,7 +694,7 @@ | ||
| 681 | 694 | } |
| 682 | 695 | conv.setProvider(rules); |
| 683 | 696 | activeModel = 'rules'; |
| 684 | - $('model-dot').className = 'dot off'; | |
| 697 | + pintaDot('error', id); | |
| 685 | 698 | showModelProgress('⚠️ No pude cargar el modelo: ' + (e?.message || e)); |
| 686 | 699 | setTimeout(() => showModelProgress(null), 6000); |
| 687 | 700 | rebuildSelect(); |
| @@ -742,11 +755,49 @@ | ||
| 742 | 755 | |
| 743 | 756 | function showBridgeMsg(card, text, isErr) { |
| 744 | 757 | let el2 = card.querySelector('.br-msg'); |
| 745 | - if (!el2) { el2 = document.createElement('div'); el2.className = 'br-msg muted'; el2.style.cssText = 'font-size:.7rem;margin-top:6px'; card.appendChild(el2); } | |
| 758 | + if (!el2) { el2 = document.createElement('div'); el2.className = 'br-msg muted'; el2.setAttribute('role', 'status'); el2.style.cssText = 'font-size:.7rem;margin-top:6px'; card.appendChild(el2); } | |
| 746 | 759 | el2.textContent = text; |
| 747 | 760 | el2.style.color = isErr ? '#ff6b8b' : ''; |
| 748 | 761 | } |
| 749 | 762 | |
| 763 | +// Qué bridge descargar. Todos los Mac dicen «MacIntel» en navigator.platform, | |
| 764 | +// también los Apple Silicon, y por eso a un Mac ARM se le ofrecía la versión | |
| 765 | +// Intel. Se pregunta la arquitectura a userAgentData (Chrome/Edge) y, si no se | |
| 766 | +// puede saber (Safari), se ofrecen las DOS versiones de Mac en vez de adivinar. | |
| 767 | +async function bridgeParaEstaMaquina() { | |
| 768 | + const ua = navigator.userAgent; | |
| 769 | + let arch = ''; | |
| 770 | + try { arch = (await navigator.userAgentData?.getHighEntropyValues?.(['architecture']))?.architecture || ''; } catch { /* sin datos */ } | |
| 771 | + if (/Mac/.test(ua)) { | |
| 772 | + if (arch === 'arm') return ['elffuss-bridge-mac-arm64']; | |
| 773 | + if (arch === 'x86') return ['elffuss-bridge-mac-intel']; | |
| 774 | + return ['elffuss-bridge-mac-arm64', 'elffuss-bridge-mac-intel']; | |
| 775 | + } | |
| 776 | + if (/Win/.test(ua)) return ['elffuss-bridge-windows.exe']; | |
| 777 | + if (/Linux/.test(ua)) return [arch === 'arm' || /aarch64|arm64/i.test(ua) ? 'elffuss-bridge-linux-arm64' : 'elffuss-bridge-linux']; | |
| 778 | + return ['elffuss-bridge-mac-arm64', 'elffuss-bridge-mac-intel']; | |
| 779 | +} | |
| 780 | +async function pintaDescargasBridge(card, NOMBRES) { | |
| 781 | + const principales = await bridgeParaEstaMaquina(); | |
| 782 | + const host = card.querySelector('#br-dl'), otros = card.querySelector('#br-dl-other'); | |
| 783 | + if (!host || !otros) return; | |
| 784 | + const enlace = (f, principal) => { | |
| 785 | + const a = document.createElement('a'); | |
| 786 | + a.href = 'bridge-dl/' + f; a.setAttribute('download', ''); | |
| 787 | + a.dataset.file = f; | |
| 788 | + if (principal) { a.className = 'prov-use'; a.style.cssText = 'text-decoration:none;display:inline-block;margin:0 6px 6px 0'; a.textContent = t('setBridgeDownload', { os: NOMBRES[f] }); } | |
| 789 | + else { a.style.cssText = 'color:var(--accent2);font-size:.72rem'; a.textContent = NOMBRES[f]; } | |
| 790 | + // El tamaño, para saber qué se baja (una petición HEAD, sin descargar). | |
| 791 | + fetch(a.href, { method: 'HEAD' }).then(r => { | |
| 792 | + const n = +r.headers.get('content-length'); | |
| 793 | + if (r.ok && n) a.textContent += ` (${(n / 1048576).toFixed(1)} MB)`; | |
| 794 | + }).catch(() => {}); | |
| 795 | + return a; | |
| 796 | + }; | |
| 797 | + host.replaceChildren(...principales.map(f => enlace(f, true))); | |
| 798 | + otros.replaceChildren(...Object.keys(NOMBRES).filter(f => !principales.includes(f)).map(f => { const d = document.createElement('div'); d.appendChild(enlace(f, false)); return d; })); | |
| 799 | +} | |
| 800 | + | |
| 750 | 801 | // pequeño estallido de fuegos artificiales (canvas, un par de segundos) para |
| 751 | 802 | // que se entienda de un vistazo que el bridge quedó conectado. |
| 752 | 803 | function fireworks() { |
| @@ -808,12 +859,25 @@ | ||
| 808 | 859 | }; |
| 809 | 860 | }); |
| 810 | 861 | const grid = el('div', 'model-grid'); |
| 862 | + grid.setAttribute('role', 'group'); | |
| 863 | + grid.setAttribute('aria-label', t('setBrainTitle')); | |
| 811 | 864 | for (const m of LOCAL) { |
| 812 | 865 | if (m.need === 'gpu' && !realGPU) continue; |
| 813 | - const card = el('button', 'model-card' + (activeModel === m.id ? ' active' : '') + (m.disabled ? ' disabled' : '')); | |
| 866 | + const cargando = loadingId === m.id; | |
| 867 | + const card = el('button', 'model-card' + (activeModel === m.id ? ' active' : '') + (m.disabled ? ' disabled' : '') + (cargando ? ' loading' : '')); | |
| 814 | 868 | if (m.disabled) card.disabled = true; |
| 815 | - card.innerHTML = `<b>${m.name}</b><span>${m.sub}</span>`; | |
| 816 | - card.onclick = () => { changeModel(m.id); renderSettings(); }; | |
| 869 | + card.setAttribute('aria-pressed', activeModel === m.id ? 'true' : 'false'); | |
| 870 | + if (cargando) card.setAttribute('aria-busy', 'true'); | |
| 871 | + card.innerHTML = `<b>${m.name}</b><span>${cargando ? escapeHtml(t('setModelLoadingCard')) : m.sub}</span>`; | |
| 872 | + // La tarjeta dice «cargando…» mientras carga, y el panel se repinta cuando | |
| 873 | + // termina: antes se repintaba al instante y el resaltado se quedaba en el | |
| 874 | + // modelo anterior hasta reabrir Ajustes. | |
| 875 | + card.onclick = async () => { | |
| 876 | + const p = changeModel(m.id); | |
| 877 | + renderSettings(); | |
| 878 | + await p; | |
| 879 | + if (!$('settings-panel').hidden && $('settings-panel').querySelector('.model-grid')) renderSettings(); | |
| 880 | + }; | |
| 817 | 881 | grid.appendChild(card); |
| 818 | 882 | } |
| 819 | 883 | box.appendChild(grid); |
| @@ -904,40 +968,36 @@ | ||
| 904 | 968 | // --- Bridge local (ejecución REAL en tu máquina: node, npm, python…) --- |
| 905 | 969 | box.append(el('div', 'sk-h', t("setBridgeTitle"))); |
| 906 | 970 | const brCard = el('div', 'prov-card bridge-card'); |
| 907 | - const guessOS = () => { | |
| 908 | - const ua = navigator.userAgent; | |
| 909 | - if (/Mac/.test(ua)) return /Intel/.test(navigator.platform) && !/arm/i.test(ua) ? 'elffuss-bridge-mac-intel' : 'elffuss-bridge-mac-arm64'; | |
| 910 | - if (/Win/.test(ua)) return 'elffuss-bridge-windows.exe'; | |
| 911 | - if (/Linux/.test(ua)) return /aarch64|arm64/i.test(ua) ? 'elffuss-bridge-linux-arm64' : 'elffuss-bridge-linux'; | |
| 912 | - return 'elffuss-bridge-mac-arm64'; | |
| 913 | - }; | |
| 914 | 971 | const OTHER = { 'elffuss-bridge-mac-arm64': 'Mac (Apple Silicon)', 'elffuss-bridge-mac-intel': 'Mac (Intel)', 'elffuss-bridge-windows.exe': 'Windows', 'elffuss-bridge-linux': 'Linux (x64)', 'elffuss-bridge-linux-arm64': 'Linux (ARM)' }; |
| 915 | - const primary = guessOS(); | |
| 972 | + // Etiquetas ASOCIADAS a sus campos (for/id) y mensajes en una región viva. | |
| 916 | 973 | brCard.innerHTML = |
| 917 | - `<div class="prov-head"><span id="br-dot" class="dot off"></span><b>Bridge local</b><span id="br-status" class="muted" style="margin-left:auto;font-size:.72rem">desconectado</span></div>` + | |
| 974 | + `<div class="prov-head"><span id="br-dot" class="dot off" aria-hidden="true"></span><b>${escapeHtml(t('setBridgeName'))}</b><span id="br-status" class="muted" role="status" style="margin-left:auto;font-size:.72rem">${escapeHtml(t('setBridgeDisconnected'))}</span></div>` + | |
| 918 | 975 | `<p class="muted" style="font-size:.72rem;margin:6px 0">${t('setBridgeDesc')}</p>` + |
| 919 | 976 | `<p class="muted" style="font-size:.7rem;margin:0 0 6px">${t('setBridgeOld')}</p>` + |
| 920 | - `<a class="prov-use" style="text-decoration:none;display:inline-block" href="bridge-dl/${primary}" download>${t('setBridgeDownload',{os:OTHER[primary]})}</a>` + | |
| 921 | - `<details style="margin-top:6px"><summary class="muted" style="font-size:.7rem;cursor:pointer">${t('setBridgeOtherOS')}</summary>` + | |
| 922 | - Object.entries(OTHER).filter(([f]) => f !== primary).map(([f, label]) => `<div><a href="bridge-dl/${f}" download style="color:var(--accent2);font-size:.72rem">${label}</a></div>`).join('') + | |
| 923 | - `</details>` + | |
| 924 | - `<div class="field" style="margin-top:8px"><label class="muted" style="font-size:.68rem">${t('setBrToken')}</label><input id="br-token" placeholder="${t('brTokenPh')}"></div>` + | |
| 925 | - `<div class="field" style="margin-top:6px"><label class="muted" style="font-size:.68rem">${t('setBridgeFolderLabel')}</label><input id="br-folder" placeholder="${t('setBridgeFolderPh')}"></div>` + | |
| 926 | - `<button id="br-connect" class="prov-use" style="margin-top:8px">${t('setBridgeConnect')}</button>`; | |
| 977 | + `<div id="br-dl"></div>` + | |
| 978 | + `<details style="margin-top:6px"><summary class="muted" style="font-size:.7rem;cursor:pointer">${t('setBridgeOtherOS')}</summary><div id="br-dl-other"></div></details>` + | |
| 979 | + `<p class="muted" style="font-size:.7rem;margin:6px 0 0"><a href="https://github.com/KikoCis/elffuss-code/tree/main/bridge" target="_blank" rel="noopener noreferrer" style="color:var(--accent2)">${escapeHtml(t('setBridgeSource'))} ↗</a></p>` + | |
| 980 | + `<div class="field" style="margin-top:8px"><label for="br-token" class="muted" style="font-size:.68rem">${t('setBrToken')}</label><input id="br-token" type="password" autocomplete="off" placeholder="${t('brTokenPh')}"></div>` + | |
| 981 | + `<div class="field" style="margin-top:6px"><label for="br-folder" class="muted" style="font-size:.68rem">${t('setBridgeFolderLabel')}</label><input id="br-folder" placeholder="${t('setBridgeFolderPh')}"></div>` + | |
| 982 | + `<div style="display:flex;gap:8px;flex-wrap:wrap;margin-top:8px"><button id="br-connect" class="prov-use">${t('setBridgeConnect')}</button>` + | |
| 983 | + `<button id="br-disconnect" class="prov-use" hidden>${escapeHtml(t('setBridgeDisconnect'))}</button>` + | |
| 984 | + `<button id="br-forget" class="prov-use" hidden>${escapeHtml(t('setBridgeForget'))}</button></div>`; | |
| 927 | 985 | box.appendChild(brCard); |
| 986 | + pintaDescargasBridge(brCard, OTHER); | |
| 928 | 987 | brCard.querySelector('#br-folder').value = bridge.getFolder(); |
| 929 | 988 | brCard.querySelector('#br-token').value = localStorage.getItem('elffusscode.bridgeToken') || ''; |
| 930 | 989 | const paintBridge = () => { |
| 931 | - // el panel puede haberse cerrado entre sondeos de fondo — si ya no está | |
| 932 | - // en el DOM, nos desuscribimos en vez de tocar nodos huérfanos. | |
| 933 | - if (!document.body.contains(brCard)) { bridge.onStatusChange(() => {}); return; } | |
| 934 | 990 | const on = bridge.isConnected(); |
| 935 | 991 | brCard.querySelector('#br-dot').className = 'dot ' + (on ? 'on' : 'off'); |
| 936 | 992 | brCard.querySelector('#br-status').textContent = on ? t("setBridgeOnStatus") : t("setBridgeDisconnected"); |
| 937 | 993 | if (on) brCard.querySelector('#br-token').value = localStorage.getItem('elffusscode.bridgeToken') || ''; |
| 994 | + brCard.querySelector('#br-disconnect').hidden = !on; | |
| 995 | + brCard.querySelector('#br-forget').hidden = !bridge.hasSavedToken(); | |
| 938 | 996 | }; |
| 939 | 997 | paintBridge(); |
| 940 | - bridge.onStatusChange(paintBridge); // repinta solo si el bridge conecta/cae mientras Ajustes está abierto | |
| 998 | + // repinta si el bridge conecta/cae mientras Ajustes está abierto; al cerrarse | |
| 999 | + // el panel se deja de escuchar | |
| 1000 | + const dejar = bridge.onStatusChange(() => { if (!document.body.contains(brCard)) return dejar(); paintBridge(); }); | |
| 941 | 1001 | brCard.querySelector('#br-connect').onclick = async () => { |
| 942 | 1002 | const btn = brCard.querySelector('#br-connect'); |
| 943 | 1003 | bridge.setFolder(brCard.querySelector('#br-folder').value); |
| @@ -948,16 +1008,27 @@ | ||
| 948 | 1008 | catch (e) { showBridgeMsg(brCard, '⚠️ ' + e.message, true); } |
| 949 | 1009 | finally { btn.disabled = false; btn.textContent = t("setBridgeConnect"); } |
| 950 | 1010 | }; |
| 1011 | + // Antes no había forma de desconectar (la función existía y nadie la usaba) | |
| 1012 | + // ni de que el navegador olvidara el token guardado. | |
| 1013 | + brCard.querySelector('#br-disconnect').onclick = () => { bridge.disconnect(); paintBridge(); showBridgeMsg(brCard, t('setBridgeDisconnectedMsg')); }; | |
| 1014 | + brCard.querySelector('#br-forget').onclick = () => { | |
| 1015 | + bridge.forgetToken(); | |
| 1016 | + brCard.querySelector('#br-token').value = ''; | |
| 1017 | + paintBridge(); | |
| 1018 | + showBridgeMsg(brCard, t('setBridgeForgotMsg')); | |
| 1019 | + }; | |
| 951 | 1020 | |
| 952 | 1021 | // --- Permisos de ejecución (mismo interruptor que </> Auto de la barra) --- |
| 953 | 1022 | box.append(el('div', 'sk-h', t("setPermTitle"))); |
| 954 | 1023 | const permCard = el('div', 'prov-card'); |
| 955 | 1024 | permCard.innerHTML = |
| 1025 | + // Lo que de verdad controla: escribir/editar ficheros. Decía «y comandos de | |
| 1026 | + // terminal», y la nota de debajo contaba que terminal.run no pregunta nunca. | |
| 956 | 1027 | `<label style="display:flex;align-items:center;gap:8px;cursor:pointer">` + |
| 957 | 1028 | `<input type="checkbox" id="perm-autoedit"> ` + |
| 958 | - `<span>Ejecutar todo automáticamente (escribir/editar ficheros y comandos de terminal), sin pedir confirmación</span>` + | |
| 1029 | + `<span>${escapeHtml(t('setPermLabel'))}</span>` + | |
| 959 | 1030 | `</label>` + |
| 960 | - `<p class="muted" style="font-size:.7rem;margin:6px 0 0">terminal.run ya se ejecuta siempre sin preguntar. Esto controla solo la escritura de ficheros (code.write/code.edit) — desmárcalo si prefieres revisar cada cambio antes de aplicarlo.</p>`; | |
| 1031 | + `<p class="muted" style="font-size:.7rem;margin:6px 0 0">${escapeHtml(t('setPermNote'))}</p>`; | |
| 961 | 1032 | box.appendChild(permCard); |
| 962 | 1033 | const permCheckbox = permCard.querySelector('#perm-autoedit'); |
| 963 | 1034 | permCheckbox.checked = autoEdit; |
| @@ -1034,6 +1105,7 @@ | ||
| 1034 | 1105 | const card = el('div', 'prov-card' + (c.enabled ? ' on' : '')); |
| 1035 | 1106 | const head = el('div', 'prov-head'); |
| 1036 | 1107 | const toggle = document.createElement('input'); toggle.type = 'checkbox'; toggle.checked = c.enabled; |
| 1108 | + toggle.setAttribute('aria-label', t('provToggle', { name: c.label })); | |
| 1037 | 1109 | const title = el('b', null, c.label); |
| 1038 | 1110 | const use = el('button', 'prov-use', t("setProvUse")); |
| 1039 | 1111 | use.hidden = !c.enabled || activeModel === 'ext:' + id; |
| @@ -1341,6 +1413,8 @@ | ||
| 1341 | 1413 | anuncioPendiente = setTimeout(() => { r.textContent = texto; }, 50); |
| 1342 | 1414 | } |
| 1343 | 1415 | $('model-select').addEventListener('change', e => changeModel(e.target.value)); |
| 1416 | +$('model-dot').addEventListener('click', () => { $('settings-panel').hidden = false; renderSettings(); $('settings-panel').querySelector('.model-card')?.focus(); }); | |
| 1417 | +pintaDot('off', 'rules'); | |
| 1344 | 1418 | // móvil: conmutar chat ↔ editor |
| 1345 | 1419 | $('code-flip').addEventListener('click', () => { |
| 1346 | 1420 | const showEditor = !document.body.classList.contains('show-editor'); |
| @@ -1538,12 +1612,18 @@ | ||
| 1538 | 1612 | $('terminal-panel').hidden = !show; |
| 1539 | 1613 | $('act-term').classList.toggle('on', show); |
| 1540 | 1614 | if (show) { |
| 1541 | - const cap = shell.capabilities(); | |
| 1542 | - $('term-caps').textContent = cap.bridge ? t("termCapsBridge") : t("termCapsNoBridge"); | |
| 1615 | + pintaCapacidades(); | |
| 1543 | 1616 | await terminal.mount($('terminal-host')); |
| 1544 | 1617 | terminal.refit(); |
| 1545 | 1618 | } |
| 1546 | 1619 | } |
| 1620 | +// La etiqueta del terminal sigue al bridge: antes solo se pintaba al abrir el | |
| 1621 | +// panel y se quedaba vieja si el bridge conectaba o caía con él abierto. | |
| 1622 | +function pintaCapacidades() { | |
| 1623 | + const cap = shell.capabilities(); | |
| 1624 | + $('term-caps').textContent = cap.bridge ? t("termCapsBridge") : t("termCapsNoBridge"); | |
| 1625 | +} | |
| 1626 | +bridge.onStatusChange(() => { if (!$('terminal-panel').hidden) pintaCapacidades(); }); | |
| 1547 | 1627 | $('act-term').addEventListener('click', () => toggleTerminal()); |
| 1548 | 1628 | $('term-close').addEventListener('click', () => toggleTerminal(false)); |
| 1549 | 1629 | $('term-clear').addEventListener('click', () => terminal.clearScreen()); |