|
1273 | 1273 | </div> |
1274 | 1274 |
|
1275 | 1275 | <script> |
1276 | | -window.addEventListener('beforeunload',()=>teardownPathWorker(false)); |
| 1276 | +// ── safeLS: localStorage con fallback seguro para entornos iframe/sandbox ── |
| 1277 | +function safeLS(op, key, val) { |
| 1278 | + try { |
| 1279 | + if (op === 'get') return localStorage.getItem(key); |
| 1280 | + if (op === 'set') { localStorage.setItem(key, val); return true; } |
| 1281 | + if (op === 'rm') { localStorage.removeItem(key); return true; } |
| 1282 | + } catch(e) { console.warn('[safeLS] localStorage bloqueado:', e); return null; } |
| 1283 | +} |
| 1284 | + |
1277 | 1285 |
|
1278 | 1286 | if(localStorage.getItem('theme')==='light')document.body.classList.add('light-mode'); |
1279 | 1287 | 'use strict'; |
|
2129 | 2137 | if(typeof AG==='undefined'||!AG)return 0; |
2130 | 2138 | return Object.values(AG).filter(ag=>ag&&ag.state&&ag.state!=='idle').length; |
2131 | 2139 | } |
2132 | | -function refreshOpsBar(){ |
| 2140 | +// [DEDUP-REMOVED] function refreshOpsBar(){ |
2133 | 2141 | const nowEl=document.getElementById('opsNow'); |
2134 | 2142 | const metaEl=document.getElementById('opsMeta'); |
2135 | 2143 | if(!nowEl||!metaEl)return; |
|
2276 | 2284 | }; |
2277 | 2285 | } |
2278 | 2286 |
|
2279 | | -function nearestWalkable(g){let best=null,bd=Infinity;for(let gz=0;gz<GH;gz++)for(let gx=0;gx<GW;gx++){if(!NAV[gz*GW+gx]){const d=(gx-g.gx)**2+(gz-g.gz)**2;if(d<bd){bd=d;best={gx,gz};}}}return best;} |
2280 | | -function astar(sx,sz,tx,tz){ |
| 2287 | +// [DEDUP-REMOVED] function nearestWalkable(g){let best=null,bd=Infinity;for(let gz=0;gz<GH;gz++)for(let gx=0;gx<GW;gx++){if(!NAV[gz*GW+gx]){const d=(gx-g.gx)**2+(gz-g.gz)**2;if(d<bd){bd=d;best={gx,gz};}}}return best;} |
| 2288 | +// [DEDUP-REMOVED] function astar(sx,sz,tx,tz){ |
2281 | 2289 | if(!NAV)return null; |
2282 | 2290 | const sg=wG(sx,sz),eg=wG(tx,tz); |
2283 | 2291 | if(NAV[eg.gz*GW+eg.gx]){const b=nearestWalkable(eg);if(b)Object.assign(eg,b);else return null;} |
|
2308 | 2316 | while(c!==-1&&c!==idx(sg)){raw.unshift(gW(c%GW,Math.floor(c/GW)));c=par[c];} |
2309 | 2317 | return smooth(raw.length?raw:[gW(eg.gx,eg.gz)]); |
2310 | 2318 | } |
2311 | | -function los(x0,z0,x1,z1){ |
| 2319 | +// [DEDUP-REMOVED] function los(x0,z0,x1,z1){ |
2312 | 2320 | const g0=wG(x0,z0),g1=wG(x1,z1);let dx=Math.abs(g1.gx-g0.gx),dz=Math.abs(g1.gz-g0.gz),x=g0.gx,z=g0.gz; |
2313 | 2321 | const sx=g1.gx>g0.gx?1:-1,sz=g1.gz>g0.gz?1:-1,steps=dx+dz;let err=dx-dz; |
2314 | 2322 | for(let i=0;i<=steps;i++){if(x<0||x>=GW||z<0||z>=GH||NAV[z*GW+x])return false;const e2=err*2;if(e2>-dz){err-=dz;x+=sx;}if(e2<dx){err+=dx;z+=sz;}}return true; |
2315 | 2323 | } |
2316 | | -function smooth(pts){if(pts.length<=2)return pts;const res=[pts[0]];let i=0;while(i<pts.length-1){let j=pts.length-1;while(j>i+1&&!los(pts[i].x,pts[i].z,pts[j].x,pts[j].z))j--;i=j;res.push(pts[i]);}return res;} |
| 2324 | +// [DEDUP-REMOVED] function smooth(pts){if(pts.length<=2)return pts;const res=[pts[0]];let i=0;while(i<pts.length-1){let j=pts.length-1;while(j>i+1&&!los(pts[i].x,pts[i].z,pts[j].x,pts[j].z))j--;i=j;res.push(pts[i]);}return res;} |
2317 | 2325 |
|
2318 | 2326 |
|
2319 | 2327 | let pathWorker=null,_wkUrl=null,_wkIdCtr=1,_wkCallbacks=new Map(); |
2320 | 2328 |
|
2321 | | -function teardownPathWorker(resolvePending=false){ |
| 2329 | +// [DEDUP-REMOVED] function teardownPathWorker(resolvePending=false){ |
2322 | 2330 | if(pathWorker){try{pathWorker.terminate();}catch(e){}pathWorker=null;} |
2323 | 2331 | document.getElementById('wkBadge')?.classList.remove('on'); |
2324 | 2332 | if(!resolvePending){_wkCallbacks.clear();return;} |
|
7267 | 7275 | } |
7268 | 7276 |
|
7269 | 7277 | /* AGENT PROFILE */ |
7270 | | -function openProfile(k,px,py){ |
| 7278 | +// [DEDUP-REMOVED] function openProfile(k,px,py){ |
7271 | 7279 | profileKey=k;const cfg=ACFG[k],ag=AG[k]; |
7272 | 7280 | if(GKEY&&chatAgent!==k)setChatAgent(k); |
7273 | 7281 | document.getElementById('apAv').textContent=cfg.name.split(' ').map(n=>n[0]).join(''); |
|
7293 | 7301 | const el=document.getElementById('agentProfile');el.style.left=l+'px';el.style.top=t+'px';el.classList.add('show'); |
7294 | 7302 | syncPanelContext(); |
7295 | 7303 | } |
7296 | | -function updateProfileData(){ |
| 7304 | +// [DEDUP-REMOVED] function updateProfileData(){ |
7297 | 7305 | if(!profileKey)return;const ag=AG[profileKey],cfg=ACFG[profileKey]; |
7298 | 7306 | const st=document.getElementById('apSt');st.textContent=ag.state;st.style.color=cfg.col;st.style.borderColor=cfg.col+'44'; |
7299 | 7307 | document.getElementById('apTm').textContent=ag.stateTime<60?`${Math.floor(ag.stateTime)}s`:`${Math.floor(ag.stateTime/60)}m`; |
7300 | 7308 | document.getElementById('apLast').textContent=ag.lastMsg?`"${ag.lastMsg.slice(0,36)}"` :''; |
7301 | 7309 | } |
7302 | | -function closeProfile(){profileKey=null;document.getElementById('agentProfile').classList.remove('show');syncPanelContext();} |
| 7310 | +// [DEDUP-REMOVED] function closeProfile(){profileKey=null;document.getElementById('agentProfile').classList.remove('show');syncPanelContext();} |
7303 | 7311 | function profileFlow(){if(profileKey)selAgent(profileKey);closeProfile();} |
7304 | | -function profileFollow(){if(!profileKey)return;followAg=profileKey;followT=6.;closeProfile();showToast('Siguiendo → '+ACFG[profileKey].name.split(' ')[0],ACFG[profileKey].col);} |
| 7312 | +// [DEDUP-REMOVED] function profileFollow(){if(!profileKey)return;followAg=profileKey;followT=6.;closeProfile();showToast('Siguiendo → '+ACFG[profileKey].name.split(' ')[0],ACFG[profileKey].col);} |
7305 | 7313 | function profileFPS(){if(!profileKey)return;const k=profileKey;closeProfile();enterFPS(k);} |
7306 | 7314 | function profileChat(){if(!profileKey)return;setChatAgent(profileKey);switchPanel('consola');closeProfile();} |
7307 | 7315 |
|
|
7334 | 7342 | syncPanelContext(); |
7335 | 7343 | } |
7336 | 7344 |
|
7337 | | -function openProfile(k,px,py){ |
| 7345 | +// [DEDUP-REMOVED] function openProfile(k,px,py){ |
7338 | 7346 | profileKey=k; |
7339 | 7347 | const cfg=ACFG[k],ag=AG[k]; |
7340 | 7348 | if(GKEY&&chatAgent!==k)setChatAgent(k); |
|
7422 | 7430 | showToast('Memoria del equipo limpiada','#cc3344'); |
7423 | 7431 | } |
7424 | 7432 |
|
7425 | | -function clearAgentMemory(k){ |
| 7433 | +// [DEDUP-REMOVED] function clearAgentMemory(k){ |
7426 | 7434 | if(!k||k==='all'){clearAllAgentMemory();return;} |
7427 | 7435 | chatH[k]=[]; |
7428 | 7436 | try{localStorage.removeItem('chat_'+k);}catch(e){} |
|
7437 | 7445 | showToast('Memoria de '+ACFG[k].name.split(' ')[0]+' limpiada','#cc3344'); |
7438 | 7446 | } |
7439 | 7447 |
|
7440 | | -function saveChatH(k){ |
| 7448 | +// [DEDUP-REMOVED] function saveChatH(k){ |
7441 | 7449 | try{localStorage.setItem('chat_'+k,JSON.stringify((chatH[k]||[]).slice(-60)));}catch(e){} |
7442 | 7450 | _refreshMemoryBarUI(); |
7443 | 7451 | } |
7444 | 7452 |
|
7445 | | -function initConsole(){ |
| 7453 | +// [DEDUP-REMOVED] function initConsole(){ |
7446 | 7454 | const nk=document.getElementById('noKeyMsg'),cb=document.getElementById('casBar'); |
7447 | 7455 | const ms=document.getElementById('cmsgs'),ip=document.querySelector('.cinp-area'); |
7448 | 7456 | const tw=document.getElementById('toolMiniWrap'),sw=document.getElementById('chatSearchWrap'); |
|
7823 | 7831 | [523,659,784,1047].forEach((f,i)=>{const o=ctx.createOscillator(),g=ctx.createGain();o.type='sine';o.frequency.value=f;g.gain.setValueAtTime(.08,ctx.currentTime+i*.08);g.gain.exponentialRampToValueAtTime(.001,ctx.currentTime+i*.08+.18);o.connect(g);g.connect(ctx.destination);o.start(ctx.currentTime+i*.08);o.stop(ctx.currentTime+i*.08+.2);}); |
7824 | 7832 | }catch(e){} |
7825 | 7833 | } |
7826 | | -function openAchievements(){ |
| 7834 | +// [DEDUP-REMOVED] function openAchievements(){ |
7827 | 7835 | const existing=document.getElementById('achOv');if(existing)existing.remove(); |
7828 | 7836 | const ov=document.createElement('div');ov.id='achOv'; |
7829 | 7837 | ov.style.cssText='position:fixed;inset:0;z-index:300;background:rgba(0,0,0,.88);display:flex;align-items:center;justify-content:center'; |
|
7904 | 7912 | lbl._lvlBadge.textContent='Lv'+lvl; |
7905 | 7913 | } |
7906 | 7914 | // Panel de XP |
7907 | | -function openXPPanel(){ |
| 7915 | +// [DEDUP-REMOVED] function openXPPanel(){ |
7908 | 7916 | const existing=document.getElementById('xpOv');if(existing)existing.remove(); |
7909 | 7917 | const ov=document.createElement('div');ov.id='xpOv'; |
7910 | 7918 | ov.style.cssText='position:fixed;inset:0;z-index:300;background:rgba(0,0,0,.88);display:flex;align-items:center;justify-content:center'; |
|
8933 | 8941 | if(_meetHistory.length>20)_meetHistory.pop(); |
8934 | 8942 | try{localStorage.setItem('meetHistory',JSON.stringify(_meetHistory));}catch(e){} |
8935 | 8943 | } |
8936 | | -function openMeetHistory(){ |
| 8944 | +// [DEDUP-REMOVED] function openMeetHistory(){ |
8937 | 8945 | const existing=document.getElementById('meetHistOv');if(existing)existing.remove(); |
8938 | 8946 | const ov=document.createElement('div');ov.id='meetHistOv'; |
8939 | 8947 | ov.style.cssText='position:fixed;inset:0;z-index:300;background:rgba(0,0,0,.88);display:flex;align-items:center;justify-content:center'; |
|
9442 | 9450 | return currentPanel||'tree'; |
9443 | 9451 | } |
9444 | 9452 |
|
9445 | | -function updateConsoleContextHint(){ |
| 9453 | +// [DEDUP-REMOVED] function updateConsoleContextHint(){ |
9446 | 9454 | const el=document.getElementById('consoleContextHint'); |
9447 | 9455 | if(!el)return; |
9448 | 9456 | const focusKey=_getUiFocusAgentKey(); |
|
9735 | 9743 | data:'Hola, soy Andres Torres, Data Analyst de Dev Teams.' |
9736 | 9744 | }; |
9737 | 9745 | function addGreeting(){const t=GREETS[chatAgent];if(!t)return;appendMsg('agent',ACFG[chatAgent].name,t);chatH[chatAgent].push({role:'assistant',content:t});} |
9738 | | -function setChatAgent(k){ |
| 9746 | +// [DEDUP-REMOVED] function setChatAgent(k){ |
9739 | 9747 | chatAgent=k;document.querySelectorAll('.cas-btn').forEach(b=>b.classList.remove('on'));document.getElementById('cas-'+k)?.classList.add('on'); |
9740 | 9748 | _refreshWorkspaceQuickUI(); |
9741 | 9749 | const badge=document.getElementById('cagbadge'); |
|
9878 | 9886 | if(el)el.value=value; |
9879 | 9887 | } |
9880 | 9888 |
|
9881 | | -function _refreshWorkspaceQuickUI(){ |
| 9889 | +// [DEDUP-REMOVED] function _refreshWorkspaceQuickUI(){ |
9882 | 9890 | const meta=document.getElementById('toolMiniMeta'); |
9883 | 9891 | if(!meta)return; |
9884 | 9892 | if(!_workspaceDirHandle){ |
|
9897 | 9905 | _refreshWorkspaceQuickUI(); |
9898 | 9906 | } |
9899 | 9907 |
|
9900 | | -function _refreshWorkspaceQuickUI(){ |
| 9908 | +// [DEDUP-REMOVED] function _refreshWorkspaceQuickUI(){ |
9901 | 9909 | const meta=document.getElementById('toolMiniMeta'); |
9902 | 9910 | if(!meta)return; |
9903 | 9911 | if(!_workspaceDirHandle){ |
|
0 commit comments