@lunora/vue 1.0.0-alpha.112 → 1.0.0-alpha.114
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 +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/useInfiniteQuery-2KHGc4Ss.mjs +1 -0
- package/dist/packem_shared/useVoiceAgent-BEGHhbmX.mjs +1 -0
- package/package.json +4 -4
- package/dist/packem_shared/useInfiniteQuery-CvBV9XVA.mjs +0 -1
- package/dist/packem_shared/useVoiceAgent-CRolV39k.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -977,8 +977,24 @@ interface MicrophoneConfig {
|
|
|
977
977
|
interruptChunks: number;
|
|
978
978
|
/** RMS above which the user is considered to be barging in while the agent speaks. */
|
|
979
979
|
interruptThreshold: number;
|
|
980
|
-
/**
|
|
981
|
-
|
|
980
|
+
/**
|
|
981
|
+
* `true` from the moment a turn is committed until it completes — the whole
|
|
982
|
+
* `thinking` + `speaking` window, not just the audible half.
|
|
983
|
+
*
|
|
984
|
+
* It gates BOTH branches below, and the wider span is the point. Gated only
|
|
985
|
+
* on "audibly speaking", turn detection kept running through the entire
|
|
986
|
+
* STT+LLM window after a `commit`: room noise at the (deliberately low)
|
|
987
|
+
* `silenceThreshold` re-armed `sawSpeech`, another quiet gap fired a SECOND
|
|
988
|
+
* `commit`, and the DO refused it with "a turn is already in progress" —
|
|
989
|
+
* a refusal that returns before draining the audio buffer, so the PCM
|
|
990
|
+
* captured since the first commit leaked into the next utterance.
|
|
991
|
+
*
|
|
992
|
+
* A genuine barge-in still works in that window: it routes through the
|
|
993
|
+
* `onInterrupt` branch, which needs `interruptChunks` consecutive chunks at
|
|
994
|
+
* `interruptThreshold` — an order of magnitude above `silenceThreshold` —
|
|
995
|
+
* and `interrupt` is exactly what the DO tells the client to send.
|
|
996
|
+
*/
|
|
997
|
+
isTurnActive: () => boolean;
|
|
982
998
|
/** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
|
|
983
999
|
onAudio: (pcm: Uint8Array) => void;
|
|
984
1000
|
/** A barge-in was detected (RMS spike while the agent is speaking). */
|
package/dist/index.d.ts
CHANGED
|
@@ -977,8 +977,24 @@ interface MicrophoneConfig {
|
|
|
977
977
|
interruptChunks: number;
|
|
978
978
|
/** RMS above which the user is considered to be barging in while the agent speaks. */
|
|
979
979
|
interruptThreshold: number;
|
|
980
|
-
/**
|
|
981
|
-
|
|
980
|
+
/**
|
|
981
|
+
* `true` from the moment a turn is committed until it completes — the whole
|
|
982
|
+
* `thinking` + `speaking` window, not just the audible half.
|
|
983
|
+
*
|
|
984
|
+
* It gates BOTH branches below, and the wider span is the point. Gated only
|
|
985
|
+
* on "audibly speaking", turn detection kept running through the entire
|
|
986
|
+
* STT+LLM window after a `commit`: room noise at the (deliberately low)
|
|
987
|
+
* `silenceThreshold` re-armed `sawSpeech`, another quiet gap fired a SECOND
|
|
988
|
+
* `commit`, and the DO refused it with "a turn is already in progress" —
|
|
989
|
+
* a refusal that returns before draining the audio buffer, so the PCM
|
|
990
|
+
* captured since the first commit leaked into the next utterance.
|
|
991
|
+
*
|
|
992
|
+
* A genuine barge-in still works in that window: it routes through the
|
|
993
|
+
* `onInterrupt` branch, which needs `interruptChunks` consecutive chunks at
|
|
994
|
+
* `interruptThreshold` — an order of magnitude above `silenceThreshold` —
|
|
995
|
+
* and `interrupt` is exactly what the DO tells the client to send.
|
|
996
|
+
*/
|
|
997
|
+
isTurnActive: () => boolean;
|
|
982
998
|
/** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
|
|
983
999
|
onAudio: (pcm: Uint8Array) => void;
|
|
984
1000
|
/** A barge-in was detected (RMS spike while the agent is speaking). */
|
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-
|
|
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-2KHGc4Ss.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-BEGHhbmX.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{shallowRef as _,watch as v,toValue as L,onScopeDispose as q,computed as E}from"vue";import{initialPages as $,derivePaginationStatus as D,rebalance as z,applyLoadMore as G}from"@lunora/client/pagination";import{i as H}from"./is-browser-BEdfLJHK.mjs";import{useLunora as X}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const Y=/["\\\u0000-\u001F\uD800-\uDFFF]/,T=e=>Y.test(e)?JSON.stringify(e):`"${e}"`,x=e=>{if(e===void 0)return"null";if(typeof e=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(typeof e=="number"){if(Number.isNaN(e))return"nan";if(e===1/0)return"inf";if(e===-1/0)return"-inf";if(Object.is(e,-0))return"-0"}if(typeof e=="string")return T(e);if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e)){let o="[";for(let r=0;r<e.length;r++)r>0&&(o+=","),o+=x(e[r]);return o+"]"}const n=Object.getPrototypeOf(e);if(n!==null&&n!==Object.prototype){const o=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${o} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const y=e,f=Object.keys(y).sort();let a="{",t=!0;for(const o of f){const r=y[o];r!==void 0&&(t?t=!1:a+=",",a+=T(o),a+=":",a+=x(r))}return a+"}"},F=e=>{let n="";for(let f=0;f<e.length;f+=32768)n+=String.fromCharCode(...e.subarray(f,f+32768));return btoa(n)},d="$lunora.wire$",U=64,J="__proto__",Z=e=>{if(e===null||typeof e!="object")return!1;const n=Object.getPrototypeOf(e);return n===null||n===Object.prototype},S=(e,n=0)=>{if(n>U)throw new RangeError(`wire-codec: value nesting exceeds the ${U}-level limit`);if(e===void 0)return[d,"undefined"];if(e===null)return null;const y=typeof e;if(y==="bigint")return[d,"bigint",e.toString()];if(y==="number"){const t=e;return Number.isNaN(t)?[d,"nan"]:t===1/0?[d,"inf"]:t===-1/0?[d,"-inf"]:t}if(y!=="object")return e;if(e instanceof Date)return[d,"date",S(e.getTime(),n+1)];if(e instanceof Error){const t=e,o={};for(const c of Object.keys(t)){if(t[c]===void 0)continue;const b=S(t[c],n+1);c===J?Object.defineProperty(o,c,{configurable:!0,enumerable:!0,value:b,writable:!0}):o[c]=b}const r=[d,"error",t.name,t.message,o];return t.cause!==void 0&&r.push(S(t.cause,n+1)),r}if(e instanceof URL)return[d,"url",e.href];if(e instanceof Map)return[d,"map",[...e.entries()].map(([t,o])=>[S(t,n+1),S(o,n+1)])];if(e instanceof Set)return[d,"set",[...e].map(t=>S(t,n+1))];if(e instanceof ArrayBuffer)return[d,"bytes",F(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,o=t.constructor.name,r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return o==="Uint8Array"?[d,"bytes",F(r)]:[d,"bytes",F(r),o]}if(Array.isArray(e)){const t=e.map(o=>S(o,n+1));return t.length>0&&t[0]===d?[d,"arr",t]:t}if(!Z(e)){const t=e.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${t} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const f=e,a={};for(const t of Object.keys(f)){const o=f[t];if(o===void 0)continue;const r=S(o,n+1);t===J?Object.defineProperty(a,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):a[t]=r}return a},W=e=>x(S(e)),A=(e,n)=>`${e}::${W(n)}`,M=(e,n)=>({...n,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),Q=(e,n,y)=>{const f=X(),{initialNumItems:a,onError:t,shardKey:o}=y,r=_($(a)),c=_([]),b=_(void 0);let R;const P=new Map,m=new Map,w=new Set,K=(s,i)=>{c.value=s.map(h=>{const l=A(e.__lunoraRef,M(h,i));return m.get(l)})},V=(s,i,h)=>{const l=p=>A(e.__lunoraRef,M(p,h));for(const p of i){const g=l(p);if(m.has(g))continue;const N=s.find(u=>u.lower===p.lower);if(N){const u=m.get(l(N));u&&m.set(g,u)}}},C=(s,i)=>{const h=new Set;for(const l of s)h.add(A(e.__lunoraRef,M(l,i)));for(const[l,p]of P)h.has(l)||(p(),P.delete(l),m.delete(l),w.delete(l));for(const l of s){const p=M(l,i),g=A(e.__lunoraRef,p);if(P.has(g))continue;w.add(g);const N=f.subscribe(e,p,u=>{m.set(g,u),w.delete(g),b.value=void 0;const k=L(n);if(K(r.value,k),w.size===0){const O=r.value,j=z(O,c.value);j&&(V(O,j,k),r.value=j)}},{onError:u=>{w.delete(g),b.value=u;const k=r.value,O=k.at(-1);k.length>1&&O&&!m.has(g)&&A(e.__lunoraRef,M(O,i))===g&&(r.value=k.slice(0,-1)),t?.(u)},shardKey:o});P.set(g,N)}},I=()=>{for(const s of P.values())s();P.clear(),m.clear(),w.clear()};v(()=>W(L(n)),()=>{if(!H())return;const s=L(n);I(),r.value=$(a),c.value=[],b.value=void 0,R=void 0,s!=="skip"&&(C(r.value,s),K(r.value,s))},{immediate:!0}),v(()=>r.value,s=>{const i=L(n);R=void 0,i!=="skip"&&(C(s,i),K(s,i))}),q(I);const B=_("LoadingFirstPage");return v([()=>L(n),c],([s,i])=>{B.value=D(s==="skip",i).status},{immediate:!0}),{error:b,loadMore:s=>{const i=L(n);if(i==="skip")return;const{nextCursor:h,status:l}=D(!1,c.value);if(l!=="CanLoadMore"||h===R)return;const p=G(r.value,h,s);if(!p)return;R=h,b.value=void 0;const g=r.value.at(-1),N=p.at(-2);if(g&&N){const u=A(e.__lunoraRef,M(g,i)),k=A(e.__lunoraRef,M(N,i)),O=P.get(u);if(O&&u!==k){const j=m.get(u);j&&m.set(k,j),O(),P.delete(u),m.delete(u),w.delete(u)}}r.value=p},pageResults:c,status:B}},se=(e,n,y)=>{const{error:f,loadMore:a,pageResults:t,status:o}=Q(e,n,y),r=E(()=>t.value.flatMap(b=>b?.page??[])),c=E(()=>o.value==="LoadingFirstPage"||o.value==="LoadingMore");return{error:f,isLoading:c,loadMore:a,results:r,status:o}},ie=(e,n,y)=>{const{initialNumItems:f}=y,{error:a,loadMore:t,pageResults:o,status:r}=Q(e,n,y),c=E(()=>o.value.flatMap(w=>w?[w.page]:[])),b=E(()=>r.value==="LoadingFirstPage"),R=E(()=>r.value==="CanLoadMore"),P=E(()=>r.value==="LoadingMore");return{error:a,fetchNextPage:w=>{t(w??f)},hasNextPage:R,isFetchingNextPage:P,isLoading:b,pages:c,status:r}};export{ie as useInfiniteQuery,se as usePaginatedQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ref as y,onScopeDispose as N,toValue as O}from"vue";import{useLunora as P}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const M="/_lunora/ws",H="/_lunora/voice/",$=4001,I=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,B=e=>{const r=e.startsWith("agents:")?e.slice(7):e;return r.endsWith("Voice")?r.slice(0,-5):r},K=(e,r)=>{if(r===void 0||r==="")return I(e);if(r.endsWith(M))return r.slice(0,-M.length);try{return new URL(r).origin}catch{return I(e)}},q=e=>{const r=K(e.httpUrl,e.wsUrl),s=r.endsWith("/")?r.slice(0,-1):r,i=new URLSearchParams({threadKey:e.threadKey});return`${s}${H}${encodeURIComponent(e.agent)}?${i.toString()}`},J=(e,r)=>{if(r?.code===$)return new Error(`${e}: authentication token expired — refresh the credential and start a new call`)},G=(e,r,s)=>{const i=e.currentIdentity();return e.onAuthTokenChange(()=>{e.currentIdentity()!==i&&s(new Error(`${r}: the signed-in identity changed during the call — the session was ended; start a new call`))})},X=16e3,j=e=>{if(e.length===0)return 0;let r=0;for(const s of e)r+=s*s;return Math.sqrt(r/e.length)},z=(e,r)=>{const s=r/X,i=s>1?Math.floor(e.length/s):e.length,g=new ArrayBuffer(i*2),p=new DataView(g);for(let l=0;l<i;l+=1){const k=e[Math.floor(l*s)]??0,v=Math.max(-1,Math.min(1,k));p.setInt16(l*2,v<0?v*32768:v*32767,!0)}return new Uint8Array(g)},Q=async e=>{const r=globalThis,s=r.navigator?.mediaDevices?.getUserMedia.bind(r.navigator.mediaDevices),i=r.AudioContext??r.webkitAudioContext;if(!s||!i)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const g=await s({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),p=new i,l=p.createMediaStreamSource(g),k=p.createScriptProcessor(4096,1,1);let v=!1,w=!1,c=0,o=0;return k.onaudioprocess=u=>{const d=u.inputBuffer.getChannelData(0),f=v?0:j(d);if(e.onLevel(f),v)return;if(e.onAudio(z(d,p.sampleRate)),e.isTurnActive()){o=f>=e.interruptThreshold?o+1:0,o>=e.interruptChunks&&(o=0,e.onInterrupt());return}o=0;const S=d.length/p.sampleRate*1e3;if(f>=e.silenceThreshold){w=!0,c=0;return}w&&(c+=S,c>=e.silenceDurationMs&&(w=!1,c=0,e.onSilence()))},l.connect(k),k.connect(p.destination),{setMuted:u=>{v=u},stop:()=>{k.disconnect(),l.disconnect();for(const u of g.getTracks())u.stop();p.close()}}},Y=()=>{const e=globalThis,r=e.AudioContext??e.webkitAudioContext;if(!r)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const s=new r,i=new Set;let g=0,p=Promise.resolve(),l=0;const k=async(c,o)=>{if(o!==l)return;let u;try{u=await s.decodeAudioData(c.buffer)}catch{return}if(o!==l)return;const d=s.createBufferSource();d.buffer=u,d.connect(s.destination);const f=Math.max(s.currentTime,g);d.start(f),g=f+u.duration,i.add(d),d.onended=()=>{i.delete(d)}},v=c=>{const o=Uint8Array.from(c),u=l;p=p.then(()=>k(o,u))},w=()=>{l+=1;for(const c of i)try{c.stop()}catch{}i.clear(),g=s.currentTime};return{enqueue:v,interrupt:w,stop:()=>{w(),s.close()}}},U=1,Z=.01,ee=1200,te=.15,ne=3,ae=e=>{const{createMicrophone:r=Q,createSpeaker:s=Y,createSocket:i,interruptChunks:g=ne,interruptThreshold:p=te,silenceDurationMs:l=ee,silenceThreshold:k=Z,threadKey:v,voice:w}=e,c=P(),o=y("idle"),u=y(!1),d=y(""),f=y(""),S=y(0),C=y(!1),m=y(void 0);let a,b=!1;const _=t=>{const n=a?.socket;return n?.readyState===U?(n.send(JSON.stringify(t)),!0):!1},T=()=>{const t=a;if(a=void 0,t){t.unwatchIdentity?.(),t.microphone?.stop(),t.speaker?.stop(),t.socket.onmessage=null,t.socket.onerror=null,t.socket.onclose=null;try{t.socket.close()}catch{}}b=!1,u.value=!1,o.value="idle",S.value=0},R=T,D=t=>{const n=a;switch(t.type){case"assistant_delta":{n&&(n.speaking=!0),o.value="speaking",f.value+=t.text;break}case"assistant_done":{n&&(n.awaitingTurn=!1,n.speaking=!1),f.value=t.text,o.value="listening";break}case"error":{n&&(n.awaitingTurn=!1,n.speaking=!1),m.value=new Error(t.message),o.value="listening";break}case"interrupted":{n&&(n.awaitingTurn=!1,n.speaking=!1,n.suppressAudio=!1),n?.speaker?.interrupt(),o.value="listening";break}case"ready":{n&&(n.audioFormat=t.audioFormat,n.suppressAudio=!1),u.value=!0,o.value="listening";break}case"user_transcript":{n&&(n.suppressAudio=!1),d.value=t.text,f.value="",o.value="thinking";break}}},L=t=>{const n=a;!n||n.suppressAudio||(n.speaker??=s({audioFormat:n.audioFormat}),n.speaking=!0,o.value="speaking",n.speaker.enqueue(t))},V=async()=>{if(a||b)return;b=!0,m.value=void 0,d.value="",f.value="";let t;try{const n=q({agent:B(w.__lunoraRef),httpUrl:c.url,threadKey:O(v),wsUrl:c.wsUrl}),A=(i??(h=>{const E=c.getWebSocketImpl();if(!E)throw new Error("useVoiceAgent: no WebSocket implementation available (pass createSocket explicitly)");return new E(h)}))(n);A.binaryType="arraybuffer",t={audioFormat:"mp3",microphone:void 0,socket:A,speaker:void 0,speaking:!1,awaitingTurn:!1,suppressAudio:!1,unwatchIdentity:void 0},a=t,t.unwatchIdentity=G(c,"useVoiceAgent",h=>{a===t&&(m.value=h,T())}),A.onmessage=h=>{if(typeof h.data=="string"){try{D(JSON.parse(h.data))}catch{}return}L(new Uint8Array(h.data))},A.onerror=()=>{m.value=new Error("useVoiceAgent: voice socket error")},A.onclose=h=>{if(a!==t)return;const E=J("useVoiceAgent",h);E&&(m.value=E),T()};const x=await r({interruptChunks:g,interruptThreshold:p,isTurnActive:()=>(a?.speaking??!1)||(a?.awaitingTurn??!1),onAudio:h=>{A.readyState===U&&A.send(h)},onInterrupt:()=>{_({type:"interrupt"}),a?.speaker?.interrupt(),a&&(a.awaitingTurn=!1,a.speaking=!1,a.suppressAudio=!0),o.value="listening"},onLevel:h=>{S.value=h},onSilence:()=>{_({type:"commit"}),a&&(a.awaitingTurn=!0),o.value="thinking"},silenceDurationMs:l,silenceThreshold:k});a===t?(t.microphone=x,C.value=!1,t.speaking||(o.value="listening")):x.stop()}catch(n){a===t&&(m.value=n instanceof Error?n:new Error(String(n)),T())}finally{b=!1}},F=()=>{const t=!C.value;return a?.microphone?.setMuted(t),C.value=t,t},W=t=>{_({text:t,type:"text"})&&(a&&(a.awaitingTurn=!0),o.value="thinking")};return N(T),{audioLevel:S,connected:u,endCall:R,error:m,interimTranscript:f,isMuted:C,sendText:W,startCall:V,status:o,toggleMute:F,transcript:d}};export{ae as useVoiceAgent};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/vue",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.114",
|
|
4
4
|
"description": "Vue adapter for Lunora — live composables, optimistic mutations, and reactive loaders",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@lunora/client": "1.0.0-alpha.
|
|
58
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
59
|
-
"@lunora/ratelimit": "1.0.0-alpha.
|
|
57
|
+
"@lunora/client": "1.0.0-alpha.79",
|
|
58
|
+
"@lunora/errors": "1.0.0-alpha.32",
|
|
59
|
+
"@lunora/ratelimit": "1.0.0-alpha.39",
|
|
60
60
|
"@visulima/storage-client": "1.0.2"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{shallowRef as _,watch as v,toValue as j,onScopeDispose as V,computed as E}from"vue";import{initialPages as $,derivePaginationStatus as D,rebalance as q,applyLoadMore as z}from"@lunora/client/pagination";import{i as G}from"./is-browser-BEdfLJHK.mjs";import{useLunora as H}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const X=/["\\\u0000-\u001F\uD800-\uDFFF]/,T=e=>X.test(e)?JSON.stringify(e):`"${e}"`,x=e=>{if(e===void 0)return"null";if(typeof e=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(typeof e=="number"){if(Number.isNaN(e))return"nan";if(e===1/0)return"inf";if(e===-1/0)return"-inf";if(Object.is(e,-0))return"-0"}if(typeof e=="string")return T(e);if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e)){let o="[";for(let r=0;r<e.length;r++)r>0&&(o+=","),o+=x(e[r]);return o+"]"}const n=Object.getPrototypeOf(e);if(n!==null&&n!==Object.prototype){const o=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${o} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const d=e,u=Object.keys(d).sort();let a="{",t=!0;for(const o of u){const r=d[o];r!==void 0&&(t?t=!1:a+=",",a+=T(o),a+=":",a+=x(r))}return a+"}"},F=e=>{let n="";for(let u=0;u<e.length;u+=32768)n+=String.fromCharCode(...e.subarray(u,u+32768));return btoa(n)},l="$lunora.wire$",U=64,Y="__proto__",Z=e=>{if(e===null||typeof e!="object")return!1;const n=Object.getPrototypeOf(e);return n===null||n===Object.prototype},S=(e,n=0)=>{if(n>U)throw new RangeError(`wire-codec: value nesting exceeds the ${U}-level limit`);if(e===void 0)return[l,"undefined"];if(e===null)return null;const d=typeof e;if(d==="bigint")return[l,"bigint",e.toString()];if(d==="number"){const t=e;return Number.isNaN(t)?[l,"nan"]:t===1/0?[l,"inf"]:t===-1/0?[l,"-inf"]:t}if(d!=="object")return e;if(e instanceof Date)return[l,"date",S(e.getTime(),n+1)];if(e instanceof Error){const t=e,o={};for(const y of Object.keys(t))t[y]!==void 0&&(o[y]=S(t[y],n+1));const r=[l,"error",t.name,t.message,o];return t.cause!==void 0&&r.push(S(t.cause,n+1)),r}if(e instanceof URL)return[l,"url",e.href];if(e instanceof Map)return[l,"map",[...e.entries()].map(([t,o])=>[S(t,n+1),S(o,n+1)])];if(e instanceof Set)return[l,"set",[...e].map(t=>S(t,n+1))];if(e instanceof ArrayBuffer)return[l,"bytes",F(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,o=t.constructor.name,r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return o==="Uint8Array"?[l,"bytes",F(r)]:[l,"bytes",F(r),o]}if(Array.isArray(e)){const t=e.map(o=>S(o,n+1));return t.length>0&&t[0]===l?[l,"arr",t]:t}if(!Z(e)){const t=e.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${t} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const u=e,a={};for(const t of Object.keys(u)){const o=u[t];if(o===void 0)continue;const r=S(o,n+1);t===Y?Object.defineProperty(a,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):a[t]=r}return a},J=e=>x(S(e)),A=(e,n)=>`${e}::${J(n)}`,M=(e,n)=>({...n,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),W=(e,n,d)=>{const u=H(),{initialNumItems:a,onError:t,shardKey:o}=d,r=_($(a)),y=_([]),P=_(void 0);let R;const w=new Map,b=new Map,m=new Set,K=(s,i)=>{y.value=s.map(h=>{const f=A(e.__lunoraRef,M(h,i));return b.get(f)})},Q=(s,i,h)=>{const f=p=>A(e.__lunoraRef,M(p,h));for(const p of i){const g=f(p);if(b.has(g))continue;const O=s.find(c=>c.lower===p.lower);if(O){const c=b.get(f(O));c&&b.set(g,c)}}},C=(s,i)=>{const h=new Set;for(const f of s)h.add(A(e.__lunoraRef,M(f,i)));for(const[f,p]of w)h.has(f)||(p(),w.delete(f),b.delete(f),m.delete(f));for(const f of s){const p=M(f,i),g=A(e.__lunoraRef,p);if(w.has(g))continue;m.add(g);const O=u.subscribe(e,p,c=>{b.set(g,c),m.delete(g),P.value=void 0;const k=j(n);if(K(r.value,k),m.size===0){const N=r.value,L=q(N,y.value);L&&(Q(N,L,k),r.value=L)}},{onError:c=>{m.delete(g),P.value=c;const k=r.value,N=k.at(-1);k.length>1&&N&&!b.has(g)&&A(e.__lunoraRef,M(N,i))===g&&(r.value=k.slice(0,-1)),t?.(c)},shardKey:o});w.set(g,O)}},I=()=>{for(const s of w.values())s();w.clear(),b.clear(),m.clear()};v(()=>J(j(n)),()=>{if(!G())return;const s=j(n);I(),r.value=$(a),y.value=[],P.value=void 0,R=void 0,s!=="skip"&&(C(r.value,s),K(r.value,s))},{immediate:!0}),v(()=>r.value,s=>{const i=j(n);R=void 0,i!=="skip"&&(C(s,i),K(s,i))}),V(I);const B=_("LoadingFirstPage");return v([()=>j(n),y],([s,i])=>{B.value=D(s==="skip",i).status},{immediate:!0}),{error:P,loadMore:s=>{const i=j(n);if(i==="skip")return;const{nextCursor:h,status:f}=D(!1,y.value);if(f!=="CanLoadMore"||h===R)return;const p=z(r.value,h,s);if(!p)return;R=h,P.value=void 0;const g=r.value.at(-1),O=p.at(-2);if(g&&O){const c=A(e.__lunoraRef,M(g,i)),k=A(e.__lunoraRef,M(O,i)),N=w.get(c);if(N&&c!==k){const L=b.get(c);L&&b.set(k,L),N(),w.delete(c),b.delete(c),m.delete(c)}}r.value=p},pageResults:y,status:B}},se=(e,n,d)=>{const{error:u,loadMore:a,pageResults:t,status:o}=W(e,n,d),r=E(()=>t.value.flatMap(P=>P?.page??[])),y=E(()=>o.value==="LoadingFirstPage"||o.value==="LoadingMore");return{error:u,isLoading:y,loadMore:a,results:r,status:o}},ie=(e,n,d)=>{const{initialNumItems:u}=d,{error:a,loadMore:t,pageResults:o,status:r}=W(e,n,d),y=E(()=>o.value.flatMap(m=>m?[m.page]:[])),P=E(()=>r.value==="LoadingFirstPage"),R=E(()=>r.value==="CanLoadMore"),w=E(()=>r.value==="LoadingMore");return{error:a,fetchNextPage:m=>{t(m??u)},hasNextPage:R,isFetchingNextPage:w,isLoading:P,pages:y,status:r}};export{ie as useInfiniteQuery,se as usePaginatedQuery};
|
|
@@ -1 +0,0 @@
|
|
|
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};
|