Aichatbot12321 commited on
Commit
c30838e
·
verified ·
1 Parent(s): f1684dd

Update live.html

Browse files
Files changed (1) hide show
  1. live.html +33 -28
live.html CHANGED
@@ -45,7 +45,7 @@ body.live #cap.status{color:#c9cff0}
45
  #pill{flex:1;min-width:0;height:62px;border-radius:34px;position:relative;overflow:hidden;color:var(--dim);font-size:13px;border:1px solid color-mix(in srgb,var(--c1) 35%,#ffffff10);
46
  background:radial-gradient(120% 150% at 50% 140%,color-mix(in srgb,var(--c2) 55%,#0a1a4a),#04060f 70%);
47
  box-shadow:0 0 calc(10px + var(--lv)*52px) color-mix(in srgb,var(--c1) 50%,transparent),inset 0 -10px 24px color-mix(in srgb,var(--c2) 30%,transparent);transition:border-color .6s}
48
- #pill::after{content:"absolute;inset:0;background:linear-gradient(110deg,transparent 30%,#ffffff20 50%,transparent 70%);transform:translateX(-100%);animation:sweep 3.6s ease-in-out infinite}
49
  @keyframes sweep{60%,100%{transform:translateX(100%)}}
50
  #bars{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;gap:5px;opacity:0;transition:opacity .4s}
51
  #bars i{width:5px;height:6px;border-radius:5px;background:linear-gradient(var(--c1),var(--c2))}
@@ -159,8 +159,9 @@ const TXT={idle:'Start a conversation anytime',listening:'Listening…',thinking
159
  nomic:'No sound from your mic. Pick the right one in Settings.',mutedT:'Mic muted',unmutedT:'Mic on',
160
  lang:'AI speaks',mode:'Voice input',mic:'Microphone',brow:'Browser',nat:'Native',err:'Connecting… send again in a moment'};
161
 
162
- // FORCE DATABASE TO MATCH THE REST OF THE SUITE
163
- localforage.config({ name: 'AI_Pro_Suite', storeName: 'massive_chat_history' });
 
164
 
165
  let LANG='hi';
166
  try{LANG=localStorage.getItem('ailang')||'hi'}catch{}
@@ -190,7 +191,7 @@ function applyLang(){
190
  }
191
 
192
  async function saveToHistory() {
193
- if (interactionCount < 2) return;
194
  try {
195
  let history = await localforage.getItem('aiHistory') || [];
196
 
@@ -386,6 +387,7 @@ $('mics').onchange=e=>{micId=e.target.value;try{localStorage.setItem('micId',mic
386
  async function start(){if(active||starting)return;try{await startInner()}catch(e){console.error(e);toast('Start failed: '+(e&&e.message||e),10000);stop()}}
387
  async function startInner(){
388
  starting=true;
 
389
  if(!navigator.mediaDevices||!window.AudioWorklet){starting=false;toast('The microphone only works on http://localhost or https. Open the page that way.',10000);return}
390
  try{stream=await openMic()}catch(e){starting=false;toast('Microphone error: '+(e.name||e.message)+'. Allow the microphone and try again.',10000);return}
391
  stream.getAudioTracks().forEach(t=>t.enabled=!muted);
@@ -418,6 +420,7 @@ async function startInner(){
418
  if(typeof e.data!=='string'){playPcm(e.data);return}
419
  const d=JSON.parse(e.data);
420
  if(d.t==='ready'){active=true;starting=false;document.body.classList.add('live');$('bend').classList.add('on');$('st').textContent=d.model;
 
421
  state='';setState('thinking');chunks=0;heard=0;if(MODE==='stt')startRec();
422
  clearInterval(window.dbg);window.dbg=setInterval(()=>{$('diag').textContent=(MODE==='stt'?'phrases '+heard+' · '+rst:'native')+' · audio '+chunks},600)}
423
  else if(d.t==='user')onUserText(d.text);
@@ -433,7 +436,7 @@ function stop(){
433
  active=false;starting=false;stopRec();closeCam();clearTimeout(window.silent);clearInterval(window.dbg);liveUser=null;micAn=null;
434
  try{ws.close()}catch{}stream&&stream.getTracks().forEach(t=>t.stop());
435
  micCtx&&micCtx.close();outCtx&&outCtx.close();stopPlayback();hideTyping();endTurn();
436
- document.body.classList.remove('live');$('bend').classList.remove('on');$('st').textContent='offline';
437
  botActive=false;ucapSet('');state='';setState('idle');
438
  }
439
  function restart(){if(active){stop();setTimeout(start,400)}}
@@ -530,30 +533,32 @@ document.addEventListener("DOMContentLoaded", () => {
530
  if (restoreId) {
531
  $('textview').classList.add('on');$('textview').dataset.restored = "true";
532
 
533
- localforage.getItem('aiHistory').then(history => {
534
- if (history) {
535
- const session = history.find(h => String(h.id) === String(restoreId));
536
- if (session && session.interactions) {
537
- liveSessionId = session.id;
538
- currentInteractions = session.interactions;
539
- interactionCount = currentInteractions.length;
540
-
541
- session.interactions.forEach(inter => {
542
- if (inter.question) {
543
- const u = newLine('you');
544
- u.classList.remove('cursor');
545
- u.lastChild.textContent = inter.question;
546
- }
547
- if (inter.answer) {
548
- const b = newLine('bot');
549
- b.classList.remove('cursor');
550
- b.lastChild.textContent = inter.answer;
551
- }
552
- });
553
- chat.scrollTop = 1e9;
 
 
554
  }
555
- }
556
- }).catch(e => console.error("Restore Error:", e));
557
  }
558
  });
559
  </script>
 
45
  #pill{flex:1;min-width:0;height:62px;border-radius:34px;position:relative;overflow:hidden;color:var(--dim);font-size:13px;border:1px solid color-mix(in srgb,var(--c1) 35%,#ffffff10);
46
  background:radial-gradient(120% 150% at 50% 140%,color-mix(in srgb,var(--c2) 55%,#0a1a4a),#04060f 70%);
47
  box-shadow:0 0 calc(10px + var(--lv)*52px) color-mix(in srgb,var(--c1) 50%,transparent),inset 0 -10px 24px color-mix(in srgb,var(--c2) 30%,transparent);transition:border-color .6s}
48
+ #pill::after{content:"";position:absolute;inset:0;background:linear-gradient(110deg,transparent 30%,#ffffff20 50%,transparent 70%);transform:translateX(-100%);animation:sweep 3.6s ease-in-out infinite}
49
  @keyframes sweep{60%,100%{transform:translateX(100%)}}
50
  #bars{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;gap:5px;opacity:0;transition:opacity .4s}
51
  #bars i{width:5px;height:6px;border-radius:5px;background:linear-gradient(var(--c1),var(--c2))}
 
159
  nomic:'No sound from your mic. Pick the right one in Settings.',mutedT:'Mic muted',unmutedT:'Mic on',
160
  lang:'AI speaks',mode:'Voice input',mic:'Microphone',brow:'Browser',nat:'Native',err:'Connecting… send again in a moment'};
161
 
162
+ if (typeof localforage !== 'undefined') {
163
+ localforage.config({ name: 'AI_Pro_Suite', storeName: 'massive_chat_history' });
164
+ }
165
 
166
  let LANG='hi';
167
  try{LANG=localStorage.getItem('ailang')||'hi'}catch{}
 
191
  }
192
 
193
  async function saveToHistory() {
194
+ if (interactionCount < 2 || typeof localforage === 'undefined') return;
195
  try {
196
  let history = await localforage.getItem('aiHistory') || [];
197
 
 
387
  async function start(){if(active||starting)return;try{await startInner()}catch(e){console.error(e);toast('Start failed: '+(e&&e.message||e),10000);stop()}}
388
  async function startInner(){
389
  starting=true;
390
+ $('st').textContent = 'Connecting...';$('pl').textContent = 'Connecting...';
391
  if(!navigator.mediaDevices||!window.AudioWorklet){starting=false;toast('The microphone only works on http://localhost or https. Open the page that way.',10000);return}
392
  try{stream=await openMic()}catch(e){starting=false;toast('Microphone error: '+(e.name||e.message)+'. Allow the microphone and try again.',10000);return}
393
  stream.getAudioTracks().forEach(t=>t.enabled=!muted);
 
420
  if(typeof e.data!=='string'){playPcm(e.data);return}
421
  const d=JSON.parse(e.data);
422
  if(d.t==='ready'){active=true;starting=false;document.body.classList.add('live');$('bend').classList.add('on');$('st').textContent=d.model;
423
+ $('pl').textContent=T('tap');
424
  state='';setState('thinking');chunks=0;heard=0;if(MODE==='stt')startRec();
425
  clearInterval(window.dbg);window.dbg=setInterval(()=>{$('diag').textContent=(MODE==='stt'?'phrases '+heard+' · '+rst:'native')+' · audio '+chunks},600)}
426
  else if(d.t==='user')onUserText(d.text);
 
436
  active=false;starting=false;stopRec();closeCam();clearTimeout(window.silent);clearInterval(window.dbg);liveUser=null;micAn=null;
437
  try{ws.close()}catch{}stream&&stream.getTracks().forEach(t=>t.stop());
438
  micCtx&&micCtx.close();outCtx&&outCtx.close();stopPlayback();hideTyping();endTurn();
439
+ document.body.classList.remove('live');$('bend').classList.remove('on');$('st').textContent='offline';$('pl').textContent=T('tap');
440
  botActive=false;ucapSet('');state='';setState('idle');
441
  }
442
  function restart(){if(active){stop();setTimeout(start,400)}}
 
533
  if (restoreId) {
534
  $('textview').classList.add('on');$('textview').dataset.restored = "true";
535
 
536
+ if (typeof localforage !== 'undefined') {
537
+ localforage.getItem('aiHistory').then(history => {
538
+ if (history) {
539
+ const session = history.find(h => String(h.id) === String(restoreId));
540
+ if (session && session.interactions) {
541
+ liveSessionId = session.id;
542
+ currentInteractions = session.interactions;
543
+ interactionCount = currentInteractions.length;
544
+
545
+ session.interactions.forEach(inter => {
546
+ if (inter.question) {
547
+ const u = newLine('you');
548
+ u.classList.remove('cursor');
549
+ u.lastChild.textContent = inter.question;
550
+ }
551
+ if (inter.answer) {
552
+ const b = newLine('bot');
553
+ b.classList.remove('cursor');
554
+ b.lastChild.textContent = inter.answer;
555
+ }
556
+ });
557
+ chat.scrollTop = 1e9;
558
+ }
559
  }
560
+ }).catch(e => console.error("Restore Error:", e));
561
+ }
562
  }
563
  });
564
  </script>