utopia-ia/elffuss-translator public
Changesets · Branches · Tags · Compare
| Changeset | d086819343903ac6569a7eea338dafc6289fddeff30c5ea92e461283c844b5d9 |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-08-14 16:52 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-08-14 16:52 +02:00 |
| Parents | 97412e6712c4 |
2 files changed
modified README.md +81 −45
| @@ -2,95 +2,131 @@ | ||
| 2 | 2 | |
| 3 | 3 | # Elffuss Translator |
| 4 | 4 | |
| 5 | -**Traducción de conversaciones en tiempo real, 100 % en tu navegador.** | |
| 5 | +**Real-time conversation translation, 100% in your browser.** | |
| 6 | 6 | |
| 7 | -Escucha, distingue quién habla, traduce y responde por voz. | |
| 8 | -Sin servidor, sin cuenta, sin API de pago — nada de lo que digas sale de tu máquina. | |
| 7 | +It listens, tells speakers apart, translates and speaks back. | |
| 8 | +No server, no account, no paid API — nothing you say ever leaves your machine. | |
| 9 | 9 | |
| 10 | -[**▶ Abrir la app**](https://translator.elffuss.utopiaia.com) · [Elffuss](https://elffuss.utopiaia.com) · Apache-2.0 | |
| 10 | +[**▶ Open the app**](https://translator.elffuss.utopiaia.com) · [Elffuss](https://elffuss.utopiaia.com) · Apache-2.0 | |
| 11 | 11 | |
| 12 | 12 | </div> |
| 13 | 13 | |
| 14 | 14 | --- |
| 15 | 15 | |
| 16 | -## El copiloto en vivo | |
| 16 | +## Live skills: a meeting facilitator that costs nothing | |
| 17 | 17 | |
| 18 | -El translator no solo traduce: puede **pasarle la conversación a [Elffuss Claw](https://github.com/KikoCis/elffuss-claw)**, que actúa de copiloto y te va soplando qué decir mientras hablas. Un vendedor habla español, el cliente inglés, y en la otra ventana los objetivos de la llamada se van cumpliendo solos. | |
| 18 | +The translator does more than translate. It can hand the conversation to | |
| 19 | +[Elffuss Claw](https://github.com/KikoCis/elffuss-claw), which runs a **live audio skill** | |
| 20 | +and works while you talk. Pick one when you hit **Skills en vivo**: | |
| 19 | 21 | |
| 20 | - | |
| 22 | +| | Skill | What it does | | |
| 23 | +|---|---|---| | |
| 24 | +| 🎯 | **Sales copilot** | Feeds you the exact line to say and tracks the call's objectives. | | |
| 25 | +| 📇 | **Customer card** | Fills a customer record by itself from what the client says. Exports to Excel. | | |
| 26 | +| 🧑🏫 | **Meeting facilitator** | Topics, decisions and action items, live. Exports. | | |
| 27 | +| 📝 | **Summary & ideas** | A running summary plus the ideas that come up. | | |
| 28 | + | |
| 29 | +Each skill paints its own **surface**: a live view that renders *inside the translator*, | |
| 30 | +next to the subtitles — not just a notification. It updates as the conversation goes on | |
| 31 | +and, where it makes sense, exports what it captured as a spreadsheet. | |
| 32 | + | |
| 33 | + | |
| 21 | 34 | |
| 22 | 35 | <div align="center"><sub> |
| 23 | 36 | |
| 24 | -Demo guionizada para enseñar el flujo · [vídeo completo con audio](docs/demo.mp4) | |
| 37 | +**Staged recreation** of the flow (scripted dialogue and timings), not a screen recording of a live run · | |
| 38 | +[full video with audio](docs/demo.mp4) | |
| 25 | 39 | |
| 26 | 40 | </sub></div> |
| 27 | 41 | |
| 28 | -Los dos dominios son distintos, así que la tubería va por `postMessage` con validación de origen: el translator manda cada intervención (`[Hablante N] …`), Claw responde con una línea accionable y el estado de los objetivos, y el consejo vuelve a aparecer sobre los subtítulos. | |
| 42 | +Skills are defined as plain `SKILL.md` files and are **self-editing**: ask in Claw's chat for | |
| 43 | +"add an email field" or "keep the advice shorter" and the skill rewrites itself. | |
| 44 | + | |
| 45 | +## How the surface gets there | |
| 46 | + | |
| 47 | +The two apps live on different origins, so the pipe is `postMessage` with origin checks on | |
| 48 | +both ends. The skill's view is **projected** from Claw into the translator and rendered in a | |
| 49 | +sandboxed iframe (`allow-scripts` only — never `allow-same-origin`, so it can't reach back | |
| 50 | +into the page that hosts it): | |
| 29 | 51 | |
| 30 | -## Qué hace | |
| 52 | +``` | |
| 53 | +translator ──[hablante + texto]──▶ Claw ──▶ model ──▶ CONSEJO / DATOS | |
| 54 | + ▲ │ | |
| 55 | + └───[surface html + state]────────┘ (rendered sandboxed, right-hand panel) | |
| 56 | +``` | |
| 31 | 57 | |
| 32 | -- **Modo conversación**: un solo micrófono, manos libres. Detecta los turnos por energía, separa **quién habla** por su voz y enruta cada turno al idioma del otro. | |
| 33 | -- **Subtítulos** con el original y la traducción debajo, creciendo hacia abajo como en una llamada real. | |
| 34 | -- **Voz**: lee la traducción en alto — o la silencias con un botón y sigue traduciendo y subtitulando igual. | |
| 35 | -- **Medio dúplex**: mientras habla, no se escucha a sí mismo. Sin esto, entra en bucle traduciendo su propia voz. | |
| 36 | -- **Ahorro de batería**: en segundo plano se pausa; al volver, se recupera solo. | |
| 37 | -- **Offline de verdad**: descargas los modelos una vez, quedan cacheados y luego funciona sin red. | |
| 58 | +This is written up as a small spec — see **[Skill Surface Protocol](https://github.com/KikoCis/elffuss-claw)**. | |
| 38 | 59 | |
| 39 | -## El stack, todo ONNX en el navegador | |
| 60 | +## What it does | |
| 40 | 61 | |
| 41 | -| Pieza | Modelo | | |
| 62 | +- **Conversation mode**: one microphone, hands free. It finds the turns by energy, tells | |
| 63 | + **who is speaking** from their voice, and routes each turn into the other language. | |
| 64 | +- **Subtitles** with the original and the translation underneath, growing downward like a real call. | |
| 65 | +- **Voice**: reads the translation out loud — or mute it and keep translating and subtitling. | |
| 66 | +- **Half duplex**: it doesn't listen to itself while speaking. Without this it loops, translating its own voice. | |
| 67 | +- **Battery aware**: pauses in the background and recovers on its own (and never pauses while a live skill is running). | |
| 68 | +- **Actually offline**: download the models once, they stay cached, and it works with no network. | |
| 69 | + | |
| 70 | +## The stack, all ONNX in the browser | |
| 71 | + | |
| 72 | +| Piece | Model | | |
| 42 | 73 | |---|---| |
| 43 | -| **ASR** | `whisper-base` (WebGPU con caída a WASM) | | |
| 44 | -| **Diarización** | `pyannote-segmentation-3.0` (habla/silencio) + `wespeaker-voxceleb-resnet34-LM` (embeddings de hablante) | | |
| 45 | -| **Traducción** | Translator API on-device del navegador, con `opus-mt` (transformers.js) de reserva | | |
| 46 | -| **Voz** | `speechSynthesis` del sistema | | |
| 74 | +| **ASR** | `whisper-base` (WebGPU, falls back to WASM) | | |
| 75 | +| **Diarization** | `pyannote-segmentation-3.0` (speech/silence) + `wespeaker-voxceleb-resnet34-LM` (speaker embeddings) | | |
| 76 | +| **Translation** | The browser's on-device Translator API, with `opus-mt` (transformers.js) as fallback | | |
| 77 | +| **Voice** | The system's `speechSynthesis` | | |
| 47 | 78 | |
| 48 | -Corre sobre [transformers.js](https://github.com/huggingface/transformers.js) y ONNX Runtime Web. Sin framework y sin *build*: HTML y ES modules, se sirve como ficheros estáticos. | |
| 79 | +Runs on [transformers.js](https://github.com/huggingface/transformers.js) and ONNX Runtime Web. | |
| 80 | +No framework and no build step: HTML and ES modules, served as static files. | |
| 49 | 81 | |
| 50 | -## Cómo funciona la diarización | |
| 82 | +## Using the diarizer on its own | |
| 51 | 83 | |
| 52 | -`diarize.mjs` es autónomo y se puede usar suelto: | |
| 84 | +`diarize.mjs` is standalone: | |
| 53 | 85 | |
| 54 | 86 | ```js |
| 55 | -import { loadDiarizer, diarize, makeSpeakerBook } from './diarize.mjs'; | |
| 87 | +import { loadDiarizer, diarize, makeSpeakerBook, speakerVec } from './diarize.mjs'; | |
| 56 | 88 | |
| 57 | 89 | const D = await loadDiarizer(transformers, { device: 'webgpu' }); |
| 58 | 90 | |
| 59 | -// (a) troceado por turnos de un audio ya grabado | |
| 60 | -const turns = await diarize(D, audio16k); // [{ start, end, speaker }] | |
| 91 | +// (a) split a recorded clip into turns | |
| 92 | +const turns = await diarize(D, audio16k); // [{ start, end, speaker }] | |
| 61 | 93 | |
| 62 | -// (b) en vivo: asigna cada fragmento a un hablante estable | |
| 94 | +// (b) live: assign each chunk to a stable speaker | |
| 63 | 95 | const book = makeSpeakerBook({ tau: 0.5, maxSpeakers: 2 }); |
| 64 | -const { label } = book.assign(await speakerVec(D, fragmento16k)); // 'S1' | 'S2' | |
| 96 | +const { label } = book.assign(await speakerVec(D, chunk16k)); // 'S1' | 'S2' | |
| 65 | 97 | ``` |
| 66 | 98 | |
| 67 | -Segmentación → embeddings por sub-ventana → agrupación por coseno. Dos fragmentos del mismo hablante rondan 0.8 de similitud; de hablantes distintos, ~0.15. | |
| 68 | - | |
| 69 | -## Bordes honestos | |
| 99 | +Segmentation → per-window embeddings → cosine clustering. Two chunks from the same speaker | |
| 100 | +land around 0.8 similarity; different speakers, about 0.15. | |
| 70 | 101 | |
| 71 | -- **La primera carga son megas.** Le mandas el modelo al usuario una vez; después vive en caché. | |
| 72 | -- **Separar voces simultáneas en un micro mono no es fiable**: el hablante más fuerte domina el embedding. La diarización **por turnos** sí funciona; para solapamiento real hace falta una captura por interlocutor. | |
| 73 | -- **Whisper alucina con el silencio.** Hay un umbral de energía y un filtro de muletillas típicas ("Subtítulos por…"), pero alguna se cuela. | |
| 74 | -- **Chrome/Edge** para WebGPU. Sin él cae a CPU y va más lento. | |
| 75 | -- La calidad de la voz es la del sistema operativo, que varía bastante entre idiomas. | |
| 102 | +## Honest edges | |
| 76 | 103 | |
| 77 | -## Ficheros | |
| 104 | +- **The first load is a download.** You ship the model to the user once; after that it lives in cache. | |
| 105 | +- **Separating simultaneous voices on a mono mic is not reliable** — the louder speaker dominates the | |
| 106 | + embedding. Turn-by-turn diarization does work; real overlap needs one capture per speaker. | |
| 107 | +- **Whisper hallucinates on silence.** There's an energy gate and a filter for the usual filler | |
| 108 | + ("Subtitles by…"), but some still slips through. | |
| 109 | +- **Chrome/Edge** for WebGPU. Without it, it falls back to CPU and gets slower. | |
| 110 | +- Voice quality is whatever the operating system provides, which varies a lot by language. | |
| 111 | + | |
| 112 | +## Files | |
| 78 | 113 | |
| 79 | 114 | | | | |
| 80 | 115 | |---|---| |
| 81 | -| `index.html` | La app completa: UI, captura, pipeline y tubería con Claw. | | |
| 82 | -| `diarize.mjs` | Motor de diarización (segmentación + embeddings + clustering). | | |
| 116 | +| `index.html` | The whole app: UI, capture, pipeline, live-skill picker and the pipe to Claw. | | |
| 117 | +| `diarize.mjs` | Diarization engine (segmentation + embeddings + clustering). | | |
| 83 | 118 | |
| 84 | -## Servirlo tú mismo | |
| 119 | +## Hosting it yourself | |
| 85 | 120 | |
| 86 | -Son ficheros estáticos; cualquier servidor vale. Un único cuidado: **los `.mjs` deben servirse como JavaScript**, o el navegador bloquea el módulo. En nginx: | |
| 121 | +Static files; any server works. One catch: **`.mjs` must be served as JavaScript**, or the | |
| 122 | +browser refuses the module. In nginx: | |
| 87 | 123 | |
| 88 | 124 | ```nginx |
| 89 | 125 | location ~ \.mjs$ { default_type text/javascript; } |
| 90 | 126 | ``` |
| 91 | 127 | |
| 92 | -Y conviene servirlo por HTTPS: el micrófono y WebGPU lo exigen fuera de `localhost`. | |
| 128 | +Serve it over HTTPS — the microphone and WebGPU require it outside `localhost`. | |
| 93 | 129 | |
| 94 | -## Licencia | |
| 130 | +## License | |
| 95 | 131 | |
| 96 | 132 | Apache-2.0. |
modified index.html +85 −13
| @@ -91,6 +91,28 @@ | ||
| 91 | 91 | .dlsub{font-size:.72rem;color:var(--ok);margin-bottom:10px;text-transform:uppercase;letter-spacing:.08em} |
| 92 | 92 | .dlfile{font-size:.7rem;color:var(--mut);font-family:ui-monospace,monospace;min-height:1.1em;word-break:break-all} |
| 93 | 93 | .dlbytes{font-size:.82rem;color:#c3c9d0;margin-top:2px} |
| 94 | + | |
| 95 | + /* superficie proyectada (pantalla partida real) */ | |
| 96 | + body.withsurface #convo{flex-direction:row} | |
| 97 | + .convmain{display:flex;flex-direction:column;min-width:0;flex:1} | |
| 98 | + #surface{flex:0 0 40%;max-width:520px;border-left:1px solid var(--line);display:none;position:relative} | |
| 99 | + body.withsurface #surface{display:block} | |
| 100 | + #surface iframe{width:100%;height:100%;border:0;display:block;background:var(--bg)} | |
| 101 | + #surfClose{position:absolute;top:8px;right:10px;z-index:3;background:rgba(9,10,17,.7);color:var(--mut);border:1px solid var(--line);border-radius:5px;font-size:.68rem;padding:3px 8px;cursor:pointer} | |
| 102 | + #surfClose:hover{color:var(--fg)} | |
| 103 | + @media(max-width:900px){ body.withsurface #convo{flex-direction:column} #surface{flex:0 0 46%;max-width:none;border-left:0;border-top:1px solid var(--line)} } | |
| 104 | + .skpick{position:fixed;inset:0;background:rgba(6,8,11,.86);display:flex;align-items:center;justify-content:center;padding:20px;z-index:60} | |
| 105 | + .skpick[hidden]{display:none} | |
| 106 | + .skpick .card{background:var(--panel);border:1px solid var(--line);border-radius:16px;max-width:560px;width:100%;padding:28px} | |
| 107 | + .skpick h2{font-family:var(--serif);font-size:1.4rem;margin-bottom:6px} | |
| 108 | + .skpick .lead{color:var(--mut);font-size:.86rem;margin-bottom:20px;line-height:1.5} | |
| 109 | + .skgrid{display:grid;gap:10px} | |
| 110 | + .skitem{display:flex;gap:13px;align-items:flex-start;text-align:left;padding:14px;border:1px solid var(--line);border-radius:11px;background:transparent;color:var(--fg);cursor:pointer;font:inherit;transition:border-color .3s,transform .3s,background .3s} | |
| 111 | + .skitem:hover{border-color:var(--accent);transform:translateY(-2px);background:rgba(200,160,106,.05)} | |
| 112 | + .skitem .ico{font-size:1.3rem;line-height:1} | |
| 113 | + .skitem b{display:block;font-size:.95rem;margin-bottom:3px} | |
| 114 | + .skitem span{color:var(--mut);font-size:.79rem;line-height:1.4} | |
| 115 | + .skpick .cancel{margin-top:16px;width:100%;background:transparent;color:var(--mut);border:1px solid var(--line);border-radius:8px;padding:10px;font:inherit;font-size:.82rem;cursor:pointer} | |
| 94 | 116 | </style> |
| 95 | 117 | </head> |
| 96 | 118 | <body> |
| @@ -120,9 +142,10 @@ | ||
| 120 | 142 | |
| 121 | 143 | <!-- CONVERSACIÓN --> |
| 122 | 144 | <main id="convo" class="screen" hidden> |
| 145 | + <div class="convmain"> | |
| 123 | 146 | <div class="convtop"> |
| 124 | 147 | <span class="pair" id="pairLabel">—</span> |
| 125 | - <button id="copilot" class="toggle paused" title="Abre Claw y te sopla argumentos de venta en vivo">Copiloto</button> | |
| 148 | + <button id="copilot" class="toggle paused" title="Skills que escuchan la conversación y trabajan mientras hablas">Skills en vivo</button> | |
| 126 | 149 | <button id="mute" class="toggle" title="Silenciar la voz: sigue traduciendo y mostrando subtítulos, pero sin hablar">🔊 Voz</button> |
| 127 | 150 | <button id="toggle" class="toggle">Parar</button> |
| 128 | 151 | </div> |
| @@ -130,6 +153,8 @@ | ||
| 130 | 153 | <div class="status" id="status">Escuchando…</div> |
| 131 | 154 | <div class="advice" id="advice" hidden><div class="box"><span class="k">Copiloto</span><span class="t"></span></div></div> |
| 132 | 155 | <div class="subs" id="log"><div class="empty" id="emptyMsg">Habla y aparecerá aquí, con la traducción debajo.</div></div> |
| 156 | + </div> | |
| 157 | + <aside id="surface"><button id="surfClose" title="Cerrar la vista">✕ vista</button><iframe id="surfFrame" sandbox="allow-scripts allow-downloads" title="Vista de la skill"></iframe></aside> | |
| 133 | 158 | </main> |
| 134 | 159 | |
| 135 | 160 | <footer>La versión navegador de la Gemma Translator: local, offline, sin cuenta. · Código abierto en <a href="https://github.com/KikoCis/elffuss-translator" target="_blank" rel="noopener">GitHub</a> · <a href="https://elffuss.utopiaia.com" target="_blank" rel="noopener">elffuss</a></footer> |
| @@ -160,6 +185,14 @@ | ||
| 160 | 185 | </div> |
| 161 | 186 | </div> |
| 162 | 187 | |
| 188 | + | |
| 189 | +<!-- selector de skills de audio en vivo --> | |
| 190 | +<div class="skpick" id="skPick" hidden><div class="card"> | |
| 191 | + <h2>Skills en vivo</h2> | |
| 192 | + <p class="lead">Elffuss escucha la conversación y trabaja mientras hablas. Elige qué quieres que haga — todo en tu navegador, sin cuota.</p> | |
| 193 | + <div class="skgrid" id="skGrid"></div> | |
| 194 | + <button class="cancel" id="skCancel">Ahora no</button> | |
| 195 | +</div></div> | |
| 163 | 196 | <script type="module"> |
| 164 | 197 | import { loadDiarizer, speakerVec, makeSpeakerBook } from './diarize.mjs'; |
| 165 | 198 | const LANGS=[['es','Español'],['en','English'],['fr','Français'],['de','Deutsch'],['it','Italiano'],['pt','Português'],['ca','Català'],['nl','Nederlands'],['ru','Русский'],['uk','Українська']]; |
| @@ -321,7 +354,9 @@ | ||
| 321 | 354 | lastAudioTs=Date.now(); |
| 322 | 355 | clearInterval(convWatch); |
| 323 | 356 | convWatch=setInterval(()=>{ |
| 324 | - if(!convOn||document.hidden) return; | |
| 357 | + if(!convOn) return; | |
| 358 | + const copilotOpen = !!(copilotWin && !copilotWin.closed); | |
| 359 | + if(document.hidden && !copilotOpen) return; // en 2º plano de verdad: no tocar | |
| 325 | 360 | // Quedó marcado como pausado pero la ventana YA se ve (pasa al abrir el |
| 326 | 361 | // copiloto: Chrome oculta la ventana tapada y luego no siempre reanuda): |
| 327 | 362 | // reconstruir en vez de quedarse mudo para siempre. |
| @@ -373,8 +408,10 @@ | ||
| 373 | 408 | addEventListener('message', e=>{ if(e.origin!==CLAW || !e.data) return; |
| 374 | 409 | if(e.data.kind==='copilot-ready'){ copilotReady=true; |
| 375 | 410 | const sc=$('langA').value, sn=(LANGS.find(l=>l[0]===sc)||[])[1]||sc, oc=$('langB').value, on=(LANGS.find(l=>l[0]===oc)||[])[1]||oc; |
| 376 | - try{ copilotWin.postMessage({kind:'copilot-init', sellerLangName:sn, sellerCode:sc, clientLangName:on},CLAW); }catch{} | |
| 411 | + try{ copilotWin.postMessage({kind:'copilot-init', skill:pickedSkill, sellerLangName:sn, sellerCode:sc, clientLangName:on},CLAW); }catch{} | |
| 377 | 412 | copilotBuf.forEach(t=>{ try{copilotWin.postMessage(t,CLAW);}catch{} }); copilotBuf=[]; } |
| 413 | + else if(e.data.kind==='surface' && typeof e.data.html==='string'){ showSurface(e.data.html); } | |
| 414 | + else if(e.data.kind==='surface-state'){ try{ $('surfFrame').contentWindow?.postMessage({type:'surface-state',id:e.data.id,data:e.data.data,advice:e.data.advice},'*'); }catch{} } | |
| 378 | 415 | else if(e.data.kind==='copilot-advice'){ |
| 379 | 416 | // El modelo suele devolver el guion ENTRE COMILLAS ("—"), y así se colaba |
| 380 | 417 | // como si fuera un consejo. Limpiar comillas/espacios y descartar si queda vacío. |
| @@ -383,21 +420,52 @@ | ||
| 383 | 420 | }); |
| 384 | 421 | function copilotSend(speaker,text){ if(!copilotWin||copilotWin.closed) return; const msg={kind:'transcript',speaker,text}; |
| 385 | 422 | if(copilotReady){ try{copilotWin.postMessage(msg,CLAW);}catch{} } else copilotBuf.push(msg); } |
| 386 | -function copilotReset(){ copilotWin=null; copilotReady=false; copilotBuf=[]; $('copilot').classList.remove('on'); $('copilot').textContent='Copiloto'; } | |
| 387 | -$('copilot').onclick=()=>{ | |
| 388 | - if(copilotWin && !copilotWin.closed){ try{copilotWin.close();}catch{} copilotReset(); return; } // toggle: si está abierto, ciérralo | |
| 423 | +function copilotReset(){ copilotWin=null; copilotReady=false; copilotBuf=[]; $('copilot').classList.remove('on'); $('copilot').textContent='Skills en vivo'; } | |
| 424 | +// Catálogo de skills de audio en vivo (el «facilitador», pero local y gratis). | |
| 425 | +const AUDIO_SKILLS=[ | |
| 426 | + {id:'ventas',icon:'🎯',name:'Copiloto de ventas',desc:'Te sopla el argumento exacto y marca los objetivos de la llamada.'}, | |
| 427 | + {id:'ficha',icon:'📇',name:'Ficha de cliente',desc:'Rellena la ficha sola con lo que dice el cliente. Se exporta a Excel.'}, | |
| 428 | + {id:'facilitador',icon:'🧑🏫',name:'Facilitador de reunión',desc:'Temas, decisiones y tareas en vivo. Se exporta.'}, | |
| 429 | + {id:'resumen',icon:'📝',name:'Resumen e ideas',desc:'Resumen progresivo y las ideas que van saliendo.'}, | |
| 430 | +]; | |
| 431 | +let pickedSkill='ventas'; | |
| 432 | +function openSkillPicker(){ | |
| 433 | + const g=$('skGrid'); g.replaceChildren(); | |
| 434 | + for(const sk of AUDIO_SKILLS){ | |
| 435 | + const b=document.createElement('button'); b.className='skitem'; b.type='button'; | |
| 436 | + b.innerHTML='<span class="ico"></span><span class="txt"><b></b><span class="d"></span></span>'; | |
| 437 | + b.querySelector('.ico').textContent=sk.icon; | |
| 438 | + b.querySelector('b').textContent=sk.name; | |
| 439 | + b.querySelector('.d').textContent=sk.desc; | |
| 440 | + b.onclick=()=>{ $('skPick').hidden=true; pickedSkill=sk.id; launchCopilot(sk.id); }; | |
| 441 | + g.appendChild(b); | |
| 442 | + } | |
| 443 | + $('skPick').hidden=false; | |
| 444 | +} | |
| 445 | +$('skCancel').onclick=()=>{ $('skPick').hidden=true; }; | |
| 446 | + | |
| 447 | +function launchCopilot(skill){ | |
| 389 | 448 | copilotReady=false; copilotBuf=[]; |
| 390 | - // Media pantalla derecha: el copiloto queda al lado sin taparte los subtítulos. | |
| 391 | - // (No podemos mover ESTA ventana —el navegador solo deja recolocar las que | |
| 392 | - // abre el propio script—, pero sí colocar la del copiloto donde toca.) | |
| 393 | 449 | const sw=screen.availWidth||1280, sh=screen.availHeight||800, sl=screen.availLeft||0, st=screen.availTop||0; |
| 394 | 450 | const w=Math.max(420,Math.floor(sw/2)), h=sh; |
| 395 | - copilotWin=window.open(CLAW+'/?copilot=1','elffuss-copilot', | |
| 451 | + copilotWin=window.open(CLAW+'/?copilot=1&skill='+encodeURIComponent(skill),'elffuss-copilot', | |
| 396 | 452 | `popup=yes,width=${w},height=${h},left=${sl+sw-w},top=${st}`); |
| 397 | - if(copilotWin){ $('copilot').classList.add('on'); $('copilot').textContent='Cerrar copiloto'; } | |
| 453 | + if(copilotWin){ $('copilot').classList.add('on'); $('copilot').textContent='Cerrar skill'; } | |
| 454 | +} | |
| 455 | +$('copilot').onclick=()=>{ | |
| 456 | + if(copilotWin && !copilotWin.closed){ try{copilotWin.close();}catch{} copilotReset(); closeSurface(); return; } | |
| 457 | + openSkillPicker(); | |
| 398 | 458 | }; |
| 399 | -// si cierras la ventana del copiloto a mano, el botón vuelve a su estado | |
| 400 | 459 | setInterval(()=>{ if(copilotWin && copilotWin.closed) copilotReset(); }, 1500); |
| 460 | + | |
| 461 | +// ── superficie proyectada: la vista de la skill, DENTRO del translator ── | |
| 462 | +let surfaceOn=false; | |
| 463 | +function showSurface(html){ | |
| 464 | + $('surfFrame').srcdoc=html; document.body.classList.add('withsurface'); surfaceOn=true; | |
| 465 | +} | |
| 466 | +function closeSurface(){ document.body.classList.remove('withsurface'); $('surfFrame').srcdoc=''; surfaceOn=false; } | |
| 467 | +$('surfClose').onclick=closeSurface; | |
| 468 | + | |
| 401 | 469 | window.__copilot={ ready:()=>copilotReady, send:copilotSend, open:()=>$('copilot').click() }; |
| 402 | 470 | |
| 403 | 471 | // ── flujo de arranque: elegir idiomas → consentir → descargar todo → conversar ── |
| @@ -429,7 +497,11 @@ | ||
| 429 | 497 | // Al ocultarse, SIEMPRE soltar el TTS: si se queda hablando, su onend no |
| 430 | 498 | // llega nunca y el medio-dúplex deja la app sorda al volver. |
| 431 | 499 | ttsRelease(); |
| 432 | - if(convOn && convCtx && convCtx.state==='running'){ try{convCtx.suspend();}catch{} convPaused=true; setStatus('Pausado en segundo plano — ahorro de batería.','work'); } | |
| 500 | + // OJO: con el copiloto abierto NO se pausa. Su ventana tapa al translator y | |
| 501 | + // Chrome lo marca «oculto», pero es uso normal: si pausáramos, dejaría de | |
| 502 | + // escuchar justo cuando más falta hace. | |
| 503 | + const copilotOpen = !!(copilotWin && !copilotWin.closed); | |
| 504 | + if(!copilotOpen && convOn && convCtx && convCtx.state==='running'){ try{convCtx.suspend();}catch{} convPaused=true; setStatus('Pausado en segundo plano — ahorro de batería.','work'); } | |
| 433 | 505 | } else if(convOn && convPaused){ |
| 434 | 506 | ttsRelease(); convBusy=false; // volver siempre en limpio |
| 435 | 507 | convPaused=false; |