tz-voice-chat 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var ve=Object.create;var fe=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var xe=Object.getPrototypeOf,Ae=Object.prototype.hasOwnProperty;var Ie=(e,s,n,a)=>{if(s&&typeof s=="object"||typeof s=="function")for(let t of Te(s))!Ae.call(e,t)&&t!==n&&fe(e,t,{get:()=>s[t],enumerable:!(a=ke(s,t))||a.enumerable});return e};var de=(e,s,n)=>(n=e!=null?ve(xe(e)):{},Ie(s||!e||!e.__esModule?fe(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react"),g=require("react/jsx-runtime");var ie=typeof document<"u"?document.currentScript:null;function he(){let e="";function s(){const n=[];for(;;){const a=/([.!?]{1,3})(\s|$)/.exec(e);if(a){const t=e.slice(0,a.index+a[0].length).trim();if(t.length>=10){n.push(t),e=e.slice(a.index+a[0].length);continue}}if(e.length>=25){const t=/[,;:—–](\s|$)/.exec(e);if(t){const o=e.slice(0,t.index+t[0].length).trim();if(o.length>=20){n.push(o),e=e.slice(t.index+t[0].length);continue}}}if(e.length>=45){const t=e.lastIndexOf(" ",44),o=t>10?t:45;n.push(e.slice(0,o).trim()),e=e.slice(o).trimStart();continue}break}return n}return{write(n){return e+=n,s()},flush(){const n=e.trim();return e="",n}}}async function Ne(e,{dtype:s="q8",device:n="cpu",modelProxyUrl:a="/api/models/"}={}){var u,v;const{env:t}=await import("/vendor/transformers/transformers.min.js");t.remoteHost=a,(v=(u=t==null?void 0:t.backends)==null?void 0:u.onnx)!=null&&v.wasm&&(t.backends.onnx.wasm.wasmPaths="/vendor/transformers/"),t!=null&&t.onnx&&(t.onnx.logSeverityLevel=3);const o=await import("/vendor/kokoro/kokoro.web.js"),{KokoroTTS:i}=o;let b=s;n==="webgpu"&&(s==="q4"||s==="q8")&&(console.warn(`[modelLoader] dtype "${s}" not supported on WebGPU — using "fp32".`),b="fp32");let r=0;const m=d=>{typeof(d==null?void 0:d.progress)=="number"&&(r=Math.max(r,d.progress/100),e==null||e("kokoro",Math.min(.99,r)))};async function w(d,_){return i.from_pretrained("onnx-community/Kokoro-82M-ONNX",{dtype:_,device:d,progress_callback:m})}let c;try{c=await w(n,b)}catch(d){if(n!=="wasm")console.warn(`[modelLoader] Kokoro on "${n}" failed (${d==null?void 0:d.message}) — falling back to WASM.`),r=0,c=await w("wasm",s);else throw d}return e==null||e("kokoro",1),{kokoro:c}}function Re(e,{voice:s="af_bella",onPlayStart:n}={}){const a=new AudioContext,t=[];let o=!1,i=null,b=!1;async function r(c){if(c instanceof AudioBuffer)return c;const u=(c==null?void 0:c.audio)??c;if(u instanceof ArrayBuffer)return await a.decodeAudioData(u.slice(0));if(u instanceof Float32Array){const v=(c==null?void 0:c.samplingRate)??24e3,d=a.createBuffer(1,u.length,v);return d.copyToChannel(u,0),d}throw new Error("Unsupported TTS payload")}async function m(c){await a.resume();const u=a.createBufferSource();return u.buffer=c,u.connect(a.destination),new Promise(v=>{u.onended=()=>{i===u&&(i=null),v()},i=u,u.start(),b||(b=!0,n==null||n())})}async function w(){if(!o){for(o=!0;t.length>0;){const c=t.shift();try{const u=await c;u&&await m(u)}catch(u){console.error("[TtsQueue]",u)}}o=!1}}return{enqueue(c){t.push(e.generate(c,{voice:s}).then(r)),w()},cancel(){if(t.length=0,i){try{i.stop()}catch{}i=null}},async finished(){for(;o||t.length>0;)await new Promise(c=>setTimeout(c,200))}}}function ze({voice:e="",onPlayStart:s,url:n="/api/tts"}={}){const a=new AudioContext,t=[];let o=!1,i=null,b=!1;async function r(c){const u={text:c};e&&(u.voice=e);const v=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)});if(!v.ok)throw new Error(`TTS ${v.status}: ${await v.text()}`);return a.decodeAudioData(await v.arrayBuffer())}async function m(c){await a.resume();const u=a.createBufferSource();return u.buffer=c,u.connect(a.destination),new Promise(v=>{u.onended=()=>{i===u&&(i=null),v()},i=u,u.start(),b||(b=!0,s==null||s())})}async function w(){if(!o){for(o=!0;t.length>0;){const c=t.shift();try{await m(await c)}catch(u){console.error("[ServerTTS]",u)}}o=!1}}return{enqueue(c){c!=null&&c.trim()&&(t.push(r(c)),w())},cancel(){if(t.length=0,i){try{i.stop()}catch{}i=null}b=!1},async finished(){for(;o||t.length>0;)await new Promise(c=>setTimeout(c,100))}}}function Ee({voice:e="",rate:s=1,pitch:n=1,onPlayStart:a}={}){const t=[];let o=!1,i=!1;function b(){return e?speechSynthesis.getVoices().find(w=>w.name===e||w.voiceURI===e)??null:null}function r(){if(o||t.length===0)return;o=!0;const m=t.shift(),w=new SpeechSynthesisUtterance(m),c=b();c&&(w.voice=c),w.rate=s,w.pitch=n,w.onstart=()=>{i||(i=!0,a==null||a())},w.onend=()=>{o=!1,r()},w.onerror=u=>{console.error("[WebSpeech TTS] error",u.error),o=!1,r()},speechSynthesis.speak(w)}return{enqueue(m){m!=null&&m.trim()&&(t.push(m),r())},cancel(){t.length=0,speechSynthesis.cancel(),o=!1,i=!1},async finished(){for(;o||t.length>0;)await new Promise(m=>setTimeout(m,100))}}}async function _e({onSpeechStart:e,onSpeechEnd:s,onError:n,deviceId:a}){try{const{MicVAD:t}=window.vad;return await t.new({model:"legacy",baseAssetPath:"/vendor/vad/",onnxWASMBasePath:"/vendor/ort/",additionalAudioConstraints:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!1,...a?{deviceId:{exact:a}}:{}},onSpeechStart:()=>e==null?void 0:e(),onSpeechEnd:i=>{console.log("[VAD] onSpeechEnd — samples:",i==null?void 0:i.length),s==null||s(i)},onVADMisfire:()=>{},negativeSpeechThreshold:.25,positiveSpeechThreshold:.5,redemptionFrames:4,minSpeechFrames:3,preSpeechPadFrames:1})}catch(t){throw n==null||n("VAD initialization failed. Falling back to manual microphone capture."),t}}const S={IDLE:"idle",LISTENING:"listening",TRANSCRIBING:"transcribing",THINKING:"thinking",SPEAKING:"speaking"},Me="You are a friendly assistant for quick voice interactions. Provide answers only in the form of a single concise sentence, without any introductory phrases. Don't use any formatting, markdown, emoji, or code blocks — just plain text. The answers will be spoken aloud, so keep them short and natural.";function je({processInput:e,systemPrompt:s=Me,ttsProvider:n="server-kokoro",ttsVoice:a="af_bella",ttsServerUrl:t="/api/tts",ttsSpeechRate:o=1,ttsSpeechPitch:i=1,whisperModel:b="onnx-community/whisper-tiny.en",whisperDtype:r="q8",whisperDevice:m="cpu",kokoroDtype:w="q8",kokoroBrowserDevice:c="wasm",modelProxyUrl:u="/api/models/"}={}){const[v,d]=h.useState(S.IDLE),[_,A]=h.useState(!0),[j,N]=h.useState({whisper:0,kokoro:0}),[L,z]=h.useState(null),[J,P]=h.useState([]),[$,G]=h.useState(null),[y,R]=h.useState(!1),[M,Y]=h.useState(""),[X,ee]=h.useState([]),[te,C]=h.useState(null),D=h.useRef(S.IDLE),B=h.useRef(!1),x=h.useRef(null),V=h.useRef(null),K=h.useRef(null),U=h.useRef(null),ne=h.useRef(null),se=h.useRef(null),Q=h.useRef([{role:"system",content:s}]),ae=h.useRef(e);h.useEffect(()=>{D.current=v},[v]),h.useEffect(()=>{B.current=y},[y]),h.useEffect(()=>{ae.current=e},[e]),h.useEffect(()=>{async function p(){try{const k=await navigator.mediaDevices.enumerateDevices();ee(k.filter(l=>l.kind==="audioinput"))}catch{}}return p(),navigator.mediaDevices.addEventListener("devicechange",p),()=>navigator.mediaDevices.removeEventListener("devicechange",p)},[y]),h.useEffect(()=>{let p=!1;async function k(){try{const l=()=>{var f;n==="webspeech"&&((f=V.current)==null||f.pause())};if(n==="webspeech")x.current=Ee({voice:a,rate:o,pitch:i,onPlayStart:l}),N(f=>({...f,kokoro:1}));else if(n==="kokoro"){const{kokoro:f}=await Ne((T,q)=>N(F=>({...F,[T]:q})),{dtype:w,device:c,modelProxyUrl:u});if(p)return;x.current=Re(f,{voice:a,onPlayStart:l})}else x.current=ze({voice:a,onPlayStart:l,url:t}),N(f=>({...f,kokoro:1}));if(p)return;U.current=new Worker(new URL("/assets/whisperWorker-BJuP9cl9.js",typeof document>"u"?require("url").pathToFileURL(__filename).href:ie&&ie.tagName.toUpperCase()==="SCRIPT"&&ie.src||new URL("index.cjs",document.baseURI).href),{type:"module"}),U.current.onmessage=f=>{f.data.type==="transcript"?pe(f.data.text):f.data.type==="progress"?N(T=>({...T,whisper:f.data.progress})):f.data.type==="ready"?(N(T=>({...T,whisper:1})),A(!1)):f.data.type==="error"&&(z(`Whisper: ${f.data.message}`),A(!1))},U.current.onerror=()=>{z("Model load failed. Check WebGPU/WASM browser support."),A(!1)},U.current.postMessage({type:"init",model:b,dtype:r,device:m,modelProxyUrl:u})}catch(l){p||(z("Initialisation failed: "+((l==null?void 0:l.message)??String(l))),A(!1))}}return k(),()=>{var l;p=!0,(l=U.current)==null||l.terminate()}},[n,b,r,m,w,c]);function ce(p,k){P(l=>[...l,{role:p,content:k,time:new Date().toISOString()}])}async function pe(p){if(!(p!=null&&p.trim())){d(B.current?S.LISTENING:S.IDLE);return}d(S.THINKING),ce("user",p);const k=[...Q.current,{role:"user",content:p}];Q.current=k,await ge(p,k)}async function ge(p,k){var l,f,T,q,F;(l=K.current)==null||l.abort(),K.current=new AbortController,(f=x.current)==null||f.cancel();try{if(!ae.current)throw new Error("processInput is not provided");const W=he();let H="",re=!1;G("");for await(const ue of ae.current(p,k,K.current.signal))H+=ue,G(H),W.write(ue).forEach(Se=>{var le;re||(re=!0,d(S.SPEAKING)),(le=x.current)==null||le.enqueue(Se)});const oe=W.flush();oe&&(re||d(S.SPEAKING),(T=x.current)==null||T.enqueue(oe)),ce("assistant",H),G(null),Q.current=[...Q.current,{role:"assistant",content:H}],await((q=x.current)==null?void 0:q.finished()),n==="webspeech"&&((F=V.current)==null||F.start())}catch(W){G(null),W.name!=="AbortError"&&z(W.message||"Processing failed.")}finally{d(B.current?S.LISTENING:S.IDLE)}}async function we(){var p,k;z(null),D.current===S.SPEAKING&&((p=x.current)==null||p.cancel(),(k=K.current)==null||k.abort());try{d(S.LISTENING),R(!0);try{const l=await navigator.mediaDevices.getUserMedia({audio:M?{deviceId:{exact:M}}:!0,video:!1});se.current=l;const f=new AudioContext;ne.current=f;const T=f.createAnalyser();T.fftSize=256,f.createMediaStreamSource(l).connect(T),C(T)}catch(l){console.warn("[TZVoiceChat] waveform analyser unavailable:",l)}V.current=await _e({onSpeechStart:()=>{var l,f;n==="webspeech"&&D.current===S.SPEAKING||(D.current===S.SPEAKING&&((l=x.current)==null||l.cancel(),(f=K.current)==null||f.abort()),d(S.LISTENING))},onSpeechEnd:l=>{var f;n==="webspeech"&&D.current===S.SPEAKING||(d(S.TRANSCRIBING),(f=U.current)==null||f.postMessage({type:"transcribe",audio:l},[l.buffer]))},onError:l=>{z(l),d(S.IDLE)},deviceId:M||void 0})}catch(l){console.error("[TZVoiceChat] startListening failed:",l),z("Microphone access failed. Allow audio permissions and refresh."),d(S.IDLE),R(!1)}}function be(){var p,k,l,f,T;R(!1),(p=V.current)==null||p.destroy(),V.current=null,(k=se.current)==null||k.getTracks().forEach(q=>q.stop()),se.current=null,(l=ne.current)==null||l.close(),ne.current=null,C(null),(f=x.current)==null||f.cancel(),(T=K.current)==null||T.abort(),d(S.IDLE)}function ye(p){var T;if(!(p!=null&&p.trim()))return;d(S.SPEAKING);const k=he(),l=k.write(p),f=k.flush();[...l,...f?[f]:[]].forEach(q=>{var F;return(F=x.current)==null?void 0:F.enqueue(q)}),(T=x.current)==null||T.finished().then(()=>{d(B.current?S.LISTENING:S.IDLE)})}return{status:v,loading:_,progress:j,error:L,transcript:J,streamingMessage:$,micEnabled:y,startListening:we,stopListening:be,speak:ye,liveAnalyser:te,devices:X,selectedMicId:M,setSelectedMicId:Y}}function me(e){const s=e.replace("#",""),n=s.length===3?s.split("").map(a=>a+a).join(""):s;return[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]}function Le(e,s,n){e/=255,s/=255,n/=255;const a=Math.max(e,s,n),t=Math.min(e,s,n),o=(a+t)/2;if(a===t)return[0,0,o*100];const i=a-t,b=o>.5?i/(2-a-t):i/(a+t);let r;switch(a){case e:r=((s-n)/i+(s<n?6:0))/6;break;case s:r=((n-e)/i+2)/6;break;default:r=((e-s)/i+4)/6}return[r*360,b*100,o*100]}function $e(e,s,n){s/=100,n/=100;const a=i=>(i+e/30)%12,t=s*Math.min(n,1-n),o=i=>n-t*Math.max(-1,Math.min(a(i)-3,Math.min(9-a(i),1)));return[Math.round(o(0)*255),Math.round(o(8)*255),Math.round(o(4)*255)]}function E(e,s){const[n,a,t]=me(e),[o,i,b]=Le(n,a,t),[r,m,w]=$e(o,i,Math.max(0,Math.min(100,b+s)));return`rgb(${r}, ${m}, ${w})`}function I(e,s){const[n,a,t]=me(e);return`rgba(${n}, ${a}, ${t}, ${s})`}function O(e,s){return e.replace("rgb(","rgba(").replace(")",`, ${s})`)}const Z=10;function De({analyser:e}){const s=h.useRef(null),n=h.useRef(null);return h.useEffect(()=>{if(cancelAnimationFrame(n.current),!e)return;const a=s.current;if(!a)return;const t=a.getContext("2d"),o=e.frequencyBinCount,i=new Uint8Array(o),b=Math.max(1,Math.floor(o/Z)),r=getComputedStyle(a),m=+r.getPropertyValue("--bar-hue"),w=+r.getPropertyValue("--bar-hue-range"),c=+r.getPropertyValue("--bar-sat"),u=+r.getPropertyValue("--bar-lit"),v=+r.getPropertyValue("--bar-lit-range"),d=()=>{n.current=requestAnimationFrame(d),e.getByteFrequencyData(i);const _=a.width,A=a.height;t.clearRect(0,0,_,A);const j=(_-(Z-1)*2)/Z;for(let N=0;N<Z;N++){const L=i[N*b]/255,z=Math.max(3,L*A*.88);t.fillStyle=`hsl(${m+L*w}, ${c}%, ${u+L*v}%)`,t.beginPath(),t.roundRect(N*(j+2),(A-z)/2,j,z,[2]),t.fill()}};return d(),()=>cancelAnimationFrame(n.current)},[e]),g.jsx("canvas",{ref:s,width:55,height:35,className:"ai-btn__canvas"})}function qe({status:e="idle",active:s=!1,loading:n=!1,analyser:a=null,onToggle:t,devices:o=[],selectedMicId:i="",onDeviceChange:b,accentColor:r="#f97316",uiColor:m="#64748b",size:w=70,barHue:c=25,barHueRange:u=20,barSat:v=88,barLit:d=65,barLitRange:_=20}){var G;const[A,j]=h.useState(!1),N=h.useRef(null);h.useEffect(()=>{if(!A)return;function y(R){var M;(M=N.current)!=null&&M.contains(R.target)||j(!1)}return document.addEventListener("pointerdown",y),()=>document.removeEventListener("pointerdown",y)},[A]);function L(y){b==null||b(y),j(!1)}const z=h.useMemo(()=>{const y=E(r,-8),R=E(r,-15),M=E(r,-22),Y=E(r,-30),X=E(r,-42),ee=E(r,8),te=E(r,20),C=E(r,30),D=E(m,-22),B=E(m,-30),x=E(m,18),V=E(m,37);return{"--tz-size":`${w}px`,"--tz-a":r,"--tz-a-d8":y,"--tz-a-d15":R,"--tz-a-d22":M,"--tz-a-d30":Y,"--tz-a-d42":X,"--tz-a-l8":ee,"--tz-a-l20":te,"--tz-a-l30":C,"--tz-a-25":I(r,.25),"--tz-a-28":I(r,.28),"--tz-a-30":I(r,.3),"--tz-a-32":I(r,.32),"--tz-a-34":I(r,.34),"--tz-a-35":I(r,.35),"--tz-a-38":I(r,.38),"--tz-a-45":I(r,.45),"--tz-a-50":I(r,.5),"--tz-a-55":I(r,.55),"--tz-a-60":I(r,.6),"--tz-a-65":I(r,.65),"--tz-a-68":I(r,.68),"--tz-u":m,"--tz-u-d22":D,"--tz-u-d30":B,"--tz-u-l18":x,"--tz-u-l37":V,"--tz-u-30":I(m,.3),"--tz-u-55":I(m,.55),"--tz-u-d30-a85":O(B,.85),"--tz-u-l18-a18":O(x,.18),"--tz-u-l18-a20":O(x,.2),"--tz-u-l18-a32":O(x,.32),"--tz-u-d22-a90":O(D,.9),"--bar-hue":c,"--bar-hue-range":u,"--bar-sat":v,"--bar-lit":d,"--bar-lit-range":_}},[r,m,w,c,u,v,d,_]),J=((G=o.find(y=>y.deviceId===i))==null?void 0:G.label)||(i?`Mic ${i.slice(0,6)}…`:"Default mic"),P=s?e:"off";let $;return!s||e==="idle"?$=g.jsx("svg",{className:"ai-btn__mic",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:g.jsx("path",{d:"M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4zm6 10a1 1 0 0 1 2 0 8 8 0 0 1-7 7.94V21h2a1 1 0 0 1 0 2H9a1 1 0 0 1 0-2h2v-2.06A8 8 0 0 1 4 11a1 1 0 0 1 2 0 6 6 0 0 0 12 0z"})}):e==="listening"?$=g.jsx(De,{analyser:a}):e==="transcribing"?$=g.jsx("div",{className:"ai-btn__bars ai-btn__bars--transcribing",children:Array.from({length:7},(y,R)=>g.jsx("span",{style:{animationDelay:`${R*.1}s`}},R))}):e==="thinking"?$=g.jsxs("div",{className:"ai-btn__dots",children:[g.jsx("span",{}),g.jsx("span",{style:{animationDelay:"0.18s"}}),g.jsx("span",{style:{animationDelay:"0.36s"}})]}):e==="speaking"&&($=g.jsx("div",{className:"ai-btn__bars ai-btn__bars--speaking",children:Array.from({length:7},(y,R)=>g.jsx("span",{style:{animationDelay:`${R*.11}s`}},R))})),g.jsxs("div",{className:"ai-btn-root",style:z,children:[g.jsxs("div",{className:`ai-btn-rings ai-btn-rings--${P}`,"aria-hidden":"true",children:[g.jsx("span",{className:"ai-ring ai-ring--1"}),g.jsx("span",{className:"ai-ring ai-ring--2"})]}),g.jsxs("button",{className:`ai-btn ai-btn--${P}`,disabled:n,onClick:t,"aria-label":s?"Stop assistant":"Start assistant","aria-pressed":s,children:[$,s&&g.jsx("span",{className:"ai-btn__hover-stop","aria-hidden":"true",children:"■"})]}),g.jsxs("div",{className:`ai-mic-sel${A?" open":""}`,ref:N,children:[g.jsxs("button",{className:"ai-mic-sel__trigger",onClick:()=>j(y=>!y),title:"Change microphone","aria-label":"Change microphone","aria-expanded":A,children:[g.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[g.jsx("path",{d:"M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4z"}),g.jsx("path",{d:"M5 11a1 1 0 0 0-2 0 9 9 0 0 0 8 8.94V22H9a1 1 0 0 0 0 2h6a1 1 0 0 0 0-2h-2v-2.06A9 9 0 0 0 21 11a1 1 0 0 0-2 0 7 7 0 0 1-14 0z"})]}),g.jsx("span",{className:"ai-mic-sel__label",children:J}),g.jsx("svg",{className:`ai-mic-sel__caret${A?" open":""}`,width:"9",height:"9",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:g.jsx("path",{d:"M12 16L4 8h16l-8 8z"})})]}),A&&g.jsxs("ul",{className:"ai-mic-sel__menu",role:"listbox","aria-label":"Select microphone",children:[g.jsx("li",{role:"option",className:`ai-mic-sel__option${i===""?" selected":""}`,onClick:()=>L(""),"aria-selected":i==="",children:"Default microphone"}),o.map(y=>g.jsx("li",{role:"option",className:`ai-mic-sel__option${i===y.deviceId?" selected":""}`,onClick:()=>L(y.deviceId),"aria-selected":i===y.deviceId,children:y.label||`Microphone ${y.deviceId.slice(0,8)}`},y.deviceId))]})]})]})}exports.AIAssistantButton=qe;exports.STATES=S;exports.TZVoiceChat=je;
1
+ "use strict";var ve=Object.create;var de=Object.defineProperty;var xe=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var ke=Object.getPrototypeOf,Ae=Object.prototype.hasOwnProperty;var Ie=(e,s,n,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let t of Te(s))!Ae.call(e,t)&&t!==n&&de(e,t,{get:()=>s[t],enumerable:!(r=xe(s,t))||r.enumerable});return e};var he=(e,s,n)=>(n=e!=null?ve(ke(e)):{},Ie(s||!e||!e.__esModule?de(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react"),h=require("react/jsx-runtime");var ie=typeof document<"u"?document.currentScript:null;function me(){let e="";function s(){const n=[];for(;;){const r=/([.!?]{1,3})(\s|$)/.exec(e);if(r){const t=e.slice(0,r.index+r[0].length).trim();if(t.length>=10){n.push(t),e=e.slice(r.index+r[0].length);continue}}if(e.length>=25){const t=/[,;:—–](\s|$)/.exec(e);if(t){const o=e.slice(0,t.index+t[0].length).trim();if(o.length>=20){n.push(o),e=e.slice(t.index+t[0].length);continue}}}if(e.length>=45){const t=e.lastIndexOf(" ",44),o=t>10?t:45;n.push(e.slice(0,o).trim()),e=e.slice(o).trimStart();continue}break}return n}return{write(n){return e+=n,s()},flush(){const n=e.trim();return e="",n}}}async function Ne(e,{dtype:s="q8",device:n="cpu",modelProxyUrl:r="/api/models/"}={}){var u,S;const{env:t}=await import("/vendor/transformers/transformers.min.js");t.remoteHost=r,(S=(u=t==null?void 0:t.backends)==null?void 0:u.onnx)!=null&&S.wasm&&(t.backends.onnx.wasm.wasmPaths="/vendor/transformers/"),t!=null&&t.onnx&&(t.onnx.logSeverityLevel=3);const o=await import("/vendor/kokoro/kokoro.web.js"),{KokoroTTS:i}=o;let b=s;n==="webgpu"&&(s==="q4"||s==="q8")&&(console.warn(`[modelLoader] dtype "${s}" not supported on WebGPU — using "fp32".`),b="fp32");let p=0;const w=d=>{typeof(d==null?void 0:d.progress)=="number"&&(p=Math.max(p,d.progress/100),e==null||e("kokoro",Math.min(.99,p)))};async function c(d,j){return i.from_pretrained("onnx-community/Kokoro-82M-ONNX",{dtype:j,device:d,progress_callback:w})}let a;try{a=await c(n,b)}catch(d){if(n!=="wasm")console.warn(`[modelLoader] Kokoro on "${n}" failed (${d==null?void 0:d.message}) — falling back to WASM.`),p=0,a=await c("wasm",s);else throw d}return e==null||e("kokoro",1),{kokoro:a}}function Le(e,{voice:s="af_bella",onPlayStart:n}={}){const r=new AudioContext,t=[];let o=!1,i=null,b=!1;async function p(a){if(a instanceof AudioBuffer)return a;const u=(a==null?void 0:a.audio)??a;if(u instanceof ArrayBuffer)return await r.decodeAudioData(u.slice(0));if(u instanceof Float32Array){const S=(a==null?void 0:a.samplingRate)??24e3,d=r.createBuffer(1,u.length,S);return d.copyToChannel(u,0),d}throw new Error("Unsupported TTS payload")}async function w(a){await r.resume();const u=r.createBufferSource();return u.buffer=a,u.connect(r.destination),new Promise(S=>{u.onended=()=>{i===u&&(i=null),S()},i=u,u.start(),b||(b=!0,n==null||n())})}async function c(){if(!o){for(o=!0;t.length>0;){const a=t.shift();try{const u=await a;u&&await w(u)}catch(u){console.error("[TtsQueue]",u)}}o=!1}}return{enqueue(a){t.push(e.generate(a,{voice:s}).then(p)),c()},cancel(){if(t.length=0,i){try{i.stop()}catch{}i=null}},async finished(){for(;o||t.length>0;)await new Promise(a=>setTimeout(a,200))}}}function Re({voice:e="",onPlayStart:s,url:n="/api/tts"}={}){const r=new AudioContext,t=[];let o=!1,i=null,b=!1;async function p(a){const u={text:a};e&&(u.voice=e);const S=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)});if(!S.ok)throw new Error(`TTS ${S.status}: ${await S.text()}`);return r.decodeAudioData(await S.arrayBuffer())}async function w(a){await r.resume();const u=r.createBufferSource();return u.buffer=a,u.connect(r.destination),new Promise(S=>{u.onended=()=>{i===u&&(i=null),S()},i=u,u.start(),b||(b=!0,s==null||s())})}async function c(){if(!o){for(o=!0;t.length>0;){const a=t.shift();try{await w(await a)}catch(u){console.error("[ServerTTS]",u)}}o=!1}}return{enqueue(a){a!=null&&a.trim()&&(t.push(p(a)),c())},cancel(){if(t.length=0,i){try{i.stop()}catch{}i=null}b=!1},async finished(){for(;o||t.length>0;)await new Promise(a=>setTimeout(a,100))}}}function _e({voice:e="",rate:s=1,pitch:n=1,onPlayStart:r}={}){const t=[];let o=!1,i=!1;function b(){return e?speechSynthesis.getVoices().find(c=>c.name===e||c.voiceURI===e)??null:null}function p(){if(o||t.length===0)return;o=!0;const w=t.shift(),c=new SpeechSynthesisUtterance(w),a=b();a&&(c.voice=a),c.rate=s,c.pitch=n,c.onstart=()=>{i||(i=!0,r==null||r())},c.onend=()=>{o=!1,p()},c.onerror=u=>{console.error("[WebSpeech TTS] error",u.error),o=!1,p()},speechSynthesis.speak(c)}return{enqueue(w){w!=null&&w.trim()&&(t.push(w),p())},cancel(){t.length=0,speechSynthesis.cancel(),o=!1,i=!1},async finished(){for(;o||t.length>0;)await new Promise(w=>setTimeout(w,100))}}}async function ze({onSpeechStart:e,onSpeechEnd:s,onError:n,deviceId:r}){try{const{MicVAD:t}=window.vad;return await t.new({model:"legacy",baseAssetPath:"/vendor/vad/",onnxWASMBasePath:"/vendor/ort/",additionalAudioConstraints:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!1,...r?{deviceId:{exact:r}}:{}},onSpeechStart:()=>e==null?void 0:e(),onSpeechEnd:i=>{console.log("[VAD] onSpeechEnd — samples:",i==null?void 0:i.length),s==null||s(i)},onVADMisfire:()=>{},negativeSpeechThreshold:.25,positiveSpeechThreshold:.5,redemptionFrames:4,minSpeechFrames:3,preSpeechPadFrames:1})}catch(t){throw n==null||n("VAD initialization failed. Falling back to manual microphone capture."),t}}const y={IDLE:"idle",LISTENING:"listening",TRANSCRIBING:"transcribing",THINKING:"thinking",SPEAKING:"speaking"},Ee="You are a friendly assistant for quick voice interactions. Provide answers only in the form of a single concise sentence, without any introductory phrases. Don't use any formatting, markdown, emoji, or code blocks — just plain text. The answers will be spoken aloud, so keep them short and natural.";function Me({processInput:e,systemPrompt:s=Ee,ttsProvider:n="server-kokoro",ttsVoice:r="af_bella",ttsServerUrl:t="/api/tts",ttsSpeechRate:o=1,ttsSpeechPitch:i=1,whisperModel:b="onnx-community/whisper-tiny.en",whisperDtype:p="q8",whisperDevice:w="cpu",kokoroDtype:c="q8",kokoroBrowserDevice:a="wasm",modelProxyUrl:u="/api/models/"}={}){const[S,d]=m.useState(y.IDLE),[j,R]=m.useState(!0),[B,k]=m.useState({whisper:0,kokoro:0}),[$,N]=m.useState(null),[Z,ee]=m.useState([]),[te,_]=m.useState(null),[V,z]=m.useState(!1),[F,v]=m.useState(""),[E,U]=m.useState([]),[ne,H]=m.useState(null),O=m.useRef(y.IDLE),W=m.useRef(!1),I=m.useRef(null),D=m.useRef(null),q=m.useRef(null),M=m.useRef(null),C=m.useRef(null),se=m.useRef(null),J=m.useRef([{role:"system",content:s}]),re=m.useRef(e);m.useEffect(()=>{O.current=S},[S]),m.useEffect(()=>{W.current=V},[V]),m.useEffect(()=>{re.current=e},[e]),m.useEffect(()=>{async function g(){try{const x=await navigator.mediaDevices.enumerateDevices();U(x.filter(l=>l.kind==="audioinput"))}catch{}}return g(),navigator.mediaDevices.addEventListener("devicechange",g),()=>navigator.mediaDevices.removeEventListener("devicechange",g)},[V]),m.useEffect(()=>{let g=!1;async function x(){try{const l=()=>{var f;n==="webspeech"&&((f=D.current)==null||f.pause())};if(n==="webspeech")I.current=_e({voice:r,rate:o,pitch:i,onPlayStart:l}),k(f=>({...f,kokoro:1}));else if(n==="kokoro"){const{kokoro:f}=await Ne((T,G)=>k(K=>({...K,[T]:G})),{dtype:c,device:a,modelProxyUrl:u});if(g)return;I.current=Le(f,{voice:r,onPlayStart:l})}else I.current=Re({voice:r,onPlayStart:l,url:t}),k(f=>({...f,kokoro:1}));if(g)return;M.current=new Worker(new URL("./assets/whisperWorker-BJuP9cl9.js",typeof document>"u"?require("url").pathToFileURL(__filename).href:ie&&ie.tagName.toUpperCase()==="SCRIPT"&&ie.src||new URL("index.cjs",document.baseURI).href),{type:"module"}),M.current.onmessage=f=>{f.data.type==="transcript"?oe(f.data.text):f.data.type==="progress"?k(T=>({...T,whisper:f.data.progress})):f.data.type==="ready"?(k(T=>({...T,whisper:1})),R(!1)):f.data.type==="error"&&(N(`Whisper: ${f.data.message}`),R(!1))},M.current.onerror=()=>{N("Model load failed. Check WebGPU/WASM browser support."),R(!1)},M.current.postMessage({type:"init",model:b,dtype:p,device:w,modelProxyUrl:u})}catch(l){g||(N("Initialisation failed: "+((l==null?void 0:l.message)??String(l))),R(!1))}}return x(),()=>{var l;g=!0,(l=M.current)==null||l.terminate()}},[n,b,p,w,c,a]);function ce(g,x){ee(l=>[...l,{role:g,content:x,time:new Date().toISOString()}])}async function oe(g){if(!(g!=null&&g.trim())){d(W.current?y.LISTENING:y.IDLE);return}d(y.THINKING),ce("user",g);const x=[...J.current,{role:"user",content:g}];J.current=x,await ge(g,x)}async function ge(g,x){var l,f,T,G,K;(l=q.current)==null||l.abort(),q.current=new AbortController,(f=I.current)==null||f.cancel();try{if(!re.current)throw new Error("processInput is not provided");const P=me();let Y="",ae=!1;_("");for await(const le of re.current(g,x,q.current.signal))Y+=le,_(Y),P.write(le).forEach(Se=>{var fe;ae||(ae=!0,d(y.SPEAKING)),(fe=I.current)==null||fe.enqueue(Se)});const ue=P.flush();ue&&(ae||d(y.SPEAKING),(T=I.current)==null||T.enqueue(ue)),ce("assistant",Y),_(null),J.current=[...J.current,{role:"assistant",content:Y}],await((G=I.current)==null?void 0:G.finished()),n==="webspeech"&&((K=D.current)==null||K.start())}catch(P){_(null),P.name!=="AbortError"&&N(P.message||"Processing failed.")}finally{d(W.current?y.LISTENING:y.IDLE)}}async function we(){var g,x;N(null),O.current===y.SPEAKING&&((g=I.current)==null||g.cancel(),(x=q.current)==null||x.abort());try{d(y.LISTENING),z(!0);try{const l=await navigator.mediaDevices.getUserMedia({audio:F?{deviceId:{exact:F}}:!0,video:!1});se.current=l;const f=new AudioContext;C.current=f;const T=f.createAnalyser();T.fftSize=256,f.createMediaStreamSource(l).connect(T),H(T)}catch(l){console.warn("[TZVoiceChat] waveform analyser unavailable:",l)}D.current=await ze({onSpeechStart:()=>{var l,f;n==="webspeech"&&O.current===y.SPEAKING||(O.current===y.SPEAKING&&((l=I.current)==null||l.cancel(),(f=q.current)==null||f.abort()),d(y.LISTENING))},onSpeechEnd:l=>{var f;n==="webspeech"&&O.current===y.SPEAKING||(d(y.TRANSCRIBING),(f=M.current)==null||f.postMessage({type:"transcribe",audio:l},[l.buffer]))},onError:l=>{N(l),d(y.IDLE)},deviceId:F||void 0})}catch(l){console.error("[TZVoiceChat] startListening failed:",l),N("Microphone access failed. Allow audio permissions and refresh."),d(y.IDLE),z(!1)}}function be(){var g,x,l,f,T;z(!1),(g=D.current)==null||g.destroy(),D.current=null,(x=se.current)==null||x.getTracks().forEach(G=>G.stop()),se.current=null,(l=C.current)==null||l.close(),C.current=null,H(null),(f=I.current)==null||f.cancel(),(T=q.current)==null||T.abort(),d(y.IDLE)}function ye(g){var T;if(!(g!=null&&g.trim()))return;d(y.SPEAKING);const x=me(),l=x.write(g),f=x.flush();[...l,...f?[f]:[]].forEach(G=>{var K;return(K=I.current)==null?void 0:K.enqueue(G)}),(T=I.current)==null||T.finished().then(()=>{d(W.current?y.LISTENING:y.IDLE)})}return{status:S,loading:j,progress:B,error:$,transcript:Z,streamingMessage:te,micEnabled:V,startListening:we,stopListening:be,speak:ye,submitText:oe,liveAnalyser:ne,devices:E,selectedMicId:F,setSelectedMicId:v}}function pe(e){const s=e.replace("#",""),n=s.length===3?s.split("").map(r=>r+r).join(""):s;return[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]}function je(e,s,n){e/=255,s/=255,n/=255;const r=Math.max(e,s,n),t=Math.min(e,s,n),o=(r+t)/2;if(r===t)return[0,0,o*100];const i=r-t,b=o>.5?i/(2-r-t):i/(r+t);let p;switch(r){case e:p=((s-n)/i+(s<n?6:0))/6;break;case s:p=((n-e)/i+2)/6;break;default:p=((e-s)/i+4)/6}return[p*360,b*100,o*100]}function $e(e,s,n){s/=100,n/=100;const r=i=>(i+e/30)%12,t=s*Math.min(n,1-n),o=i=>n-t*Math.max(-1,Math.min(r(i)-3,Math.min(9-r(i),1)));return[Math.round(o(0)*255),Math.round(o(8)*255),Math.round(o(4)*255)]}function L(e,s){const[n,r,t]=pe(e),[o,i,b]=je(n,r,t),[p,w,c]=$e(o,i,Math.max(0,Math.min(100,b+s)));return`rgb(${p}, ${w}, ${c})`}function A(e,s){const[n,r,t]=pe(e);return`rgba(${n}, ${r}, ${t}, ${s})`}function Q(e,s){return e.replace("rgb(","rgba(").replace(")",`, ${s})`)}const X=10;function qe({analyser:e}){const s=m.useRef(null),n=m.useRef(null);return m.useEffect(()=>{if(cancelAnimationFrame(n.current),!e)return;const r=s.current;if(!r)return;const t=r.getContext("2d"),o=e.frequencyBinCount,i=new Uint8Array(o),b=Math.max(1,Math.floor(o/X)),p=getComputedStyle(r),w=+p.getPropertyValue("--bar-hue"),c=+p.getPropertyValue("--bar-hue-range"),a=+p.getPropertyValue("--bar-sat"),u=+p.getPropertyValue("--bar-lit"),S=+p.getPropertyValue("--bar-lit-range"),d=()=>{n.current=requestAnimationFrame(d),e.getByteFrequencyData(i);const j=r.width,R=r.height;t.clearRect(0,0,j,R);const B=(j-(X-1)*2)/X;for(let k=0;k<X;k++){const $=i[k*b]/255,N=Math.max(3,$*R*.88);t.fillStyle=`hsl(${w+$*c}, ${a}%, ${u+$*S}%)`,t.beginPath(),t.roundRect(k*(B+2),(R-N)/2,B,N,[2]),t.fill()}};return d(),()=>cancelAnimationFrame(n.current)},[e]),h.jsx("canvas",{ref:s,width:55,height:35,className:"ai-btn__canvas"})}function De({status:e="idle",active:s=!1,loading:n=!1,analyser:r=null,onToggle:t,devices:o=[],selectedMicId:i="",onDeviceChange:b,inputData:p="",sendData:w,accentColor:c="#f97316",uiColor:a="#64748b",size:u=70,barHue:S=25,barHueRange:d=20,barSat:j=88,barLit:R=65,barLitRange:B=20}){var F;const[k,$]=m.useState(!1),N=m.useRef(null);m.useEffect(()=>{if(!k)return;function v(E){var U;(U=N.current)!=null&&U.contains(E.target)||$(!1)}return document.addEventListener("pointerdown",v),()=>document.removeEventListener("pointerdown",v)},[k]);function Z(v){b==null||b(v),$(!1)}const ee=m.useMemo(()=>{const v=L(c,-8),E=L(c,-15),U=L(c,-22),ne=L(c,-30),H=L(c,-42),O=L(c,8),W=L(c,20),I=L(c,30),D=L(a,-22),q=L(a,-30),M=L(a,18),C=L(a,37);return{"--tz-size":`${u}px`,"--tz-a":c,"--tz-a-d8":v,"--tz-a-d15":E,"--tz-a-d22":U,"--tz-a-d30":ne,"--tz-a-d42":H,"--tz-a-l8":O,"--tz-a-l20":W,"--tz-a-l30":I,"--tz-a-25":A(c,.25),"--tz-a-28":A(c,.28),"--tz-a-30":A(c,.3),"--tz-a-32":A(c,.32),"--tz-a-34":A(c,.34),"--tz-a-35":A(c,.35),"--tz-a-38":A(c,.38),"--tz-a-45":A(c,.45),"--tz-a-50":A(c,.5),"--tz-a-55":A(c,.55),"--tz-a-60":A(c,.6),"--tz-a-65":A(c,.65),"--tz-a-68":A(c,.68),"--tz-u":a,"--tz-u-d22":D,"--tz-u-d30":q,"--tz-u-l18":M,"--tz-u-l37":C,"--tz-u-30":A(a,.3),"--tz-u-55":A(a,.55),"--tz-u-d30-a85":Q(q,.85),"--tz-u-l18-a18":Q(M,.18),"--tz-u-l18-a20":Q(M,.2),"--tz-u-l18-a32":Q(M,.32),"--tz-u-d22-a90":Q(D,.9),"--bar-hue":S,"--bar-hue-range":d,"--bar-sat":j,"--bar-lit":R,"--bar-lit-range":B}},[c,a,u,S,d,j,R,B]),te=((F=o.find(v=>v.deviceId===i))==null?void 0:F.label)||(i?`Mic ${i.slice(0,6)}…`:"Default mic"),_=p.trim().length>0,V=_?"ready":s?e:"off";let z;return _?z=h.jsx("svg",{className:"ai-btn__mic",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:h.jsx("path",{d:"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"})}):!s||e==="idle"?z=h.jsxs("svg",{className:"ai-btn__mic",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[h.jsx("path",{fillOpacity:"0.52",d:"M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4zm6 10a1 1 0 0 1 2 0 8 8 0 0 1-7 7.94V21h2a1 1 0 0 1 0 2H9a1 1 0 0 1 0-2h2v-2.06A8 8 0 0 1 4 11a1 1 0 0 1 2 0 6 6 0 0 0 12 0z"}),h.jsx("path",{fill:"white",fillOpacity:"0.98",d:"M14.5 0L15.65 3.45L19.1 4.6L15.65 5.75L14.5 9.2L13.35 5.75L9.9 4.6L13.35 3.45Z"}),h.jsx("path",{fill:"white",fillOpacity:"0.88",d:"M19 8.62L19.75 10.75L21.88 11.5L19.75 12.25L19 14.38L18.25 12.25L16.12 11.5L18.25 10.75Z"})]}):e==="listening"?z=h.jsx(qe,{analyser:r}):e==="transcribing"?z=h.jsx("div",{className:"ai-btn__bars ai-btn__bars--transcribing",children:Array.from({length:7},(v,E)=>h.jsx("span",{style:{animationDelay:`${E*.1}s`}},E))}):e==="thinking"?z=h.jsxs("div",{className:"ai-btn__dots",children:[h.jsx("span",{}),h.jsx("span",{style:{animationDelay:"0.18s"}}),h.jsx("span",{style:{animationDelay:"0.36s"}})]}):e==="speaking"&&(z=h.jsx("div",{className:"ai-btn__bars ai-btn__bars--speaking",children:Array.from({length:7},(v,E)=>h.jsx("span",{style:{animationDelay:`${E*.11}s`}},E))})),h.jsxs("div",{className:"ai-btn-root",style:ee,children:[h.jsxs("div",{className:`ai-btn-rings ai-btn-rings--${V}`,"aria-hidden":"true",children:[h.jsx("span",{className:"ai-ring ai-ring--1"}),h.jsx("span",{className:"ai-ring ai-ring--2"})]}),h.jsxs("button",{className:`ai-btn ai-btn--${V}`,disabled:n,onClick:_?()=>w==null?void 0:w(p):t,"aria-label":_?"Send message":s?"Stop assistant":"Start assistant","aria-pressed":_?void 0:s,children:[z,s&&!_&&h.jsx("span",{className:"ai-btn__hover-stop","aria-hidden":"true",children:"■"})]}),h.jsxs("div",{className:`ai-mic-sel${k?" open":""}`,ref:N,children:[h.jsxs("button",{className:"ai-mic-sel__trigger",onClick:()=>$(v=>!v),title:"Change microphone","aria-label":"Change microphone","aria-expanded":k,children:[h.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[h.jsx("path",{d:"M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4z"}),h.jsx("path",{d:"M5 11a1 1 0 0 0-2 0 9 9 0 0 0 8 8.94V22H9a1 1 0 0 0 0 2h6a1 1 0 0 0 0-2h-2v-2.06A9 9 0 0 0 21 11a1 1 0 0 0-2 0 7 7 0 0 1-14 0z"})]}),h.jsx("span",{className:"ai-mic-sel__label",children:te}),h.jsx("svg",{className:`ai-mic-sel__caret${k?" open":""}`,width:"9",height:"9",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:h.jsx("path",{d:"M12 16L4 8h16l-8 8z"})})]}),k&&h.jsxs("ul",{className:"ai-mic-sel__menu",role:"listbox","aria-label":"Select microphone",children:[h.jsx("li",{role:"option",className:`ai-mic-sel__option${i===""?" selected":""}`,onClick:()=>Z(""),"aria-selected":i==="",children:"Default microphone"}),o.map(v=>h.jsx("li",{role:"option",className:`ai-mic-sel__option${i===v.deviceId?" selected":""}`,onClick:()=>Z(v.deviceId),"aria-selected":i===v.deviceId,children:v.label||`Microphone ${v.deviceId.slice(0,8)}`},v.deviceId))]})]})]})}exports.AIAssistantButton=De;exports.STATES=y;exports.TZVoiceChat=Me;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { useState as L, useRef as _, useEffect as U, useMemo as ke } from "react";
2
- import { jsx as v, jsxs as V } from "react/jsx-runtime";
3
- function he() {
1
+ import { useState as x, useRef as L, useEffect as Q, useMemo as Se } from "react";
2
+ import { jsx as w, jsxs as q } from "react/jsx-runtime";
3
+ function me() {
4
4
  let e = "";
5
5
  function s() {
6
6
  const t = [];
@@ -42,7 +42,7 @@ function he() {
42
42
  }
43
43
  };
44
44
  }
45
- async function Se(e, {
45
+ async function ke(e, {
46
46
  dtype: s = "q8",
47
47
  device: t = "cpu",
48
48
  modelProxyUrl: r = "/api/models/"
@@ -59,57 +59,57 @@ async function Se(e, {
59
59
  ), { KokoroTTS: i } = o;
60
60
  let g = s;
61
61
  t === "webgpu" && (s === "q4" || s === "q8") && (console.warn(`[modelLoader] dtype "${s}" not supported on WebGPU — using "fp32".`), g = "fp32");
62
- let a = 0;
63
- const h = (d) => {
64
- typeof (d == null ? void 0 : d.progress) == "number" && (a = Math.max(a, d.progress / 100), e == null || e("kokoro", Math.min(0.99, a)));
62
+ let h = 0;
63
+ const p = (d) => {
64
+ typeof (d == null ? void 0 : d.progress) == "number" && (h = Math.max(h, d.progress / 100), e == null || e("kokoro", Math.min(0.99, h)));
65
65
  };
66
- async function p(d, R) {
66
+ async function c(d, D) {
67
67
  return i.from_pretrained("onnx-community/Kokoro-82M-ONNX", {
68
- dtype: R,
68
+ dtype: D,
69
69
  device: d,
70
- progress_callback: h
70
+ progress_callback: p
71
71
  });
72
72
  }
73
- let c;
73
+ let a;
74
74
  try {
75
- c = await p(t, g);
75
+ a = await c(t, g);
76
76
  } catch (d) {
77
77
  if (t !== "wasm")
78
- console.warn(`[modelLoader] Kokoro on "${t}" failed (${d == null ? void 0 : d.message}) — falling back to WASM.`), a = 0, c = await p("wasm", s);
78
+ console.warn(`[modelLoader] Kokoro on "${t}" failed (${d == null ? void 0 : d.message}) — falling back to WASM.`), h = 0, a = await c("wasm", s);
79
79
  else
80
80
  throw d;
81
81
  }
82
- return e == null || e("kokoro", 1), { kokoro: c };
82
+ return e == null || e("kokoro", 1), { kokoro: a };
83
83
  }
84
84
  function Ae(e, { voice: s = "af_bella", onPlayStart: t } = {}) {
85
85
  const r = new AudioContext(), n = [];
86
86
  let o = !1, i = null, g = !1;
87
- async function a(c) {
88
- if (c instanceof AudioBuffer) return c;
89
- const l = (c == null ? void 0 : c.audio) ?? c;
87
+ async function h(a) {
88
+ if (a instanceof AudioBuffer) return a;
89
+ const l = (a == null ? void 0 : a.audio) ?? a;
90
90
  if (l instanceof ArrayBuffer) return await r.decodeAudioData(l.slice(0));
91
91
  if (l instanceof Float32Array) {
92
- const b = (c == null ? void 0 : c.samplingRate) ?? 24e3, d = r.createBuffer(1, l.length, b);
92
+ const b = (a == null ? void 0 : a.samplingRate) ?? 24e3, d = r.createBuffer(1, l.length, b);
93
93
  return d.copyToChannel(l, 0), d;
94
94
  }
95
95
  throw new Error("Unsupported TTS payload");
96
96
  }
97
- async function h(c) {
97
+ async function p(a) {
98
98
  await r.resume();
99
99
  const l = r.createBufferSource();
100
- return l.buffer = c, l.connect(r.destination), new Promise((b) => {
100
+ return l.buffer = a, l.connect(r.destination), new Promise((b) => {
101
101
  l.onended = () => {
102
102
  i === l && (i = null), b();
103
103
  }, i = l, l.start(), g || (g = !0, t == null || t());
104
104
  });
105
105
  }
106
- async function p() {
106
+ async function c() {
107
107
  if (!o) {
108
108
  for (o = !0; n.length > 0; ) {
109
- const c = n.shift();
109
+ const a = n.shift();
110
110
  try {
111
- const l = await c;
112
- l && await h(l);
111
+ const l = await a;
112
+ l && await p(l);
113
113
  } catch (l) {
114
114
  console.error("[TtsQueue]", l);
115
115
  }
@@ -118,8 +118,8 @@ function Ae(e, { voice: s = "af_bella", onPlayStart: t } = {}) {
118
118
  }
119
119
  }
120
120
  return {
121
- enqueue(c) {
122
- n.push(e.generate(c, { voice: s }).then(a)), p();
121
+ enqueue(a) {
122
+ n.push(e.generate(a, { voice: s }).then(h)), c();
123
123
  },
124
124
  cancel() {
125
125
  if (n.length = 0, i) {
@@ -131,15 +131,15 @@ function Ae(e, { voice: s = "af_bella", onPlayStart: t } = {}) {
131
131
  }
132
132
  },
133
133
  async finished() {
134
- for (; o || n.length > 0; ) await new Promise((c) => setTimeout(c, 200));
134
+ for (; o || n.length > 0; ) await new Promise((a) => setTimeout(a, 200));
135
135
  }
136
136
  };
137
137
  }
138
138
  function Ie({ voice: e = "", onPlayStart: s, url: t = "/api/tts" } = {}) {
139
139
  const r = new AudioContext(), n = [];
140
140
  let o = !1, i = null, g = !1;
141
- async function a(c) {
142
- const l = { text: c };
141
+ async function h(a) {
142
+ const l = { text: a };
143
143
  e && (l.voice = e);
144
144
  const b = await fetch(t, {
145
145
  method: "POST",
@@ -149,21 +149,21 @@ function Ie({ voice: e = "", onPlayStart: s, url: t = "/api/tts" } = {}) {
149
149
  if (!b.ok) throw new Error(`TTS ${b.status}: ${await b.text()}`);
150
150
  return r.decodeAudioData(await b.arrayBuffer());
151
151
  }
152
- async function h(c) {
152
+ async function p(a) {
153
153
  await r.resume();
154
154
  const l = r.createBufferSource();
155
- return l.buffer = c, l.connect(r.destination), new Promise((b) => {
155
+ return l.buffer = a, l.connect(r.destination), new Promise((b) => {
156
156
  l.onended = () => {
157
157
  i === l && (i = null), b();
158
158
  }, i = l, l.start(), g || (g = !0, s == null || s());
159
159
  });
160
160
  }
161
- async function p() {
161
+ async function c() {
162
162
  if (!o) {
163
163
  for (o = !0; n.length > 0; ) {
164
- const c = n.shift();
164
+ const a = n.shift();
165
165
  try {
166
- await h(await c);
166
+ await p(await a);
167
167
  } catch (l) {
168
168
  console.error("[ServerTTS]", l);
169
169
  }
@@ -172,8 +172,8 @@ function Ie({ voice: e = "", onPlayStart: s, url: t = "/api/tts" } = {}) {
172
172
  }
173
173
  }
174
174
  return {
175
- enqueue(c) {
176
- c != null && c.trim() && (n.push(a(c)), p());
175
+ enqueue(a) {
176
+ a != null && a.trim() && (n.push(h(a)), c());
177
177
  },
178
178
  cancel() {
179
179
  if (n.length = 0, i) {
@@ -186,7 +186,7 @@ function Ie({ voice: e = "", onPlayStart: s, url: t = "/api/tts" } = {}) {
186
186
  g = !1;
187
187
  },
188
188
  async finished() {
189
- for (; o || n.length > 0; ) await new Promise((c) => setTimeout(c, 100));
189
+ for (; o || n.length > 0; ) await new Promise((a) => setTimeout(a, 100));
190
190
  }
191
191
  };
192
192
  }
@@ -194,29 +194,29 @@ function Ne({ voice: e = "", rate: s = 1, pitch: t = 1, onPlayStart: r } = {}) {
194
194
  const n = [];
195
195
  let o = !1, i = !1;
196
196
  function g() {
197
- return e ? speechSynthesis.getVoices().find((p) => p.name === e || p.voiceURI === e) ?? null : null;
197
+ return e ? speechSynthesis.getVoices().find((c) => c.name === e || c.voiceURI === e) ?? null : null;
198
198
  }
199
- function a() {
199
+ function h() {
200
200
  if (o || n.length === 0) return;
201
201
  o = !0;
202
- const h = n.shift(), p = new SpeechSynthesisUtterance(h), c = g();
203
- c && (p.voice = c), p.rate = s, p.pitch = t, p.onstart = () => {
202
+ const p = n.shift(), c = new SpeechSynthesisUtterance(p), a = g();
203
+ a && (c.voice = a), c.rate = s, c.pitch = t, c.onstart = () => {
204
204
  i || (i = !0, r == null || r());
205
- }, p.onend = () => {
206
- o = !1, a();
207
- }, p.onerror = (l) => {
208
- console.error("[WebSpeech TTS] error", l.error), o = !1, a();
209
- }, speechSynthesis.speak(p);
205
+ }, c.onend = () => {
206
+ o = !1, h();
207
+ }, c.onerror = (l) => {
208
+ console.error("[WebSpeech TTS] error", l.error), o = !1, h();
209
+ }, speechSynthesis.speak(c);
210
210
  }
211
211
  return {
212
- enqueue(h) {
213
- h != null && h.trim() && (n.push(h), a());
212
+ enqueue(p) {
213
+ p != null && p.trim() && (n.push(p), h());
214
214
  },
215
215
  cancel() {
216
216
  n.length = 0, speechSynthesis.cancel(), o = !1, i = !1;
217
217
  },
218
218
  async finished() {
219
- for (; o || n.length > 0; ) await new Promise((h) => setTimeout(h, 100));
219
+ for (; o || n.length > 0; ) await new Promise((p) => setTimeout(p, 100));
220
220
  }
221
221
  };
222
222
  }
@@ -255,207 +255,209 @@ const y = {
255
255
  TRANSCRIBING: "transcribing",
256
256
  THINKING: "thinking",
257
257
  SPEAKING: "speaking"
258
- }, ze = "You are a friendly assistant for quick voice interactions. Provide answers only in the form of a single concise sentence, without any introductory phrases. Don't use any formatting, markdown, emoji, or code blocks — just plain text. The answers will be spoken aloud, so keep them short and natural.";
258
+ }, Le = "You are a friendly assistant for quick voice interactions. Provide answers only in the form of a single concise sentence, without any introductory phrases. Don't use any formatting, markdown, emoji, or code blocks — just plain text. The answers will be spoken aloud, so keep them short and natural.";
259
259
  function xe({
260
260
  processInput: e,
261
- systemPrompt: s = ze,
261
+ systemPrompt: s = Le,
262
262
  ttsProvider: t = "server-kokoro",
263
263
  ttsVoice: r = "af_bella",
264
264
  ttsServerUrl: n = "/api/tts",
265
265
  ttsSpeechRate: o = 1,
266
266
  ttsSpeechPitch: i = 1,
267
267
  whisperModel: g = "onnx-community/whisper-tiny.en",
268
- whisperDtype: a = "q8",
269
- whisperDevice: h = "cpu",
270
- kokoroDtype: p = "q8",
271
- kokoroBrowserDevice: c = "wasm",
268
+ whisperDtype: h = "q8",
269
+ whisperDevice: p = "cpu",
270
+ kokoroDtype: c = "q8",
271
+ kokoroBrowserDevice: a = "wasm",
272
272
  modelProxyUrl: l = "/api/models/"
273
273
  } = {}) {
274
- const [b, d] = L(y.IDLE), [R, I] = L(!0), [x, T] = L({ whisper: 0, kokoro: 0 }), [D, M] = L(null), [ee, Z] = L([]), [G, F] = L(null), [w, z] = L(!1), [$, ne] = L(""), [te, re] = L([]), [ae, C] = L(null), q = _(y.IDLE), K = _(!1), A = _(null), W = _(null), j = _(null), Q = _(null), se = _(null), ie = _(null), J = _([{ role: "system", content: s }]), ce = _(e);
275
- U(() => {
276
- q.current = b;
277
- }, [b]), U(() => {
278
- K.current = w;
279
- }, [w]), U(() => {
274
+ const [b, d] = x(y.IDLE), [D, M] = x(!0), [K, A] = x({ whisper: 0, kokoro: 0 }), [G, T] = x(null), [Y, re] = x([]), [ae, _] = x(null), [O, E] = x(!1), [W, v] = x(""), [R, P] = x([]), [se, X] = x(null), U = L(y.IDLE), Z = L(!1), N = L(null), V = L(null), B = L(null), $ = L(null), H = L(null), ie = L(null), ee = L([{ role: "system", content: s }]), ce = L(e);
275
+ Q(() => {
276
+ U.current = b;
277
+ }, [b]), Q(() => {
278
+ Z.current = O;
279
+ }, [O]), Q(() => {
280
280
  ce.current = e;
281
- }, [e]), U(() => {
281
+ }, [e]), Q(() => {
282
282
  async function m() {
283
283
  try {
284
- const k = await navigator.mediaDevices.enumerateDevices();
285
- re(k.filter((u) => u.kind === "audioinput"));
284
+ const S = await navigator.mediaDevices.enumerateDevices();
285
+ P(S.filter((u) => u.kind === "audioinput"));
286
286
  } catch {
287
287
  }
288
288
  }
289
289
  return m(), navigator.mediaDevices.addEventListener("devicechange", m), () => navigator.mediaDevices.removeEventListener("devicechange", m);
290
- }, [w]), U(() => {
290
+ }, [O]), Q(() => {
291
291
  let m = !1;
292
- async function k() {
292
+ async function S() {
293
293
  try {
294
294
  const u = () => {
295
295
  var f;
296
- t === "webspeech" && ((f = W.current) == null || f.pause());
296
+ t === "webspeech" && ((f = V.current) == null || f.pause());
297
297
  };
298
298
  if (t === "webspeech")
299
- A.current = Ne({
299
+ N.current = Ne({
300
300
  voice: r,
301
301
  rate: o,
302
302
  pitch: i,
303
303
  onPlayStart: u
304
- }), T((f) => ({ ...f, kokoro: 1 }));
304
+ }), A((f) => ({ ...f, kokoro: 1 }));
305
305
  else if (t === "kokoro") {
306
- const { kokoro: f } = await Se(
307
- (S, B) => T((O) => ({ ...O, [S]: B })),
308
- { dtype: p, device: c, modelProxyUrl: l }
306
+ const { kokoro: f } = await ke(
307
+ (k, F) => A((j) => ({ ...j, [k]: F })),
308
+ { dtype: c, device: a, modelProxyUrl: l }
309
309
  );
310
310
  if (m) return;
311
- A.current = Ae(f, { voice: r, onPlayStart: u });
311
+ N.current = Ae(f, { voice: r, onPlayStart: u });
312
312
  } else
313
- A.current = Ie({ voice: r, onPlayStart: u, url: n }), T((f) => ({ ...f, kokoro: 1 }));
313
+ N.current = Ie({ voice: r, onPlayStart: u, url: n }), A((f) => ({ ...f, kokoro: 1 }));
314
314
  if (m) return;
315
- Q.current = new Worker(
315
+ $.current = new Worker(
316
316
  new URL(
317
317
  /* @vite-ignore */
318
- "/assets/whisperWorker-BJuP9cl9.js",
318
+ "./assets/whisperWorker-BJuP9cl9.js",
319
319
  import.meta.url
320
320
  ),
321
321
  { type: "module" }
322
- ), Q.current.onmessage = (f) => {
323
- f.data.type === "transcript" ? pe(f.data.text) : f.data.type === "progress" ? T((S) => ({ ...S, whisper: f.data.progress })) : f.data.type === "ready" ? (T((S) => ({ ...S, whisper: 1 })), I(!1)) : f.data.type === "error" && (M(`Whisper: ${f.data.message}`), I(!1));
324
- }, Q.current.onerror = () => {
325
- M("Model load failed. Check WebGPU/WASM browser support."), I(!1);
326
- }, Q.current.postMessage({
322
+ ), $.current.onmessage = (f) => {
323
+ f.data.type === "transcript" ? ue(f.data.text) : f.data.type === "progress" ? A((k) => ({ ...k, whisper: f.data.progress })) : f.data.type === "ready" ? (A((k) => ({ ...k, whisper: 1 })), M(!1)) : f.data.type === "error" && (T(`Whisper: ${f.data.message}`), M(!1));
324
+ }, $.current.onerror = () => {
325
+ T("Model load failed. Check WebGPU/WASM browser support."), M(!1);
326
+ }, $.current.postMessage({
327
327
  type: "init",
328
328
  model: g,
329
- dtype: a,
330
- device: h,
329
+ dtype: h,
330
+ device: p,
331
331
  modelProxyUrl: l
332
332
  });
333
333
  } catch (u) {
334
- m || (M("Initialisation failed: " + ((u == null ? void 0 : u.message) ?? String(u))), I(!1));
334
+ m || (T("Initialisation failed: " + ((u == null ? void 0 : u.message) ?? String(u))), M(!1));
335
335
  }
336
336
  }
337
- return k(), () => {
337
+ return S(), () => {
338
338
  var u;
339
- m = !0, (u = Q.current) == null || u.terminate();
339
+ m = !0, (u = $.current) == null || u.terminate();
340
340
  };
341
- }, [t, g, a, h, p, c]);
342
- function le(m, k) {
343
- Z((u) => [...u, { role: m, content: k, time: (/* @__PURE__ */ new Date()).toISOString() }]);
341
+ }, [t, g, h, p, c, a]);
342
+ function le(m, S) {
343
+ re((u) => [...u, { role: m, content: S, time: (/* @__PURE__ */ new Date()).toISOString() }]);
344
344
  }
345
- async function pe(m) {
345
+ async function ue(m) {
346
346
  if (!(m != null && m.trim())) {
347
- d(K.current ? y.LISTENING : y.IDLE);
347
+ d(Z.current ? y.LISTENING : y.IDLE);
348
348
  return;
349
349
  }
350
350
  d(y.THINKING), le("user", m);
351
- const k = [...J.current, { role: "user", content: m }];
352
- J.current = k, await ge(m, k);
351
+ const S = [...ee.current, { role: "user", content: m }];
352
+ ee.current = S, await ge(m, S);
353
353
  }
354
- async function ge(m, k) {
355
- var u, f, S, B, O;
356
- (u = j.current) == null || u.abort(), j.current = new AbortController(), (f = A.current) == null || f.cancel();
354
+ async function ge(m, S) {
355
+ var u, f, k, F, j;
356
+ (u = B.current) == null || u.abort(), B.current = new AbortController(), (f = N.current) == null || f.cancel();
357
357
  try {
358
358
  if (!ce.current) throw new Error("processInput is not provided");
359
- const P = he();
360
- let Y = "", oe = !1;
361
- F("");
362
- for await (const fe of ce.current(m, k, j.current.signal))
363
- Y += fe, F(Y), P.write(fe).forEach((ve) => {
364
- var de;
365
- oe || (oe = !0, d(y.SPEAKING)), (de = A.current) == null || de.enqueue(ve);
359
+ const C = me();
360
+ let ne = "", oe = !1;
361
+ _("");
362
+ for await (const de of ce.current(m, S, B.current.signal))
363
+ ne += de, _(ne), C.write(de).forEach((ve) => {
364
+ var he;
365
+ oe || (oe = !0, d(y.SPEAKING)), (he = N.current) == null || he.enqueue(ve);
366
366
  });
367
- const ue = P.flush();
368
- ue && (oe || d(y.SPEAKING), (S = A.current) == null || S.enqueue(ue)), le("assistant", Y), F(null), J.current = [...J.current, { role: "assistant", content: Y }], await ((B = A.current) == null ? void 0 : B.finished()), t === "webspeech" && ((O = W.current) == null || O.start());
369
- } catch (P) {
370
- F(null), P.name !== "AbortError" && M(P.message || "Processing failed.");
367
+ const fe = C.flush();
368
+ fe && (oe || d(y.SPEAKING), (k = N.current) == null || k.enqueue(fe)), le("assistant", ne), _(null), ee.current = [...ee.current, { role: "assistant", content: ne }], await ((F = N.current) == null ? void 0 : F.finished()), t === "webspeech" && ((j = V.current) == null || j.start());
369
+ } catch (C) {
370
+ _(null), C.name !== "AbortError" && T(C.message || "Processing failed.");
371
371
  } finally {
372
- d(K.current ? y.LISTENING : y.IDLE);
372
+ d(Z.current ? y.LISTENING : y.IDLE);
373
373
  }
374
374
  }
375
375
  async function we() {
376
- var m, k;
377
- M(null), q.current === y.SPEAKING && ((m = A.current) == null || m.cancel(), (k = j.current) == null || k.abort());
376
+ var m, S;
377
+ T(null), U.current === y.SPEAKING && ((m = N.current) == null || m.cancel(), (S = B.current) == null || S.abort());
378
378
  try {
379
- d(y.LISTENING), z(!0);
379
+ d(y.LISTENING), E(!0);
380
380
  try {
381
381
  const u = await navigator.mediaDevices.getUserMedia({
382
- audio: $ ? { deviceId: { exact: $ } } : !0,
382
+ audio: W ? { deviceId: { exact: W } } : !0,
383
383
  video: !1
384
384
  });
385
385
  ie.current = u;
386
386
  const f = new AudioContext();
387
- se.current = f;
388
- const S = f.createAnalyser();
389
- S.fftSize = 256, f.createMediaStreamSource(u).connect(S), C(S);
387
+ H.current = f;
388
+ const k = f.createAnalyser();
389
+ k.fftSize = 256, f.createMediaStreamSource(u).connect(k), X(k);
390
390
  } catch (u) {
391
391
  console.warn("[TZVoiceChat] waveform analyser unavailable:", u);
392
392
  }
393
- W.current = await Te({
393
+ V.current = await Te({
394
394
  onSpeechStart: () => {
395
395
  var u, f;
396
- t === "webspeech" && q.current === y.SPEAKING || (q.current === y.SPEAKING && ((u = A.current) == null || u.cancel(), (f = j.current) == null || f.abort()), d(y.LISTENING));
396
+ t === "webspeech" && U.current === y.SPEAKING || (U.current === y.SPEAKING && ((u = N.current) == null || u.cancel(), (f = B.current) == null || f.abort()), d(y.LISTENING));
397
397
  },
398
398
  onSpeechEnd: (u) => {
399
399
  var f;
400
- t === "webspeech" && q.current === y.SPEAKING || (d(y.TRANSCRIBING), (f = Q.current) == null || f.postMessage({ type: "transcribe", audio: u }, [u.buffer]));
400
+ t === "webspeech" && U.current === y.SPEAKING || (d(y.TRANSCRIBING), (f = $.current) == null || f.postMessage({ type: "transcribe", audio: u }, [u.buffer]));
401
401
  },
402
402
  onError: (u) => {
403
- M(u), d(y.IDLE);
403
+ T(u), d(y.IDLE);
404
404
  },
405
- deviceId: $ || void 0
405
+ deviceId: W || void 0
406
406
  });
407
407
  } catch (u) {
408
- console.error("[TZVoiceChat] startListening failed:", u), M("Microphone access failed. Allow audio permissions and refresh."), d(y.IDLE), z(!1);
408
+ console.error("[TZVoiceChat] startListening failed:", u), T("Microphone access failed. Allow audio permissions and refresh."), d(y.IDLE), E(!1);
409
409
  }
410
410
  }
411
411
  function be() {
412
- var m, k, u, f, S;
413
- z(!1), (m = W.current) == null || m.destroy(), W.current = null, (k = ie.current) == null || k.getTracks().forEach((B) => B.stop()), ie.current = null, (u = se.current) == null || u.close(), se.current = null, C(null), (f = A.current) == null || f.cancel(), (S = j.current) == null || S.abort(), d(y.IDLE);
412
+ var m, S, u, f, k;
413
+ E(!1), (m = V.current) == null || m.destroy(), V.current = null, (S = ie.current) == null || S.getTracks().forEach((F) => F.stop()), ie.current = null, (u = H.current) == null || u.close(), H.current = null, X(null), (f = N.current) == null || f.cancel(), (k = B.current) == null || k.abort(), d(y.IDLE);
414
414
  }
415
415
  function ye(m) {
416
- var S;
416
+ var k;
417
417
  if (!(m != null && m.trim())) return;
418
418
  d(y.SPEAKING);
419
- const k = he(), u = k.write(m), f = k.flush();
420
- [...u, ...f ? [f] : []].forEach((B) => {
421
- var O;
422
- return (O = A.current) == null ? void 0 : O.enqueue(B);
423
- }), (S = A.current) == null || S.finished().then(() => {
424
- d(K.current ? y.LISTENING : y.IDLE);
419
+ const S = me(), u = S.write(m), f = S.flush();
420
+ [...u, ...f ? [f] : []].forEach((F) => {
421
+ var j;
422
+ return (j = N.current) == null ? void 0 : j.enqueue(F);
423
+ }), (k = N.current) == null || k.finished().then(() => {
424
+ d(Z.current ? y.LISTENING : y.IDLE);
425
425
  });
426
426
  }
427
427
  return {
428
428
  /** Current pipeline state: 'idle' | 'listening' | 'transcribing' | 'thinking' | 'speaking' */
429
429
  status: b,
430
430
  /** True while models (Whisper + TTS) are still loading. */
431
- loading: R,
431
+ loading: D,
432
432
  /** Per-model load progress: { whisper: 0–1, kokoro: 0–1 } */
433
- progress: x,
433
+ progress: K,
434
434
  /** Last error string, or null. Cleared on startListening(). */
435
- error: D,
435
+ error: G,
436
436
  /** Completed conversation turns: [{ role, content, time }] */
437
- transcript: ee,
437
+ transcript: Y,
438
438
  /** Partial assistant response being streamed, or null. */
439
- streamingMessage: G,
439
+ streamingMessage: ae,
440
440
  /** Whether the microphone is currently open. */
441
- micEnabled: w,
441
+ micEnabled: O,
442
442
  /** Open the microphone and start the VAD → STT → AI → TTS pipeline. */
443
443
  startListening: we,
444
444
  /** Close the microphone and cancel any in-progress pipeline. */
445
445
  stopListening: be,
446
446
  /** Directly synthesise and play text via the configured TTS provider. */
447
447
  speak: ye,
448
+ /** Submit text as a user message, triggering the full AI → TTS pipeline (same as voice transcription). */
449
+ submitText: ue,
448
450
  /** AnalyserNode for real-time waveform rendering, or null when mic is off. */
449
- liveAnalyser: ae,
451
+ liveAnalyser: se,
450
452
  /** Available audio input devices (updated on permission grant). */
451
- devices: te,
453
+ devices: R,
452
454
  /** Currently selected device ID ('': system default). */
453
- selectedMicId: $,
455
+ selectedMicId: W,
454
456
  /** Select an audio input device by its deviceId. */
455
- setSelectedMicId: ne
457
+ setSelectedMicId: v
456
458
  };
457
459
  }
458
- function me(e) {
460
+ function pe(e) {
459
461
  const s = e.replace("#", ""), t = s.length === 3 ? s.split("").map((r) => r + r).join("") : s;
460
462
  return [
461
463
  parseInt(t.slice(0, 2), 16),
@@ -463,59 +465,59 @@ function me(e) {
463
465
  parseInt(t.slice(4, 6), 16)
464
466
  ];
465
467
  }
466
- function _e(e, s, t) {
468
+ function ze(e, s, t) {
467
469
  e /= 255, s /= 255, t /= 255;
468
470
  const r = Math.max(e, s, t), n = Math.min(e, s, t), o = (r + n) / 2;
469
471
  if (r === n) return [0, 0, o * 100];
470
472
  const i = r - n, g = o > 0.5 ? i / (2 - r - n) : i / (r + n);
471
- let a;
473
+ let h;
472
474
  switch (r) {
473
475
  case e:
474
- a = ((s - t) / i + (s < t ? 6 : 0)) / 6;
476
+ h = ((s - t) / i + (s < t ? 6 : 0)) / 6;
475
477
  break;
476
478
  case s:
477
- a = ((t - e) / i + 2) / 6;
479
+ h = ((t - e) / i + 2) / 6;
478
480
  break;
479
481
  default:
480
- a = ((e - s) / i + 4) / 6;
482
+ h = ((e - s) / i + 4) / 6;
481
483
  }
482
- return [a * 360, g * 100, o * 100];
484
+ return [h * 360, g * 100, o * 100];
483
485
  }
484
486
  function Me(e, s, t) {
485
487
  s /= 100, t /= 100;
486
488
  const r = (i) => (i + e / 30) % 12, n = s * Math.min(t, 1 - t), o = (i) => t - n * Math.max(-1, Math.min(r(i) - 3, Math.min(9 - r(i), 1)));
487
489
  return [Math.round(o(0) * 255), Math.round(o(8) * 255), Math.round(o(4) * 255)];
488
490
  }
489
- function E(e, s) {
490
- const [t, r, n] = me(e), [o, i, g] = _e(t, r, n), [a, h, p] = Me(o, i, Math.max(0, Math.min(100, g + s)));
491
- return `rgb(${a}, ${h}, ${p})`;
491
+ function z(e, s) {
492
+ const [t, r, n] = pe(e), [o, i, g] = ze(t, r, n), [h, p, c] = Me(o, i, Math.max(0, Math.min(100, g + s)));
493
+ return `rgb(${h}, ${p}, ${c})`;
492
494
  }
493
- function N(e, s) {
494
- const [t, r, n] = me(e);
495
+ function I(e, s) {
496
+ const [t, r, n] = pe(e);
495
497
  return `rgba(${t}, ${r}, ${n}, ${s})`;
496
498
  }
497
- function H(e, s) {
499
+ function J(e, s) {
498
500
  return e.replace("rgb(", "rgba(").replace(")", `, ${s})`);
499
501
  }
500
- const X = 10;
501
- function Ee({ analyser: e }) {
502
- const s = _(null), t = _(null);
503
- return U(() => {
502
+ const te = 10;
503
+ function _e({ analyser: e }) {
504
+ const s = L(null), t = L(null);
505
+ return Q(() => {
504
506
  if (cancelAnimationFrame(t.current), !e) return;
505
507
  const r = s.current;
506
508
  if (!r) return;
507
- const n = r.getContext("2d"), o = e.frequencyBinCount, i = new Uint8Array(o), g = Math.max(1, Math.floor(o / X)), a = getComputedStyle(r), h = +a.getPropertyValue("--bar-hue"), p = +a.getPropertyValue("--bar-hue-range"), c = +a.getPropertyValue("--bar-sat"), l = +a.getPropertyValue("--bar-lit"), b = +a.getPropertyValue("--bar-lit-range"), d = () => {
509
+ const n = r.getContext("2d"), o = e.frequencyBinCount, i = new Uint8Array(o), g = Math.max(1, Math.floor(o / te)), h = getComputedStyle(r), p = +h.getPropertyValue("--bar-hue"), c = +h.getPropertyValue("--bar-hue-range"), a = +h.getPropertyValue("--bar-sat"), l = +h.getPropertyValue("--bar-lit"), b = +h.getPropertyValue("--bar-lit-range"), d = () => {
508
510
  t.current = requestAnimationFrame(d), e.getByteFrequencyData(i);
509
- const R = r.width, I = r.height;
510
- n.clearRect(0, 0, R, I);
511
- const x = (R - (X - 1) * 2) / X;
512
- for (let T = 0; T < X; T++) {
513
- const D = i[T * g] / 255, M = Math.max(3, D * I * 0.88);
514
- n.fillStyle = `hsl(${h + D * p}, ${c}%, ${l + D * b}%)`, n.beginPath(), n.roundRect(T * (x + 2), (I - M) / 2, x, M, [2]), n.fill();
511
+ const D = r.width, M = r.height;
512
+ n.clearRect(0, 0, D, M);
513
+ const K = (D - (te - 1) * 2) / te;
514
+ for (let A = 0; A < te; A++) {
515
+ const G = i[A * g] / 255, T = Math.max(3, G * M * 0.88);
516
+ n.fillStyle = `hsl(${p + G * c}, ${a}%, ${l + G * b}%)`, n.beginPath(), n.roundRect(A * (K + 2), (M - T) / 2, K, T, [2]), n.fill();
515
517
  }
516
518
  };
517
519
  return d(), () => cancelAnimationFrame(t.current);
518
- }, [e]), /* @__PURE__ */ v("canvas", { ref: s, width: 55, height: 35, className: "ai-btn__canvas" });
520
+ }, [e]), /* @__PURE__ */ w("canvas", { ref: s, width: 55, height: 35, className: "ai-btn__canvas" });
519
521
  }
520
522
  function De({
521
523
  status: e = "idle",
@@ -526,154 +528,161 @@ function De({
526
528
  devices: o = [],
527
529
  selectedMicId: i = "",
528
530
  onDeviceChange: g,
531
+ // ── Manual input ───────────────────────────────────────────
532
+ inputData: h = "",
533
+ sendData: p,
529
534
  // ── Theming ────────────────────────────────────────────────
530
- accentColor: a = "#f97316",
531
- uiColor: h = "#64748b",
532
- size: p = 70,
533
- barHue: c = 25,
534
- barHueRange: l = 20,
535
- barSat: b = 88,
536
- barLit: d = 65,
537
- barLitRange: R = 20
535
+ accentColor: c = "#f97316",
536
+ uiColor: a = "#64748b",
537
+ size: l = 70,
538
+ barHue: b = 25,
539
+ barHueRange: d = 20,
540
+ barSat: D = 88,
541
+ barLit: M = 65,
542
+ barLitRange: K = 20
538
543
  }) {
539
- var F;
540
- const [I, x] = L(!1), T = _(null);
541
- U(() => {
542
- if (!I) return;
543
- function w(z) {
544
- var $;
545
- ($ = T.current) != null && $.contains(z.target) || x(!1);
544
+ var W;
545
+ const [A, G] = x(!1), T = L(null);
546
+ Q(() => {
547
+ if (!A) return;
548
+ function v(R) {
549
+ var P;
550
+ (P = T.current) != null && P.contains(R.target) || G(!1);
546
551
  }
547
- return document.addEventListener("pointerdown", w), () => document.removeEventListener("pointerdown", w);
548
- }, [I]);
549
- function D(w) {
550
- g == null || g(w), x(!1);
552
+ return document.addEventListener("pointerdown", v), () => document.removeEventListener("pointerdown", v);
553
+ }, [A]);
554
+ function Y(v) {
555
+ g == null || g(v), G(!1);
551
556
  }
552
- const M = ke(() => {
553
- const w = E(a, -8), z = E(a, -15), $ = E(a, -22), ne = E(a, -30), te = E(a, -42), re = E(a, 8), ae = E(a, 20), C = E(a, 30), q = E(h, -22), K = E(h, -30), A = E(h, 18), W = E(h, 37);
557
+ const re = Se(() => {
558
+ const v = z(c, -8), R = z(c, -15), P = z(c, -22), se = z(c, -30), X = z(c, -42), U = z(c, 8), Z = z(c, 20), N = z(c, 30), V = z(a, -22), B = z(a, -30), $ = z(a, 18), H = z(a, 37);
554
559
  return {
555
- "--tz-size": `${p}px`,
560
+ "--tz-size": `${l}px`,
556
561
  // Accent shades
557
- "--tz-a": a,
558
- "--tz-a-d8": w,
559
- "--tz-a-d15": z,
560
- "--tz-a-d22": $,
561
- "--tz-a-d30": ne,
562
- "--tz-a-d42": te,
563
- "--tz-a-l8": re,
564
- "--tz-a-l20": ae,
565
- "--tz-a-l30": C,
562
+ "--tz-a": c,
563
+ "--tz-a-d8": v,
564
+ "--tz-a-d15": R,
565
+ "--tz-a-d22": P,
566
+ "--tz-a-d30": se,
567
+ "--tz-a-d42": X,
568
+ "--tz-a-l8": U,
569
+ "--tz-a-l20": Z,
570
+ "--tz-a-l30": N,
566
571
  // Accent + alpha
567
- "--tz-a-25": N(a, 0.25),
568
- "--tz-a-28": N(a, 0.28),
569
- "--tz-a-30": N(a, 0.3),
570
- "--tz-a-32": N(a, 0.32),
571
- "--tz-a-34": N(a, 0.34),
572
- "--tz-a-35": N(a, 0.35),
573
- "--tz-a-38": N(a, 0.38),
574
- "--tz-a-45": N(a, 0.45),
575
- "--tz-a-50": N(a, 0.5),
576
- "--tz-a-55": N(a, 0.55),
577
- "--tz-a-60": N(a, 0.6),
578
- "--tz-a-65": N(a, 0.65),
579
- "--tz-a-68": N(a, 0.68),
572
+ "--tz-a-25": I(c, 0.25),
573
+ "--tz-a-28": I(c, 0.28),
574
+ "--tz-a-30": I(c, 0.3),
575
+ "--tz-a-32": I(c, 0.32),
576
+ "--tz-a-34": I(c, 0.34),
577
+ "--tz-a-35": I(c, 0.35),
578
+ "--tz-a-38": I(c, 0.38),
579
+ "--tz-a-45": I(c, 0.45),
580
+ "--tz-a-50": I(c, 0.5),
581
+ "--tz-a-55": I(c, 0.55),
582
+ "--tz-a-60": I(c, 0.6),
583
+ "--tz-a-65": I(c, 0.65),
584
+ "--tz-a-68": I(c, 0.68),
580
585
  // UI shades
581
- "--tz-u": h,
582
- "--tz-u-d22": q,
583
- "--tz-u-d30": K,
584
- "--tz-u-l18": A,
585
- "--tz-u-l37": W,
586
+ "--tz-u": a,
587
+ "--tz-u-d22": V,
588
+ "--tz-u-d30": B,
589
+ "--tz-u-l18": $,
590
+ "--tz-u-l37": H,
586
591
  // UI + alpha
587
- "--tz-u-30": N(h, 0.3),
588
- "--tz-u-55": N(h, 0.55),
589
- "--tz-u-d30-a85": H(K, 0.85),
590
- "--tz-u-l18-a18": H(A, 0.18),
591
- "--tz-u-l18-a20": H(A, 0.2),
592
- "--tz-u-l18-a32": H(A, 0.32),
593
- "--tz-u-d22-a90": H(q, 0.9),
592
+ "--tz-u-30": I(a, 0.3),
593
+ "--tz-u-55": I(a, 0.55),
594
+ "--tz-u-d30-a85": J(B, 0.85),
595
+ "--tz-u-l18-a18": J($, 0.18),
596
+ "--tz-u-l18-a20": J($, 0.2),
597
+ "--tz-u-l18-a32": J($, 0.32),
598
+ "--tz-u-d22-a90": J(V, 0.9),
594
599
  // Waveform bar colors (cascade to canvas via getComputedStyle)
595
- "--bar-hue": c,
596
- "--bar-hue-range": l,
597
- "--bar-sat": b,
598
- "--bar-lit": d,
599
- "--bar-lit-range": R
600
+ "--bar-hue": b,
601
+ "--bar-hue-range": d,
602
+ "--bar-sat": D,
603
+ "--bar-lit": M,
604
+ "--bar-lit-range": K
600
605
  };
601
- }, [a, h, p, c, l, b, d, R]), ee = ((F = o.find((w) => w.deviceId === i)) == null ? void 0 : F.label) || (i ? `Mic ${i.slice(0, 6)}…` : "Default mic"), Z = s ? e : "off";
602
- let G;
603
- return !s || e === "idle" ? G = /* @__PURE__ */ v("svg", { className: "ai-btn__mic", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ v("path", { d: "M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4zm6 10a1 1 0 0 1 2 0 8 8 0 0 1-7 7.94V21h2a1 1 0 0 1 0 2H9a1 1 0 0 1 0-2h2v-2.06A8 8 0 0 1 4 11a1 1 0 0 1 2 0 6 6 0 0 0 12 0z" }) }) : e === "listening" ? G = /* @__PURE__ */ v(Ee, { analyser: r }) : e === "transcribing" ? G = /* @__PURE__ */ v("div", { className: "ai-btn__bars ai-btn__bars--transcribing", children: Array.from({ length: 7 }, (w, z) => /* @__PURE__ */ v("span", { style: { animationDelay: `${z * 0.1}s` } }, z)) }) : e === "thinking" ? G = /* @__PURE__ */ V("div", { className: "ai-btn__dots", children: [
604
- /* @__PURE__ */ v("span", {}),
605
- /* @__PURE__ */ v("span", { style: { animationDelay: "0.18s" } }),
606
- /* @__PURE__ */ v("span", { style: { animationDelay: "0.36s" } })
607
- ] }) : e === "speaking" && (G = /* @__PURE__ */ v("div", { className: "ai-btn__bars ai-btn__bars--speaking", children: Array.from({ length: 7 }, (w, z) => /* @__PURE__ */ v("span", { style: { animationDelay: `${z * 0.11}s` } }, z)) })), /* @__PURE__ */ V("div", { className: "ai-btn-root", style: M, children: [
608
- /* @__PURE__ */ V("div", { className: `ai-btn-rings ai-btn-rings--${Z}`, "aria-hidden": "true", children: [
609
- /* @__PURE__ */ v("span", { className: "ai-ring ai-ring--1" }),
610
- /* @__PURE__ */ v("span", { className: "ai-ring ai-ring--2" })
606
+ }, [c, a, l, b, d, D, M, K]), ae = ((W = o.find((v) => v.deviceId === i)) == null ? void 0 : W.label) || (i ? `Mic ${i.slice(0, 6)}…` : "Default mic"), _ = h.trim().length > 0, O = _ ? "ready" : s ? e : "off";
607
+ let E;
608
+ return _ ? E = /* @__PURE__ */ w("svg", { className: "ai-btn__mic", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: /* @__PURE__ */ w("path", { d: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" }) }) : !s || e === "idle" ? E = /* @__PURE__ */ q("svg", { className: "ai-btn__mic", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: [
609
+ /* @__PURE__ */ w("path", { fillOpacity: "0.52", d: "M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4zm6 10a1 1 0 0 1 2 0 8 8 0 0 1-7 7.94V21h2a1 1 0 0 1 0 2H9a1 1 0 0 1 0-2h2v-2.06A8 8 0 0 1 4 11a1 1 0 0 1 2 0 6 6 0 0 0 12 0z" }),
610
+ /* @__PURE__ */ w("path", { fill: "white", fillOpacity: "0.98", d: "M14.5 0L15.65 3.45L19.1 4.6L15.65 5.75L14.5 9.2L13.35 5.75L9.9 4.6L13.35 3.45Z" }),
611
+ /* @__PURE__ */ w("path", { fill: "white", fillOpacity: "0.88", d: "M19 8.62L19.75 10.75L21.88 11.5L19.75 12.25L19 14.38L18.25 12.25L16.12 11.5L18.25 10.75Z" })
612
+ ] }) : e === "listening" ? E = /* @__PURE__ */ w(_e, { analyser: r }) : e === "transcribing" ? E = /* @__PURE__ */ w("div", { className: "ai-btn__bars ai-btn__bars--transcribing", children: Array.from({ length: 7 }, (v, R) => /* @__PURE__ */ w("span", { style: { animationDelay: `${R * 0.1}s` } }, R)) }) : e === "thinking" ? E = /* @__PURE__ */ q("div", { className: "ai-btn__dots", children: [
613
+ /* @__PURE__ */ w("span", {}),
614
+ /* @__PURE__ */ w("span", { style: { animationDelay: "0.18s" } }),
615
+ /* @__PURE__ */ w("span", { style: { animationDelay: "0.36s" } })
616
+ ] }) : e === "speaking" && (E = /* @__PURE__ */ w("div", { className: "ai-btn__bars ai-btn__bars--speaking", children: Array.from({ length: 7 }, (v, R) => /* @__PURE__ */ w("span", { style: { animationDelay: `${R * 0.11}s` } }, R)) })), /* @__PURE__ */ q("div", { className: "ai-btn-root", style: re, children: [
617
+ /* @__PURE__ */ q("div", { className: `ai-btn-rings ai-btn-rings--${O}`, "aria-hidden": "true", children: [
618
+ /* @__PURE__ */ w("span", { className: "ai-ring ai-ring--1" }),
619
+ /* @__PURE__ */ w("span", { className: "ai-ring ai-ring--2" })
611
620
  ] }),
612
- /* @__PURE__ */ V(
621
+ /* @__PURE__ */ q(
613
622
  "button",
614
623
  {
615
- className: `ai-btn ai-btn--${Z}`,
624
+ className: `ai-btn ai-btn--${O}`,
616
625
  disabled: t,
617
- onClick: n,
618
- "aria-label": s ? "Stop assistant" : "Start assistant",
619
- "aria-pressed": s,
626
+ onClick: _ ? () => p == null ? void 0 : p(h) : n,
627
+ "aria-label": _ ? "Send message" : s ? "Stop assistant" : "Start assistant",
628
+ "aria-pressed": _ ? void 0 : s,
620
629
  children: [
621
- G,
622
- s && /* @__PURE__ */ v("span", { className: "ai-btn__hover-stop", "aria-hidden": "true", children: "■" })
630
+ E,
631
+ s && !_ && /* @__PURE__ */ w("span", { className: "ai-btn__hover-stop", "aria-hidden": "true", children: "■" })
623
632
  ]
624
633
  }
625
634
  ),
626
- /* @__PURE__ */ V("div", { className: `ai-mic-sel${I ? " open" : ""}`, ref: T, children: [
627
- /* @__PURE__ */ V(
635
+ /* @__PURE__ */ q("div", { className: `ai-mic-sel${A ? " open" : ""}`, ref: T, children: [
636
+ /* @__PURE__ */ q(
628
637
  "button",
629
638
  {
630
639
  className: "ai-mic-sel__trigger",
631
- onClick: () => x((w) => !w),
640
+ onClick: () => G((v) => !v),
632
641
  title: "Change microphone",
633
642
  "aria-label": "Change microphone",
634
- "aria-expanded": I,
643
+ "aria-expanded": A,
635
644
  children: [
636
- /* @__PURE__ */ V("svg", { width: "11", height: "11", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: [
637
- /* @__PURE__ */ v("path", { d: "M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4z" }),
638
- /* @__PURE__ */ v("path", { d: "M5 11a1 1 0 0 0-2 0 9 9 0 0 0 8 8.94V22H9a1 1 0 0 0 0 2h6a1 1 0 0 0 0-2h-2v-2.06A9 9 0 0 0 21 11a1 1 0 0 0-2 0 7 7 0 0 1-14 0z" })
645
+ /* @__PURE__ */ q("svg", { width: "11", height: "11", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", children: [
646
+ /* @__PURE__ */ w("path", { d: "M12 1a4 4 0 0 1 4 4v6a4 4 0 0 1-8 0V5a4 4 0 0 1 4-4z" }),
647
+ /* @__PURE__ */ w("path", { d: "M5 11a1 1 0 0 0-2 0 9 9 0 0 0 8 8.94V22H9a1 1 0 0 0 0 2h6a1 1 0 0 0 0-2h-2v-2.06A9 9 0 0 0 21 11a1 1 0 0 0-2 0 7 7 0 0 1-14 0z" })
639
648
  ] }),
640
- /* @__PURE__ */ v("span", { className: "ai-mic-sel__label", children: ee }),
641
- /* @__PURE__ */ v(
649
+ /* @__PURE__ */ w("span", { className: "ai-mic-sel__label", children: ae }),
650
+ /* @__PURE__ */ w(
642
651
  "svg",
643
652
  {
644
- className: `ai-mic-sel__caret${I ? " open" : ""}`,
653
+ className: `ai-mic-sel__caret${A ? " open" : ""}`,
645
654
  width: "9",
646
655
  height: "9",
647
656
  viewBox: "0 0 24 24",
648
657
  fill: "currentColor",
649
658
  "aria-hidden": "true",
650
- children: /* @__PURE__ */ v("path", { d: "M12 16L4 8h16l-8 8z" })
659
+ children: /* @__PURE__ */ w("path", { d: "M12 16L4 8h16l-8 8z" })
651
660
  }
652
661
  )
653
662
  ]
654
663
  }
655
664
  ),
656
- I && /* @__PURE__ */ V("ul", { className: "ai-mic-sel__menu", role: "listbox", "aria-label": "Select microphone", children: [
657
- /* @__PURE__ */ v(
665
+ A && /* @__PURE__ */ q("ul", { className: "ai-mic-sel__menu", role: "listbox", "aria-label": "Select microphone", children: [
666
+ /* @__PURE__ */ w(
658
667
  "li",
659
668
  {
660
669
  role: "option",
661
670
  className: `ai-mic-sel__option${i === "" ? " selected" : ""}`,
662
- onClick: () => D(""),
671
+ onClick: () => Y(""),
663
672
  "aria-selected": i === "",
664
673
  children: "Default microphone"
665
674
  }
666
675
  ),
667
- o.map((w) => /* @__PURE__ */ v(
676
+ o.map((v) => /* @__PURE__ */ w(
668
677
  "li",
669
678
  {
670
679
  role: "option",
671
- className: `ai-mic-sel__option${i === w.deviceId ? " selected" : ""}`,
672
- onClick: () => D(w.deviceId),
673
- "aria-selected": i === w.deviceId,
674
- children: w.label || `Microphone ${w.deviceId.slice(0, 8)}`
680
+ className: `ai-mic-sel__option${i === v.deviceId ? " selected" : ""}`,
681
+ onClick: () => Y(v.deviceId),
682
+ "aria-selected": i === v.deviceId,
683
+ children: v.label || `Microphone ${v.deviceId.slice(0, 8)}`
675
684
  },
676
- w.deviceId
685
+ v.deviceId
677
686
  ))
678
687
  ] })
679
688
  ] })
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- @charset "UTF-8";.ai-btn-root{display:inline-flex;flex-direction:column;align-items:center;gap:6px;position:relative;-webkit-user-select:none;user-select:none;padding-bottom:5px}.ai-btn-rings{position:absolute;top:0;left:50%;transform:translate(-50%);width:var(--tz-size);height:var(--tz-size);pointer-events:none;z-index:0}.ai-ring{position:absolute;top:0;right:0;bottom:0;left:0;border-radius:50%;border:1px solid transparent}@keyframes ai-ring-expand{0%{transform:scale(1);opacity:1}to{transform:scale(1.65);opacity:0}}.ai-btn-rings--idle .ai-ring--1{border-color:var(--tz-a-28);animation:ai-ring-expand 2.8s ease-out infinite}.ai-btn-rings--idle .ai-ring--2{display:none}.ai-btn-rings--listening .ai-ring--1{border-color:var(--tz-a-60);animation:ai-ring-expand 1.8s ease-out infinite}.ai-btn-rings--listening .ai-ring--2{border-color:var(--tz-a-32);animation:ai-ring-expand 1.8s ease-out .55s infinite}.ai-btn-rings--transcribing .ai-ring--1{border-color:var(--tz-a-50);animation:ai-ring-expand 1.4s ease-out infinite}.ai-btn-rings--transcribing .ai-ring--2{display:none}.ai-btn-rings--thinking .ai-ring--1{border-color:var(--tz-a-34);animation:ai-ring-expand 2s ease-out infinite}.ai-btn-rings--thinking .ai-ring--2{display:none}.ai-btn-rings--speaking .ai-ring--1{border-color:var(--tz-a-68);animation:ai-ring-expand 1.1s ease-out infinite}.ai-btn-rings--speaking .ai-ring--2{border-color:var(--tz-a-38);animation:ai-ring-expand 1.1s ease-out .35s infinite}.ai-btn{position:relative;z-index:1;width:var(--tz-size);height:var(--tz-size);border-radius:50%;border:2px solid transparent;overflow:hidden;display:flex;align-items:center;justify-content:center;cursor:pointer;transition:background .3s ease,border-color .3s ease,box-shadow .3s ease,transform .15s ease;-webkit-tap-highlight-color:transparent}.ai-btn:hover:not(:disabled){transform:scale(1.045)}.ai-btn:active:not(:disabled){transform:scale(.97)}.ai-btn:disabled{cursor:not-allowed;opacity:.5}.ai-btn__hover-stop{position:absolute;top:0;right:0;bottom:0;left:0;display:flex;align-items:center;justify-content:center;font-size:12px;color:#fffc;opacity:0;background:#00000061;transition:opacity .2s;border-radius:50%;pointer-events:none}.ai-btn:hover:not(:disabled) .ai-btn__hover-stop{opacity:1}.ai-btn--off{background:var(--tz-u-d30);border-color:var(--tz-u-30);box-shadow:0 4px 18px #00000073;color:var(--tz-u)}.ai-btn--off:hover:not(:disabled){border-color:var(--tz-u-55);color:var(--tz-u-l18)}.ai-btn--idle{background:radial-gradient(circle at 42% 38%,var(--tz-a-d42),var(--tz-a-d42));border-color:var(--tz-a-30);box-shadow:0 0 22px var(--tz-a-25),0 4px 18px #0006;color:var(--tz-a-l20)}.ai-btn--listening{background:radial-gradient(circle at 42% 38%,var(--tz-a-d22),var(--tz-a-d30));border-color:var(--tz-a-50);box-shadow:0 0 28px var(--tz-a-50),0 4px 18px #0006;color:var(--tz-a-l30)}.ai-btn--transcribing{background:radial-gradient(circle at 42% 38%,var(--tz-a-d15),var(--tz-a-d22));border-color:var(--tz-a-45);box-shadow:0 0 30px var(--tz-a-55),0 4px 18px #0006;color:var(--tz-a-l8)}.ai-btn--thinking{background:radial-gradient(circle at 42% 38%,var(--tz-a-d30),var(--tz-a-d42));border-color:var(--tz-a-35);box-shadow:0 0 26px var(--tz-a-50),0 4px 18px #0006;color:var(--tz-a-l20)}.ai-btn--speaking{background:radial-gradient(circle at 42% 38%,var(--tz-a-d8),var(--tz-a-d15));border-color:var(--tz-a-55);box-shadow:0 0 32px var(--tz-a-65),0 4px 18px #0006;color:var(--tz-a-l30)}.ai-btn__mic{width:23px;height:23px;opacity:.9;flex-shrink:0}.ai-btn__canvas{display:block;max-width:58px}.ai-btn__bars{display:flex;align-items:center;gap:3px}.ai-btn__bars span{display:block;width:4px;border-radius:2px;transform-origin:center}.ai-btn__bars--transcribing{height:37px}.ai-btn__bars--transcribing span{height:31px;background:linear-gradient(180deg,var(--tz-a-l20),var(--tz-a-d8));animation:ai-bar-transcribe .85s ease-in-out infinite}.ai-btn__bars--speaking{height:37px}.ai-btn__bars--speaking span{height:31px;background:linear-gradient(180deg,var(--tz-a-l30),var(--tz-a));animation:ai-bar-speak .55s ease-in-out infinite}.ai-btn__dots{display:flex;align-items:center;gap:6px}.ai-btn__dots span{display:block;width:8px;height:8px;border-radius:50%;background:var(--tz-a-l20);animation:ai-dot-think 1.1s ease-in-out infinite}@keyframes ai-bar-transcribe{0%,to{transform:scaleY(.1);opacity:.35}50%{transform:scaleY(1);opacity:1}}@keyframes ai-bar-speak{0%,to{transform:scaleY(.18)}50%{transform:scaleY(1)}}@keyframes ai-dot-think{0%,60%,to{transform:translateY(0);opacity:.4}30%{transform:translateY(-10px);opacity:1}}.ai-mic-sel{position:relative;opacity:0;visibility:hidden;transform:translateY(4px);transition:opacity .18s,visibility .18s,transform .18s}.ai-btn-root:hover .ai-mic-sel,.ai-mic-sel.open{opacity:1;visibility:visible;transform:translateY(0)}.ai-mic-sel__trigger{display:inline-flex;align-items:center;gap:5px;padding:5px 11px;border-radius:999px;background:var(--tz-u-d30-a85);border:1px solid var(--tz-u-l18-a18);color:var(--tz-u-l18);font-size:.73rem;cursor:pointer;transition:background .18s,border-color .18s,color .18s;white-space:nowrap;max-width:200px}.ai-mic-sel__trigger:hover{background:var(--tz-u-d22-a90);border-color:var(--tz-u-l18-a32);color:var(--tz-u-l37)}.ai-mic-sel__label{max-width:130px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ai-mic-sel__caret{transition:transform .2s;flex-shrink:0;opacity:.7}.ai-mic-sel__caret.open{transform:rotate(180deg)}.ai-mic-sel__menu{position:absolute;bottom:calc(100% + 7px);left:50%;transform:translate(-50%);min-width:220px;background:var(--tz-u-d30);border:1px solid var(--tz-u-l18-a20);border-radius:10px;box-shadow:0 8px 30px #0000008c;overflow:hidden;z-index:200;list-style:none;margin:0;padding:4px}.ai-mic-sel__option{display:block;width:100%;padding:8px 12px;text-align:left;font-size:.8rem;color:var(--tz-u-l37);border-radius:7px;background:none;border:none;cursor:pointer;transition:background .15s;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ai-mic-sel__option:hover{background:#3b82f624;color:#e2e8f0}.ai-mic-sel__option.selected{background:#3b82f633;color:#93c5fd}.ai-mic-sel__option.selected:before{content:"✓ "}
1
+ @charset "UTF-8";.ai-btn-root{display:inline-flex;flex-direction:column;align-items:center;gap:6px;position:relative;-webkit-user-select:none;user-select:none;padding-bottom:5px}.ai-btn-rings{position:absolute;top:0;left:50%;transform:translate(-50%);width:var(--tz-size);height:var(--tz-size);pointer-events:none;z-index:0}.ai-ring{position:absolute;top:0;right:0;bottom:0;left:0;border-radius:50%;border:1px solid transparent}@keyframes ai-ring-expand{0%{transform:scale(1);opacity:1}to{transform:scale(1.65);opacity:0}}.ai-btn-rings--idle .ai-ring--1{border-color:var(--tz-a-28);animation:ai-ring-expand 2.8s ease-out infinite}.ai-btn-rings--idle .ai-ring--2{display:none}.ai-btn-rings--listening .ai-ring--1{border-color:var(--tz-a-60);animation:ai-ring-expand 1.8s ease-out infinite}.ai-btn-rings--listening .ai-ring--2{border-color:var(--tz-a-32);animation:ai-ring-expand 1.8s ease-out .55s infinite}.ai-btn-rings--transcribing .ai-ring--1{border-color:var(--tz-a-50);animation:ai-ring-expand 1.4s ease-out infinite}.ai-btn-rings--transcribing .ai-ring--2{display:none}.ai-btn-rings--thinking .ai-ring--1{border-color:var(--tz-a-34);animation:ai-ring-expand 2s ease-out infinite}.ai-btn-rings--thinking .ai-ring--2{display:none}.ai-btn-rings--speaking .ai-ring--1{border-color:var(--tz-a-68);animation:ai-ring-expand 1.1s ease-out infinite}.ai-btn-rings--speaking .ai-ring--2{border-color:var(--tz-a-38);animation:ai-ring-expand 1.1s ease-out .35s infinite}.ai-btn-rings--ready .ai-ring--1{border-color:var(--tz-a-55);animation:ai-ring-expand 1.6s ease-out infinite}.ai-btn-rings--ready .ai-ring--2{display:none}.ai-btn{position:relative;z-index:1;width:var(--tz-size);height:var(--tz-size);border-radius:50%;border:2px solid transparent;overflow:hidden;display:flex;align-items:center;justify-content:center;cursor:pointer;transition:background .3s ease,border-color .3s ease,box-shadow .3s ease,transform .15s ease;-webkit-tap-highlight-color:transparent}.ai-btn:hover:not(:disabled){transform:scale(1.045)}.ai-btn:active:not(:disabled){transform:scale(.97)}.ai-btn:disabled{cursor:not-allowed;opacity:.5}.ai-btn__hover-stop{position:absolute;top:0;right:0;bottom:0;left:0;display:flex;align-items:center;justify-content:center;font-size:12px;color:#fffc;opacity:0;background:#00000061;transition:opacity .2s;border-radius:50%;pointer-events:none}.ai-btn:hover:not(:disabled) .ai-btn__hover-stop{opacity:1}.ai-btn--off{background:radial-gradient(circle at 42% 38%,var(--tz-a-d22),var(--tz-a-d30));border-color:var(--tz-a-30);box-shadow:0 0 16px var(--tz-a-25),0 4px 18px #0006;color:var(--tz-a-l20)}.ai-btn--off:hover:not(:disabled){border-color:var(--tz-a-55);color:var(--tz-a-l30)}.ai-btn--idle{background:radial-gradient(circle at 42% 38%,var(--tz-a-d8),var(--tz-a-d22));border-color:var(--tz-a-50);box-shadow:0 0 26px var(--tz-a-35),0 4px 18px #0006;color:var(--tz-a-l20)}.ai-btn--listening{background:radial-gradient(circle at 42% 38%,var(--tz-a-d22),var(--tz-a-d30));border-color:var(--tz-a-50);box-shadow:0 0 28px var(--tz-a-50),0 4px 18px #0006;color:var(--tz-a-l30)}.ai-btn--transcribing{background:radial-gradient(circle at 42% 38%,var(--tz-a-d15),var(--tz-a-d22));border-color:var(--tz-a-45);box-shadow:0 0 30px var(--tz-a-55),0 4px 18px #0006;color:var(--tz-a-l8)}.ai-btn--thinking{background:radial-gradient(circle at 42% 38%,var(--tz-a-d30),var(--tz-a-d42));border-color:var(--tz-a-35);box-shadow:0 0 26px var(--tz-a-50),0 4px 18px #0006;color:var(--tz-a-l20)}.ai-btn--speaking{background:radial-gradient(circle at 42% 38%,var(--tz-a-d8),var(--tz-a-d15));border-color:var(--tz-a-55);box-shadow:0 0 32px var(--tz-a-65),0 4px 18px #0006;color:var(--tz-a-l30)}.ai-btn--ready{background:radial-gradient(circle at 42% 38%,var(--tz-a-d8),var(--tz-a-d22));border-color:var(--tz-a-65);box-shadow:0 0 28px var(--tz-a-50),0 4px 18px #0006;color:var(--tz-a-l30)}.ai-btn--ready .ai-btn__mic{width:calc(var(--tz-size) * .5);height:calc(var(--tz-size) * .5)}.ai-btn__mic{width:calc(var(--tz-size) * .65);height:calc(var(--tz-size) * .65);opacity:.9;flex-shrink:0}.ai-btn__canvas{display:block;max-width:58px}.ai-btn__bars{display:flex;align-items:center;gap:3px}.ai-btn__bars span{display:block;width:4px;border-radius:2px;transform-origin:center}.ai-btn__bars--transcribing{height:37px}.ai-btn__bars--transcribing span{height:31px;background:linear-gradient(180deg,var(--tz-a-l20),var(--tz-a-d8));animation:ai-bar-transcribe .85s ease-in-out infinite}.ai-btn__bars--speaking{height:37px}.ai-btn__bars--speaking span{height:31px;background:linear-gradient(180deg,var(--tz-a-l30),var(--tz-a));animation:ai-bar-speak .55s ease-in-out infinite}.ai-btn__dots{display:flex;align-items:center;gap:6px}.ai-btn__dots span{display:block;width:8px;height:8px;border-radius:50%;background:var(--tz-a-l20);animation:ai-dot-think 1.1s ease-in-out infinite}@keyframes ai-bar-transcribe{0%,to{transform:scaleY(.1);opacity:.35}50%{transform:scaleY(1);opacity:1}}@keyframes ai-bar-speak{0%,to{transform:scaleY(.18)}50%{transform:scaleY(1)}}@keyframes ai-dot-think{0%,60%,to{transform:translateY(0);opacity:.4}30%{transform:translateY(-10px);opacity:1}}.ai-mic-sel{position:relative;opacity:0;visibility:hidden;transform:translateY(4px);transition:opacity .18s,visibility .18s,transform .18s}.ai-btn-root:hover .ai-mic-sel,.ai-mic-sel.open{opacity:1;visibility:visible;transform:translateY(0)}.ai-mic-sel__trigger{display:inline-flex;align-items:center;gap:5px;padding:5px 11px;border-radius:999px;background:var(--tz-u-d30-a85);border:1px solid var(--tz-u-l18-a18);color:var(--tz-u-l18);font-size:.73rem;cursor:pointer;transition:background .18s,border-color .18s,color .18s;white-space:nowrap;max-width:200px}.ai-mic-sel__trigger:hover{background:var(--tz-u-d22-a90);border-color:var(--tz-u-l18-a32);color:var(--tz-u-l37)}.ai-mic-sel__label{max-width:130px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ai-mic-sel__caret{transition:transform .2s;flex-shrink:0;opacity:.7}.ai-mic-sel__caret.open{transform:rotate(180deg)}.ai-mic-sel__menu{position:absolute;bottom:calc(100% + 7px);left:50%;transform:translate(-50%);min-width:220px;background:var(--tz-u-d30);border:1px solid var(--tz-u-l18-a20);border-radius:10px;box-shadow:0 8px 30px #0000008c;overflow:hidden;z-index:200;list-style:none;margin:0;padding:4px}.ai-mic-sel__option{display:block;width:100%;padding:8px 12px;text-align:left;font-size:.8rem;color:var(--tz-u-l37);border-radius:7px;background:none;border:none;cursor:pointer;transition:background .15s;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ai-mic-sel__option:hover{background:#3b82f624;color:#e2e8f0}.ai-mic-sel__option.selected{background:#3b82f633;color:#93c5fd}.ai-mic-sel__option.selected:before{content:"✓ "}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tz-voice-chat",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "React hook for a full voice-chat pipeline: VAD → Whisper STT → custom AI processor → Kokoro/OpenAI/WebSpeech TTS.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",