@lunora/vue 1.0.0-alpha.110 → 1.0.0-alpha.111
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.d.mts
CHANGED
|
@@ -1027,7 +1027,11 @@ interface UseVoiceAgentOptions {
|
|
|
1027
1027
|
* Audio graph stays isolated (and mockable in a non-browser test env).
|
|
1028
1028
|
*/
|
|
1029
1029
|
createMicrophone?: CreateMicrophone;
|
|
1030
|
-
/**
|
|
1030
|
+
/**
|
|
1031
|
+
* Advanced/test seam: open the transport. Defaults to the WebSocket
|
|
1032
|
+
* implementation the client was built with (`client.getWebSocketImpl()`),
|
|
1033
|
+
* NOT a raw `globalThis.WebSocket`.
|
|
1034
|
+
*/
|
|
1031
1035
|
createSocket?: CreateSocket;
|
|
1032
1036
|
/** Advanced/test seam: build the audio playback subsystem. Defaults to a Web Audio implementation. */
|
|
1033
1037
|
createSpeaker?: CreateSpeaker;
|
package/dist/index.d.ts
CHANGED
|
@@ -1027,7 +1027,11 @@ interface UseVoiceAgentOptions {
|
|
|
1027
1027
|
* Audio graph stays isolated (and mockable in a non-browser test env).
|
|
1028
1028
|
*/
|
|
1029
1029
|
createMicrophone?: CreateMicrophone;
|
|
1030
|
-
/**
|
|
1030
|
+
/**
|
|
1031
|
+
* Advanced/test seam: open the transport. Defaults to the WebSocket
|
|
1032
|
+
* implementation the client was built with (`client.getWebSocketImpl()`),
|
|
1033
|
+
* NOT a raw `globalThis.WebSocket`.
|
|
1034
|
+
*/
|
|
1031
1035
|
createSocket?: CreateSocket;
|
|
1032
1036
|
/** Advanced/test seam: build the audio playback subsystem. Defaults to a Web Audio implementation. */
|
|
1033
1037
|
createSpeaker?: CreateSpeaker;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AuthLoading as r,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-nfI43dvD.mjs";import{hydratePreloaded as a}from"./packem_shared/hydratePreloaded-BpzZkPH4.mjs";import{LUNORA_INJECTION_KEY as f,createLunora as m,provideLunora as p,useLunora as x}from"./packem_shared/LUNORA_INJECTION_KEY-Bct9tKCj.mjs";import{useAction as A}from"./packem_shared/useAction-C4VLsh4M.mjs";import{useAgent as d}from"./packem_shared/useAgent-By6FSLfF.mjs";import{useAgentChat as h}from"./packem_shared/useAgentChat-Dv_y3vQH.mjs";import{useAgentState as l}from"./packem_shared/useAgentState-BYx1l9vy.mjs";import{useAgentToolEvents as Q}from"./packem_shared/useAgentToolEvents-BMwcZ2G9.mjs";import{useAuth as b}from"./packem_shared/useAuth-DJ9902_4.mjs";import{default as E}from"./packem_shared/useConnectionStatus-BSFJBnmi.mjs";import{useFlag as N,useFlags as P}from"./packem_shared/useFlag-xVfWC_c6.mjs";import{useMutation as v}from"./packem_shared/useMutation-D6PkaNaE.mjs";import{useMutator as M}from"./packem_shared/useMutator-CO7nXlRf.mjs";import{useInfiniteQuery as R,usePaginatedQuery as U}from"./packem_shared/useInfiniteQuery-CvBV9XVA.mjs";import{usePresence as J}from"./packem_shared/usePresence-BOs1lDlC.mjs";import{subscribeToQuery as V,useQuery as Y}from"./packem_shared/subscribeToQuery-G5w094pU.mjs";import{useRateLimit as k}from"./packem_shared/useRateLimit-zoPsflSG.mjs";import{useStream as w}from"./packem_shared/useStream-Ca4Rkw4p.mjs";import{useSubscription as B}from"./packem_shared/useSubscription-yGJRK0w-.mjs";import{useVoiceAgent as G}from"./packem_shared/useVoiceAgent-
|
|
1
|
+
import{AuthLoading as r,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-nfI43dvD.mjs";import{hydratePreloaded as a}from"./packem_shared/hydratePreloaded-BpzZkPH4.mjs";import{LUNORA_INJECTION_KEY as f,createLunora as m,provideLunora as p,useLunora as x}from"./packem_shared/LUNORA_INJECTION_KEY-Bct9tKCj.mjs";import{useAction as A}from"./packem_shared/useAction-C4VLsh4M.mjs";import{useAgent as d}from"./packem_shared/useAgent-By6FSLfF.mjs";import{useAgentChat as h}from"./packem_shared/useAgentChat-Dv_y3vQH.mjs";import{useAgentState as l}from"./packem_shared/useAgentState-BYx1l9vy.mjs";import{useAgentToolEvents as Q}from"./packem_shared/useAgentToolEvents-BMwcZ2G9.mjs";import{useAuth as b}from"./packem_shared/useAuth-DJ9902_4.mjs";import{default as E}from"./packem_shared/useConnectionStatus-BSFJBnmi.mjs";import{useFlag as N,useFlags as P}from"./packem_shared/useFlag-xVfWC_c6.mjs";import{useMutation as v}from"./packem_shared/useMutation-D6PkaNaE.mjs";import{useMutator as M}from"./packem_shared/useMutator-CO7nXlRf.mjs";import{useInfiniteQuery as R,usePaginatedQuery as U}from"./packem_shared/useInfiniteQuery-CvBV9XVA.mjs";import{usePresence as J}from"./packem_shared/usePresence-BOs1lDlC.mjs";import{subscribeToQuery as V,useQuery as Y}from"./packem_shared/subscribeToQuery-G5w094pU.mjs";import{useRateLimit as k}from"./packem_shared/useRateLimit-zoPsflSG.mjs";import{useStream as w}from"./packem_shared/useStream-Ca4Rkw4p.mjs";import{useSubscription as B}from"./packem_shared/useSubscription-yGJRK0w-.mjs";import{useVoiceAgent as G}from"./packem_shared/useVoiceAgent-CRolV39k.mjs";export{r as AuthLoading,t as Authenticated,f as LUNORA_INJECTION_KEY,u as Unauthenticated,m as createLunora,a as hydratePreloaded,p as provideLunora,V as subscribeToQuery,A as useAction,d as useAgent,h as useAgentChat,l as useAgentState,Q as useAgentToolEvents,b as useAuth,E as useConnectionStatus,N as useFlag,P as useFlags,R as useInfiniteQuery,x as useLunora,v as useMutation,M as useMutator,U as usePaginatedQuery,J as usePresence,Y as useQuery,k as useRateLimit,w as useStream,B as useSubscription,G as useVoiceAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ref as A,onScopeDispose as V,toValue as O}from"vue";import{useLunora as P}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const M="/_lunora/ws",H="/_lunora/voice/",$=4001,U=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,B=e=>{const o=e.startsWith("agents:")?e.slice(7):e;return o.endsWith("Voice")?o.slice(0,-5):o},K=(e,o)=>{if(o===void 0||o==="")return U(e);if(o.endsWith(M))return o.slice(0,-M.length);try{return new URL(o).origin}catch{return U(e)}},q=e=>{const o=K(e.httpUrl,e.wsUrl),s=o.endsWith("/")?o.slice(0,-1):o,c=new URLSearchParams({threadKey:e.threadKey});return`${s}${H}${encodeURIComponent(e.agent)}?${c.toString()}`},J=(e,o)=>{if(o?.code===$)return new Error(`${e}: authentication token expired — refresh the credential and start a new call`)},G=16e3,X=e=>{if(e.length===0)return 0;let o=0;for(const s of e)o+=s*s;return Math.sqrt(o/e.length)},j=(e,o)=>{const s=o/G,c=s>1?Math.floor(e.length/s):e.length,f=new ArrayBuffer(c*2),p=new DataView(f);for(let u=0;u<c;u+=1){const v=e[Math.floor(u*s)]??0,k=Math.max(-1,Math.min(1,v));p.setInt16(u*2,k<0?k*32768:k*32767,!0)}return new Uint8Array(f)},z=async e=>{const o=globalThis,s=o.navigator?.mediaDevices?.getUserMedia.bind(o.navigator.mediaDevices),c=o.AudioContext??o.webkitAudioContext;if(!s||!c)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const f=await s({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),p=new c,u=p.createMediaStreamSource(f),v=p.createScriptProcessor(4096,1,1);let k=!1,m=!1,l=0,r=0;return v.onaudioprocess=i=>{const d=i.inputBuffer.getChannelData(0),h=k?0:X(d);if(e.onLevel(h),k)return;if(e.onAudio(j(d,p.sampleRate)),e.isSpeaking()){r=h>=e.interruptThreshold?r+1:0,r>=e.interruptChunks&&(r=0,e.onInterrupt());return}r=0;const y=d.length/p.sampleRate*1e3;if(h>=e.silenceThreshold){m=!0,l=0;return}m&&(l+=y,l>=e.silenceDurationMs&&(m=!1,l=0,e.onSilence()))},u.connect(v),v.connect(p.destination),{setMuted:i=>{k=i},stop:()=>{v.disconnect(),u.disconnect();for(const i of f.getTracks())i.stop();p.close()}}},Q=()=>{const e=globalThis,o=e.AudioContext??e.webkitAudioContext;if(!o)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const s=new o,c=new Set;let f=0,p=Promise.resolve(),u=0;const v=async(l,r)=>{if(r!==u)return;let i;try{i=await s.decodeAudioData(l.buffer)}catch{return}if(r!==u)return;const d=s.createBufferSource();d.buffer=i,d.connect(s.destination);const h=Math.max(s.currentTime,f);d.start(h),f=h+i.duration,c.add(d),d.onended=()=>{c.delete(d)}},k=l=>{const r=Uint8Array.from(l),i=u;p=p.then(()=>v(r,i))},m=()=>{u+=1;for(const l of c)try{l.stop()}catch{}c.clear(),f=s.currentTime};return{enqueue:k,interrupt:m,stop:()=>{m(),s.close()}}},R=1,Y=.01,Z=1200,ee=.15,te=3,se=e=>{const{createMicrophone:o=z,createSpeaker:s=Q,createSocket:c,interruptChunks:f=te,interruptThreshold:p=ee,silenceDurationMs:u=Z,silenceThreshold:v=Y,threadKey:k,voice:m}=e,l=P(),r=A("idle"),i=A(!1),d=A(""),h=A(""),y=A(0),b=A(!1),w=A(void 0);let a,C=!1;const _=t=>{const n=a?.socket;return n?.readyState===R?(n.send(JSON.stringify(t)),!0):!1},T=()=>{const t=a;if(a=void 0,t){t.microphone?.stop(),t.speaker?.stop(),t.socket.onmessage=null,t.socket.onerror=null,t.socket.onclose=null;try{t.socket.close()}catch{}}C=!1,i.value=!1,r.value="idle",y.value=0},D=T,L=t=>{const n=a;switch(t.type){case"assistant_delta":{n&&(n.speaking=!0),r.value="speaking",h.value+=t.text;break}case"assistant_done":{n&&(n.speaking=!1),h.value=t.text,r.value="listening";break}case"error":{n&&(n.speaking=!1),w.value=new Error(t.message),r.value="listening";break}case"interrupted":{n&&(n.speaking=!1,n.suppressAudio=!1),n?.speaker?.interrupt(),r.value="listening";break}case"ready":{n&&(n.audioFormat=t.audioFormat,n.suppressAudio=!1),i.value=!0,r.value="listening";break}case"user_transcript":{n&&(n.suppressAudio=!1),d.value=t.text,h.value="",r.value="thinking";break}}},I=t=>{const n=a;!n||n.suppressAudio||(n.speaker??=s({audioFormat:n.audioFormat}),n.speaking=!0,r.value="speaking",n.speaker.enqueue(t))},F=async()=>{if(a||C)return;C=!0,w.value=void 0,d.value="",h.value="";let t;try{const n=q({agent:B(m.__lunoraRef),httpUrl:l.url,threadKey:O(k),wsUrl:l.wsUrl}),S=(c??(g=>{const E=l.getWebSocketImpl();if(!E)throw new Error("useVoiceAgent: no WebSocket implementation available (pass createSocket explicitly)");return new E(g)}))(n);S.binaryType="arraybuffer",t={audioFormat:"mp3",microphone:void 0,socket:S,speaker:void 0,speaking:!1,suppressAudio:!1},a=t,S.onmessage=g=>{if(typeof g.data=="string"){try{L(JSON.parse(g.data))}catch{}return}I(new Uint8Array(g.data))},S.onerror=()=>{w.value=new Error("useVoiceAgent: voice socket error")},S.onclose=g=>{if(a!==t)return;const E=J("useVoiceAgent",g);E&&(w.value=E),T()};const x=await o({interruptChunks:f,interruptThreshold:p,isSpeaking:()=>a?.speaking??!1,onAudio:g=>{S.readyState===R&&S.send(g)},onInterrupt:()=>{_({type:"interrupt"}),a?.speaker?.interrupt(),a&&(a.speaking=!1,a.suppressAudio=!0),r.value="listening"},onLevel:g=>{y.value=g},onSilence:()=>{_({type:"commit"}),r.value="thinking"},silenceDurationMs:u,silenceThreshold:v});a===t?(t.microphone=x,b.value=!1,t.speaking||(r.value="listening")):x.stop()}catch(n){a===t&&(w.value=n instanceof Error?n:new Error(String(n)),T())}finally{C=!1}},W=()=>{const t=!b.value;return a?.microphone?.setMuted(t),b.value=t,t},N=t=>{_({text:t,type:"text"})&&(r.value="thinking")};return V(T),{audioLevel:y,connected:i,endCall:D,error:w,interimTranscript:h,isMuted:b,sendText:N,startCall:F,status:r,toggleMute:W,transcript:d}};export{se as useVoiceAgent};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{ref as A,onScopeDispose as I,toValue as P}from"vue";import{useLunora as V}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const W=16e3,H=e=>{if(e.length===0)return 0;let r=0;for(const o of e)r+=o*o;return Math.sqrt(r/e.length)},O=(e,r)=>{const o=r/W,a=o>1?Math.floor(e.length/o):e.length,p=new ArrayBuffer(a*2),i=new DataView(p);for(let l=0;l<a;l+=1){const v=e[Math.floor(l*o)]??0,k=Math.max(-1,Math.min(1,v));i.setInt16(l*2,k<0?k*32768:k*32767,!0)}return new Uint8Array(p)},q=async e=>{const r=globalThis,o=r.navigator?.mediaDevices?.getUserMedia.bind(r.navigator.mediaDevices),a=r.AudioContext??r.webkitAudioContext;if(!o||!a)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const p=await o({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),i=new a,l=i.createMediaStreamSource(p),v=i.createScriptProcessor(4096,1,1);let k=!1,m=!1,h=0,s=0;return v.onaudioprocess=c=>{const d=c.inputBuffer.getChannelData(0),f=k?0:H(d);if(e.onLevel(f),k)return;if(e.onAudio(O(d,i.sampleRate)),e.isSpeaking()){s=f>=e.interruptThreshold?s+1:0,s>=e.interruptChunks&&(s=0,e.onInterrupt());return}s=0;const w=d.length/i.sampleRate*1e3;if(f>=e.silenceThreshold){m=!0,h=0;return}m&&(h+=w,h>=e.silenceDurationMs&&(m=!1,h=0,e.onSilence()))},l.connect(v),v.connect(i.destination),{setMuted:c=>{k=c},stop:()=>{v.disconnect(),l.disconnect();for(const c of p.getTracks())c.stop();i.close()}}},B=()=>{const e=globalThis,r=e.AudioContext??e.webkitAudioContext;if(!r)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const o=new r,a=new Set;let p=0,i=Promise.resolve(),l=0;const v=async(h,s)=>{if(s!==l)return;let c;try{c=await o.decodeAudioData(h.buffer)}catch{return}if(s!==l)return;const d=o.createBufferSource();d.buffer=c,d.connect(o.destination);const f=Math.max(o.currentTime,p);d.start(f),p=f+c.duration,a.add(d),d.onended=()=>{a.delete(d)}},k=h=>{const s=Uint8Array.from(h),c=l;i=i.then(()=>v(s,c))},m=()=>{l+=1;for(const h of a)try{h.stop()}catch{}a.clear(),p=o.currentTime};return{enqueue:k,interrupt:m,stop:()=>{m(),o.close()}}},_=1,$=.01,J=1200,K=.15,G=3,j=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,z=e=>{const r=e.__lunoraRef,o=r.startsWith("agents:")?r.slice(7):r;return o.endsWith("Voice")?o.slice(0,-5):o},Q=(e,r,o)=>{const a=j(e),p=a.endsWith("/")?a.slice(0,-1):a,i=new URLSearchParams({threadKey:o});return`${p}/_lunora/voice/${encodeURIComponent(r)}?${i.toString()}`},Z=e=>{const{createMicrophone:r=q,createSpeaker:o=B,createSocket:a,interruptChunks:p=G,interruptThreshold:i=K,silenceDurationMs:l=J,silenceThreshold:v=$,threadKey:k,voice:m}=e,h=V(),s=A("idle"),c=A(!1),d=A(""),f=A(""),w=A(0),b=A(!1),y=A(void 0);let u,T=!1;const M=t=>{const n=u?.socket;return n?.readyState===_?(n.send(JSON.stringify(t)),!0):!1},C=()=>{const t=u;if(u=void 0,t){t.microphone?.stop(),t.speaker?.stop();try{t.socket.close()}catch{}}T=!1,c.value=!1,s.value="idle",w.value=0},U=C,R=t=>{const n=u;switch(t.type){case"assistant_delta":{n&&(n.speaking=!0),s.value="speaking",f.value+=t.text;break}case"assistant_done":{n&&(n.speaking=!1),f.value=t.text,s.value="listening";break}case"error":{n&&(n.speaking=!1),y.value=new Error(t.message),s.value="listening";break}case"interrupted":{n&&(n.speaking=!1,n.suppressAudio=!1),n?.speaker?.interrupt(),s.value="listening";break}case"ready":{n&&(n.audioFormat=t.audioFormat,n.suppressAudio=!1),c.value=!0,s.value="listening";break}case"user_transcript":{n&&(n.suppressAudio=!1),d.value=t.text,f.value="",s.value="thinking";break}}},D=t=>{const n=u;!n||n.suppressAudio||(n.speaker??=o({audioFormat:n.audioFormat}),n.speaking=!0,s.value="speaking",n.speaker.enqueue(t))},L=async()=>{if(!(u||T)){T=!0,y.value=void 0,d.value="",f.value="";try{const t=Q(h.url,z(m),P(k)),S=(a??(g=>new globalThis.WebSocket(g)))(t);S.binaryType="arraybuffer";const E={audioFormat:"mp3",microphone:void 0,socket:S,speaker:void 0,speaking:!1,suppressAudio:!1};u=E,S.onmessage=g=>{if(typeof g.data=="string"){try{R(JSON.parse(g.data))}catch{}return}D(new Uint8Array(g.data))},S.onerror=()=>{y.value=new Error("useVoiceAgent: voice socket error")},S.onclose=()=>{u===E&&C()};const x=await r({interruptChunks:p,interruptThreshold:i,isSpeaking:()=>u?.speaking??!1,onAudio:g=>{S.readyState===_&&S.send(g)},onInterrupt:()=>{M({type:"interrupt"}),u?.speaker?.interrupt(),u&&(u.speaking=!1,u.suppressAudio=!0),s.value="listening"},onLevel:g=>{w.value=g},onSilence:()=>{M({type:"commit"}),s.value="thinking"},silenceDurationMs:l,silenceThreshold:v});u===E?(E.microphone=x,b.value=!1,s.value="listening"):x.stop()}catch(t){y.value=t instanceof Error?t:new Error(String(t)),C()}finally{T=!1}}},F=()=>{const t=!b.value;return u?.microphone?.setMuted(t),b.value=t,t},N=t=>{M({text:t,type:"text"})&&(s.value="thinking")};return I(C),{audioLevel:w,connected:c,endCall:U,error:y,interimTranscript:f,isMuted:b,sendText:N,startCall:L,status:s,toggleMute:F,transcript:d}};export{Z as useVoiceAgent};
|