@lunora/react 1.0.0-alpha.83 → 1.0.0-alpha.85
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/cache-BSBhN-M2.mjs +1 -0
- package/dist/packem_shared/{hydratePreloaded-o9sDozdc.mjs → hydratePreloaded-C9nnbvjN.mjs} +1 -1
- package/dist/packem_shared/use-paginated-core-CZ3gyax5.mjs +2 -0
- package/dist/packem_shared/useHttpStream-BzG5kdmo.mjs +2 -0
- package/dist/packem_shared/{useInfiniteQuery-KtrRC-3l.mjs → useInfiniteQuery-DFYRAWUe.mjs} +1 -1
- package/dist/packem_shared/{usePaginatedQuery-Bqgqg19J.mjs → usePaginatedQuery-BSJBNGSX.mjs} +1 -1
- package/dist/packem_shared/{useQuery-8ecExZyF.mjs → useQuery-TQiduIxH.mjs} +1 -1
- package/dist/packem_shared/useVoiceAgent-DHdUlo0G.mjs +2 -0
- package/package.json +4 -4
- package/dist/packem_shared/cache-BN5T8cAI.mjs +0 -1
- package/dist/packem_shared/use-paginated-core-CaKTWQBk.mjs +0 -2
- package/dist/packem_shared/useHttpStream-D9vum8Qx.mjs +0 -2
- package/dist/packem_shared/useVoiceAgent-C9NI6Vzl.mjs +0 -2
package/dist/index.d.mts
CHANGED
|
@@ -1230,8 +1230,24 @@ interface MicrophoneConfig {
|
|
|
1230
1230
|
interruptChunks: number;
|
|
1231
1231
|
/** RMS above which the user is considered to be barging in while the agent speaks. */
|
|
1232
1232
|
interruptThreshold: number;
|
|
1233
|
-
/**
|
|
1234
|
-
|
|
1233
|
+
/**
|
|
1234
|
+
* `true` from the moment a turn is committed until it completes — the whole
|
|
1235
|
+
* `thinking` + `speaking` window, not just the audible half.
|
|
1236
|
+
*
|
|
1237
|
+
* It gates BOTH branches below, and the wider span is the point. Gated only
|
|
1238
|
+
* on "audibly speaking", turn detection kept running through the entire
|
|
1239
|
+
* STT+LLM window after a `commit`: room noise at the (deliberately low)
|
|
1240
|
+
* `silenceThreshold` re-armed `sawSpeech`, another quiet gap fired a SECOND
|
|
1241
|
+
* `commit`, and the DO refused it with "a turn is already in progress" —
|
|
1242
|
+
* a refusal that returns before draining the audio buffer, so the PCM
|
|
1243
|
+
* captured since the first commit leaked into the next utterance.
|
|
1244
|
+
*
|
|
1245
|
+
* A genuine barge-in still works in that window: it routes through the
|
|
1246
|
+
* `onInterrupt` branch, which needs `interruptChunks` consecutive chunks at
|
|
1247
|
+
* `interruptThreshold` — an order of magnitude above `silenceThreshold` —
|
|
1248
|
+
* and `interrupt` is exactly what the DO tells the client to send.
|
|
1249
|
+
*/
|
|
1250
|
+
isTurnActive: () => boolean;
|
|
1235
1251
|
/** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
|
|
1236
1252
|
onAudio: (pcm: Uint8Array) => void;
|
|
1237
1253
|
/** A barge-in was detected (RMS spike while the agent is speaking). */
|
package/dist/index.d.ts
CHANGED
|
@@ -1230,8 +1230,24 @@ interface MicrophoneConfig {
|
|
|
1230
1230
|
interruptChunks: number;
|
|
1231
1231
|
/** RMS above which the user is considered to be barging in while the agent speaks. */
|
|
1232
1232
|
interruptThreshold: number;
|
|
1233
|
-
/**
|
|
1234
|
-
|
|
1233
|
+
/**
|
|
1234
|
+
* `true` from the moment a turn is committed until it completes — the whole
|
|
1235
|
+
* `thinking` + `speaking` window, not just the audible half.
|
|
1236
|
+
*
|
|
1237
|
+
* It gates BOTH branches below, and the wider span is the point. Gated only
|
|
1238
|
+
* on "audibly speaking", turn detection kept running through the entire
|
|
1239
|
+
* STT+LLM window after a `commit`: room noise at the (deliberately low)
|
|
1240
|
+
* `silenceThreshold` re-armed `sawSpeech`, another quiet gap fired a SECOND
|
|
1241
|
+
* `commit`, and the DO refused it with "a turn is already in progress" —
|
|
1242
|
+
* a refusal that returns before draining the audio buffer, so the PCM
|
|
1243
|
+
* captured since the first commit leaked into the next utterance.
|
|
1244
|
+
*
|
|
1245
|
+
* A genuine barge-in still works in that window: it routes through the
|
|
1246
|
+
* `onInterrupt` branch, which needs `interruptChunks` consecutive chunks at
|
|
1247
|
+
* `interruptThreshold` — an order of magnitude above `silenceThreshold` —
|
|
1248
|
+
* and `interrupt` is exactly what the DO tells the client to send.
|
|
1249
|
+
*/
|
|
1250
|
+
isTurnActive: () => boolean;
|
|
1235
1251
|
/** One 16 kHz mono 16-bit little-endian PCM frame captured from the mic. */
|
|
1236
1252
|
onAudio: (pcm: Uint8Array) => void;
|
|
1237
1253
|
/** A barge-in was detected (RMS spike while the agent is speaking). */
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import{AuthLoading as o,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-dC08yqew.mjs";import{useAuthState as a}from"./packem_shared/useAuthState-CoOG9XdT.mjs";import{LunoraProvider as n,useLunora as f}from"./packem_shared/LunoraProvider-DC06S-p1.mjs";import{lunoraQueryOptions as m}from"./packem_shared/lunoraQueryOptions-Celdopal.mjs";import{useAction as x}from"./packem_shared/useAction-CUSJu4yq.mjs";import{useAuthSessions as g,useAuthUsers as A,useImpersonate as h,useOrganizations as U,useSignUpInvitations as c}from"./packem_shared/useAuthSessions-gBDeNFnd.mjs";import{useAgent as C}from"./packem_shared/useAgent-BOOybemP.mjs";import{useAgentChat as S}from"./packem_shared/useAgentChat-PB0upmu5.mjs";import{useAgentState as P}from"./packem_shared/useAgentState-DcSalToC.mjs";import{useAgentToolEvents as R}from"./packem_shared/useAgentToolEvents-Lg1sM60_.mjs";import{default as I}from"./packem_shared/useAuth-x4boOoAR.mjs";import{default as v}from"./packem_shared/useClientQuery-DFs7trEf.mjs";import{default as z}from"./packem_shared/useConnectionStatus-XYsYGiT6.mjs";import{useFlag as T,useFlags as k}from"./packem_shared/useFlag-BDM923ke.mjs";import{useHttpStream as V}from"./packem_shared/useHttpStream-
|
|
2
|
+
import{AuthLoading as o,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-dC08yqew.mjs";import{useAuthState as a}from"./packem_shared/useAuthState-CoOG9XdT.mjs";import{LunoraProvider as n,useLunora as f}from"./packem_shared/LunoraProvider-DC06S-p1.mjs";import{lunoraQueryOptions as m}from"./packem_shared/lunoraQueryOptions-Celdopal.mjs";import{useAction as x}from"./packem_shared/useAction-CUSJu4yq.mjs";import{useAuthSessions as g,useAuthUsers as A,useImpersonate as h,useOrganizations as U,useSignUpInvitations as c}from"./packem_shared/useAuthSessions-gBDeNFnd.mjs";import{useAgent as C}from"./packem_shared/useAgent-BOOybemP.mjs";import{useAgentChat as S}from"./packem_shared/useAgentChat-PB0upmu5.mjs";import{useAgentState as P}from"./packem_shared/useAgentState-DcSalToC.mjs";import{useAgentToolEvents as R}from"./packem_shared/useAgentToolEvents-Lg1sM60_.mjs";import{default as I}from"./packem_shared/useAuth-x4boOoAR.mjs";import{default as v}from"./packem_shared/useClientQuery-DFs7trEf.mjs";import{default as z}from"./packem_shared/useConnectionStatus-XYsYGiT6.mjs";import{useFlag as T,useFlags as k}from"./packem_shared/useFlag-BDM923ke.mjs";import{useHttpStream as V}from"./packem_shared/useHttpStream-BzG5kdmo.mjs";import{default as q}from"./packem_shared/useInfiniteQuery-DFYRAWUe.mjs";import{useMutation as B}from"./packem_shared/useMutation-BnKec7bE.mjs";import{useMutator as G}from"./packem_shared/useMutator-BtUd-xEA.mjs";import{usePaginatedQuery as K}from"./packem_shared/usePaginatedQuery-BSJBNGSX.mjs";import{hydratePreloaded as W,default as X}from"./packem_shared/hydratePreloaded-C9nnbvjN.mjs";import{usePresence as Z}from"./packem_shared/usePresence-BVjZyltT.mjs";import{default as $}from"./packem_shared/useQuery-TQiduIxH.mjs";import{useRateLimit as re}from"./packem_shared/useRateLimit-Cckxi8m9.mjs";import{useStream as te}from"./packem_shared/useStream-MdOMnlR8.mjs";import{default as se}from"./packem_shared/useSubscription-B9rxVLlG.mjs";import{useVoiceAgent as pe}from"./packem_shared/useVoiceAgent-DHdUlo0G.mjs";import{createClientQuery as fe,getErrorCode as ie,getRetryAfterMs as me,isConflictError as de,isForbiddenError as xe,isRateLimitedError as le,isUnauthorizedError as ge}from"@lunora/client";import{RestrictionError as he,UploadControl as Ue,UploadError as ce}from"@visulima/storage-client";import{useChunkedRestUpload as Ce,useFileInput as Ee,useMultipartUpload as Se,usePasteUpload as Qe,useTusUpload as Pe,useUpload as Le}from"@visulima/storage-client/react";export{o as AuthLoading,t as Authenticated,n as LunoraProvider,he as RestrictionError,u as Unauthenticated,Ue as UploadControl,ce as UploadError,fe as createClientQuery,ie as getErrorCode,me as getRetryAfterMs,W as hydratePreloaded,de as isConflictError,xe as isForbiddenError,le as isRateLimitedError,ge as isUnauthorizedError,m as lunoraQueryOptions,x as useAction,C as useAgent,S as useAgentChat,P as useAgentState,R as useAgentToolEvents,I as useAuth,g as useAuthSessions,a as useAuthState,A as useAuthUsers,Ce as useChunkedRestUpload,v as useClientQuery,z as useConnectionStatus,Ee as useFileInput,T as useFlag,k as useFlags,V as useHttpStream,h as useImpersonate,q as useInfiniteQuery,f as useLunora,Se as useMultipartUpload,B as useMutation,G as useMutator,U as useOrganizations,K as usePaginatedQuery,Qe as usePasteUpload,X as usePreloadedQuery,Z as usePresence,$ as useQuery,re as useRateLimit,c as useSignUpInvitations,te as useStream,se as useSubscription,Pe as useTusUpload,Le as useUpload,pe as useVoiceAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{k as a}from"./query-key-BFaqaQy8.mjs";class d{constructor(e){this.client=e}client;entries=new Map;keyOf(e){return a(e)}hasConsumers(e){return this.entries.has(a(e))}attach(e,c,f,b,h,k={}){const s=a(c);let r=this.entries.get(s);if(!r){r={errorCallbacks:new Set,refCount:0,unsubscribe:void 0},this.entries.set(s,r);const t=r;try{r.unsubscribe=this.client.subscribe(f,b,n=>{e.setQueryData(c,n)},{onError:n=>{for(const C of t.errorCallbacks)C(n)},shardKey:h})}catch(n){throw this.entries.delete(s),n}}r.refCount+=1;const{onError:o}=k;o&&r.errorCallbacks.add(o);let u=!1;return()=>{if(u)return;u=!0;const t=this.entries.get(s);t&&(t.refCount-=1,o&&t.errorCallbacks.delete(o),t.refCount<=0&&(t.unsubscribe?.(),this.entries.delete(s)))}}}const l=new WeakMap,y=i=>{let e=l.get(i);return e||(e=new d(i),l.set(i,e)),e};export{y as g};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import{c as _}from"react/compiler-runtime";import{useQueryClient as b,useQuery as q}from"@tanstack/react-query";import{useRef as K,useEffect as Q}from"react";import{g as P}from"./cache-
|
|
2
|
+
import{c as _}from"react/compiler-runtime";import{useQueryClient as b,useQuery as q}from"@tanstack/react-query";import{useRef as K,useEffect as Q}from"react";import{g as P}from"./cache-BSBhN-M2.mjs";import{useLunora as v}from"./LunoraProvider-DC06S-p1.mjs";import{l as N,s as S}from"./query-key-BFaqaQy8.mjs";const T=function(a,e){const r=_(9);let o;r[0]!==e?(o=e===void 0?{}:e,r[0]=e,r[1]=o):o=r[1];const n=o,t=v(),s=b(),p=K(n.onError);let i;r[2]!==n.onError?(i=()=>{p.current=n.onError},r[2]=n.onError,r[3]=i):i=r[3],Q(i);let u;r[4]===Symbol.for("react.memo_cache_sentinel")?(u=I=>{p.current?.(I)},r[4]=u):u=r[4];const E=u,{args:l,functionPath:R,shardKey:f,value:g}=a,y={__lunoraRef:R},m=N(y,l,f),{data:h}=q({initialData:g,queryFn:()=>t.query(y,l,{shardKey:f}),queryKey:m,staleTime:Number.POSITIVE_INFINITY}),d=S(m);let c;return r[5]!==t||r[6]!==s||r[7]!==d?(c=[t,s,d,E],r[5]=t,r[6]=s,r[7]=d,r[8]=c):c=r[8],Q(()=>P(t).attach(s,m,y,l,f,{onError:E}),c),h===void 0?g:h},L=function(a,e={}){return T(a,e)};export{T as default,L as hydratePreloaded};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{initialPages as N,rebalance as j,derivePaginationStatus as O,applyLoadMore as H}from"@lunora/client/pagination";import{useQueryClient as V}from"@tanstack/react-query";import{useRef as h,useReducer as Y,useState as T,useEffect as d,useCallback as B}from"react";import{g as G}from"./cache-BSBhN-M2.mjs";import{useLunora as J}from"./LunoraProvider-DC06S-p1.mjs";import{s as c,l as I}from"./query-key-BFaqaQy8.mjs";const U=function(u){const m=h(void 0);return m.current??=u(),m},te=function(u,m,R){const i=J(),a=V(),{initialNumItems:Q,shardKey:g}=R,y=m==="skip",p=y?{}:m,[,D]=Y(e=>e+1,0),[A,K]=T(()=>N(Q)),[z,k]=T(void 0),P=h(R.onError);d(()=>{P.current=R.onError});const q=`${c(I(u,p,g))}::${String(Q)}`,x=h(q);x.current!==q&&(x.current=q,K(N(Q)),k(void 0));const b=A.map(e=>{const r={...p,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}},t=I(u,r,g);return{args:r,key:t}}),F=b.map(({key:e})=>c(e)).join("|"),v=h({baseArgs:p,entries:[],fn:u,shardKey:g});d(()=>{v.current={baseArgs:p,entries:b,fn:u,shardKey:g}});const L=(e,r,t)=>{k(t),K(o=>{const s=v.current,n=o.at(-1);if(o.length<=1||!n||a.getQueryData(r)!==void 0)return o;const w={...s.baseArgs,paginationOpts:{cursor:n.lower,endCursor:n.upper,numItems:n.numItems}};return c(I(s.fn,w,s.shardKey))===e?o.slice(0,-1):o}),P.current?.(t)},E=U(()=>new Map),M=h(i);d(()=>{const e=E.current;if(M.current!==i){for(const s of e.values())s();e.clear(),M.current=i}if(y){for(const s of e.values())s();e.clear();return}const r=v.current,t=G(i),o=new Set(r.entries.map(({key:s})=>c(s)));for(const[s,n]of e)o.has(s)||(n(),e.delete(s));for(const s of r.entries){const n=c(s.key);if(e.has(n))continue;a.fetchQuery({gcTime:Number.POSITIVE_INFINITY,queryFn:()=>i.query(r.fn,s.args,{shardKey:r.shardKey}),queryKey:s.key,staleTime:0}).catch(f=>{L(n,s.key,f instanceof Error?{code:f.code,message:f.message}:{message:String(f)})});const l=t.attach(a,s.key,r.fn,s.args,r.shardKey,{onError:f=>{L(n,s.key,f)}}),C=s.key;e.set(n,()=>{l(),t.hasConsumers(C)||a.removeQueries({exact:!0,queryKey:C})})}},[i,a,F,y]),d(()=>()=>{for(const e of E.current.values())e();E.current.clear()},[]),d(()=>a.getQueryCache().subscribe(t=>{if(t.type!=="updated")return;const o=c(t.query.queryKey);b.some(({key:s})=>c(s)===o)&&(k(void 0),D())}),[a,F]);const S=y?[]:b.map(({key:e})=>a.getQueryData(e));d(()=>{if(y)return;const e=j(A,S);e&&K(e)});const{status:_}=O(y,S),$=B(e=>{k(void 0),K(r=>{const t=v.current,o=r.map(l=>{const C={...t.baseArgs,paginationOpts:{cursor:l.lower,endCursor:l.upper,numItems:l.numItems}};return a.getQueryData(I(t.fn,C,t.shardKey))}),{nextCursor:s,status:n}=O(!1,o);return H(r,n==="CanLoadMore"?s:void 0,e)??r})},[a]);return{error:z,loadMore:$,pageResults:S,status:_}};export{te as u};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{c as S}from"react/compiler-runtime";import{useReducer as _,useRef as v,useEffect as R}from"react";import{useLunora as b}from"./LunoraProvider-DC06S-p1.mjs";import{s as z,c as E}from"./stream-state-abygFxmy.mjs";import{s as H}from"./wire-key-DhthMX_1.mjs";const w=(t,c,n)=>{const e=S(24);let m;e[0]!==n?(m=n===void 0?{}:n,e[0]=n,e[1]=m):m=e[1];const o=m,f=b();let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a={chunks:[],error:void 0,status:"idle"},e[2]=a):a=e[2];const[s,i]=_(z,a),r=c==="skip";let l;e[3]!==c||e[4]!==r?(l=r?"skip":H(c),e[3]=c,e[4]=r,e[5]=l):l=e[5];const k=l,x=v(void 0);let u;e[6]!==c||e[7]!==f||e[8]!==o.maxBuffer||e[9]!==t||e[10]!==r?(u=()=>{if(r)return i({type:"reset"}),K;i({type:"reset"}),i({type:"start"});const{cancel:B,cleanup:y}=E(f.httpStream(t,c,{maxBuffer:o.maxBuffer}),i);return x.current=B,()=>{y(),x.current=void 0}},e[6]=c,e[7]=f,e[8]=o.maxBuffer,e[9]=t,e[10]=r,e[11]=u):u=e[11];let p;e[12]!==f||e[13]!==o.maxBuffer||e[14]!==t.method||e[15]!==t.path||e[16]!==k||e[17]!==r?(p=[f,t.method,t.path,k,r,o.maxBuffer],e[12]=f,e[13]=o.maxBuffer,e[14]=t.method,e[15]=t.path,e[16]=k,e[17]=r,e[18]=p):p=e[18],R(u,p);let h;e[19]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{x.current?.()},e[19]=h):h=e[19];let d;return e[20]!==s.chunks||e[21]!==s.error||e[22]!==s.status?(d={cancel:h,chunks:s.chunks,error:s.error,status:s.status},e[20]=s.chunks,e[21]=s.error,e[22]=s.status,e[23]=d):d=e[23],d};function K(){}export{w as useHttpStream};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import{c as M}from"react/compiler-runtime";import{useRef as R,useEffect as y}from"react";import{u as C}from"./use-paginated-core-
|
|
2
|
+
import{c as M}from"react/compiler-runtime";import{useRef as R,useEffect as y}from"react";import{u as C}from"./use-paginated-core-CZ3gyax5.mjs";const v=(x,c,N)=>{const e=M(16),{initialNumItems:s}=N,{error:u,loadMore:o,pageResults:m,status:a}=C(x,c==="skip"?"skip":c,N),P=c==="skip";let t;if(e[0]!==m){t=[];for(const f of m)f&&t.push(f.page);e[0]=m,e[1]=t}else t=e[1];let i;e[2]!==s||e[3]!==o?(i={defaultNumItems:s,loadMore:o},e[2]=s,e[3]=o,e[4]=i):i=e[4];const h=R(i);let n;e[5]!==s||e[6]!==o?(n=()=>{h.current={defaultNumItems:s,loadMore:o}},e[5]=s,e[6]=o,e[7]=n):n=e[7],y(n);let r;e[8]===Symbol.for("react.memo_cache_sentinel")?(r=f=>{const{defaultNumItems:k,loadMore:L}=h.current;L(f??k)},e[8]=r):r=e[8];const I=r,d=a==="CanLoadMore",p=!P&&a==="LoadingMore",g=!P&&a==="LoadingFirstPage";let l;return e[9]!==u||e[10]!==t||e[11]!==a||e[12]!==d||e[13]!==p||e[14]!==g?(l={error:u,fetchNextPage:I,hasNextPage:d,isFetchingNextPage:p,isLoading:g,pages:t,status:a},e[9]=u,e[10]=t,e[11]=a,e[12]=d,e[13]=p,e[14]=g,e[15]=l):l=e[15],l};export{v as default};
|
package/dist/packem_shared/{usePaginatedQuery-Bqgqg19J.mjs → usePaginatedQuery-BSJBNGSX.mjs}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import{c}from"react/compiler-runtime";import{u as f}from"./use-paginated-core-
|
|
2
|
+
import{c}from"react/compiler-runtime";import{u as f}from"./use-paginated-core-CZ3gyax5.mjs";const L=(d,i,l)=>{const e=c(8),{error:r,loadMore:p,pageResults:n,status:t}=f(d,i==="skip"?"skip":i,l);let s;if(e[0]!==n){s=[];for(const u of n)u&&s.push(...u.page);e[0]=n,e[1]=s}else s=e[1];const a=!(i==="skip")&&(t==="LoadingFirstPage"||t==="LoadingMore");let o;return e[2]!==r||e[3]!==p||e[4]!==s||e[5]!==t||e[6]!==a?(o={error:r,isLoading:a,loadMore:p,results:s,status:t},e[2]=r,e[3]=p,e[4]=s,e[5]=t,e[6]=a,e[7]=o):o=e[7],o};export{L as usePaginatedQuery};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import{useQueryClient as h,useQuery as E}from"@tanstack/react-query";import{useRef as b,useEffect as n,useCallback as g,useState as I}from"react";import{g as k}from"./cache-
|
|
2
|
+
import{useQueryClient as h,useQuery as E}from"@tanstack/react-query";import{useRef as b,useEffect as n,useCallback as g,useState as I}from"react";import{g as k}from"./cache-BSBhN-M2.mjs";import{useLunora as q}from"./LunoraProvider-DC06S-p1.mjs";import{l as K,s as C}from"./query-key-BFaqaQy8.mjs";const F=(t,i,p={})=>{const e=q(),y=h(),{onError:c,shardKey:s}=p,d=b(c);n(()=>{d.current=c});const l=g(m=>{d.current?.(m)},[]),r=i==="skip",o=r?{}:i,a=K(t,o,s),[u,f]=I(e.isReady);n(()=>{u||e.whenReady().then(()=>{f(!0)})},[e,u]);const Q=r?void 0:e.peekHydratedQuery(t.__lunoraRef,o,s),{data:R}=E({enabled:!r&&u,initialData:Q,queryFn:()=>e.query(t,o,{shardKey:s}),queryKey:a,staleTime:Number.POSITIVE_INFINITY});return n(()=>r?()=>{}:k(e).attach(y,a,t,o,s,{onError:l}),[e,y,C(a),r,l]),r?void 0:R};export{F as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import{useState as T,useRef as W,useCallback as y,useEffect as G}from"react";import{useLunora as X}from"./LunoraProvider-DC06S-p1.mjs";const N="/_lunora/ws",j="/_lunora/voice/",z=4001,O=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,Q=e=>{const r=e.startsWith("agents:")?e.slice(7):e;return r.endsWith("Voice")?r.slice(0,-5):r},Y=(e,r)=>{if(r===void 0||r==="")return O(e);if(r.endsWith(N))return r.slice(0,-N.length);try{return new URL(r).origin}catch{return O(e)}},Z=e=>{const r=Y(e.httpUrl,e.wsUrl),o=r.endsWith("/")?r.slice(0,-1):r,i=new URLSearchParams({threadKey:e.threadKey});return`${o}${j}${encodeURIComponent(e.agent)}?${i.toString()}`},ee=(e,r)=>{if(r?.code===z)return new Error(`${e}: authentication token expired — refresh the credential and start a new call`)},te=(e,r,o)=>{const i=e.currentIdentity();return e.onAuthTokenChange(()=>{e.currentIdentity()!==i&&o(new Error(`${r}: the signed-in identity changed during the call — the session was ended; start a new call`))})},ne=16e3,re=e=>{if(e.length===0)return 0;let r=0;for(const o of e)r+=o*o;return Math.sqrt(r/e.length)},oe=(e,r)=>{const o=r/ne,i=o>1?Math.floor(e.length/o):e.length,d=new ArrayBuffer(i*2),l=new DataView(d);for(let u=0;u<i;u+=1){const g=e[Math.floor(u*o)]??0,p=Math.max(-1,Math.min(1,g));l.setInt16(u*2,p<0?p*32768:p*32767,!0)}return new Uint8Array(d)},se=async e=>{const r=globalThis,o=r.navigator?.mediaDevices?.getUserMedia.bind(r.navigator.mediaDevices),i=r.AudioContext??r.webkitAudioContext;if(!o||!i)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const d=await o({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),l=new i,u=l.createMediaStreamSource(d),g=l.createScriptProcessor(4096,1,1);let p=!1,w=!1,a=0,h=0;return g.onaudioprocess=s=>{const f=s.inputBuffer.getChannelData(0),m=p?0:re(f);if(e.onLevel(m),p)return;if(e.onAudio(oe(f,l.sampleRate)),e.isTurnActive()){h=m>=e.interruptThreshold?h+1:0,h>=e.interruptChunks&&(h=0,e.onInterrupt());return}h=0;const x=f.length/l.sampleRate*1e3;if(m>=e.silenceThreshold){w=!0,a=0;return}w&&(a+=x,a>=e.silenceDurationMs&&(w=!1,a=0,e.onSilence()))},u.connect(g),g.connect(l.destination),{setMuted:s=>{p=s},stop:()=>{g.disconnect(),u.disconnect();for(const s of d.getTracks())s.stop();l.close()}}},ce=()=>{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,i=new Set;let d=0,l=Promise.resolve(),u=0;const g=async(a,h)=>{if(h!==u)return;let s;try{s=await o.decodeAudioData(a.buffer)}catch{return}if(h!==u)return;const f=o.createBufferSource();f.buffer=s,f.connect(o.destination);const m=Math.max(o.currentTime,d);f.start(m),d=m+s.duration,i.add(f),f.onended=()=>{i.delete(f)}},p=a=>{const h=Uint8Array.from(a),s=u;l=l.then(()=>g(h,s))},w=()=>{u+=1;for(const a of i)try{a.stop()}catch{}i.clear(),d=o.currentTime};return{enqueue:p,interrupt:w,stop:()=>{w(),o.close()}}},P=1,ie=.01,ae=1200,ue=.15,le=3,he=e=>{const{createMicrophone:r=se,createSpeaker:o=ce,createSocket:i,interruptChunks:d=le,interruptThreshold:l=ue,silenceDurationMs:u=ae,silenceThreshold:g=ie,threadKey:p,voice:w}=e,a=X(),[h,s]=T("idle"),[f,m]=T(!1),[x,M]=T(""),[H,b]=T(""),[$,R]=T(0),[I,U]=T(!1),[B,E]=T(void 0),c=W(void 0),_=W(!1),v=y(t=>{const n=c.current?.socket;return n?.readyState===P?(n.send(JSON.stringify(t)),!0):!1},[]),A=y(()=>{const t=c.current;if(c.current=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{}}_.current=!1,m(!1),s("idle"),R(0)},[]),L=y(t=>{const n=c.current;switch(t.type){case"assistant_delta":{n&&(n.speaking=!0),s("speaking"),b(F=>F+t.text);break}case"assistant_done":{n&&(n.awaitingTurn=!1,n.speaking=!1),b(t.text),s("listening");break}case"error":{n&&(n.awaitingTurn=!1,n.speaking=!1),E(new Error(t.message)),s("listening");break}case"interrupted":{n&&(n.awaitingTurn=!1,n.speaking=!1,n.suppressAudio=!1),n?.speaker?.interrupt(),s("listening");break}case"ready":{n&&(n.audioFormat=t.audioFormat,n.suppressAudio=!1),m(!0),s("listening");break}case"user_transcript":{n&&(n.suppressAudio=!1),M(t.text),b(""),s("thinking");break}}},[]),D=y(t=>{const n=c.current;!n||n.suppressAudio||(n.speaker??=o({audioFormat:n.audioFormat}),n.speaking=!0,s("speaking"),n.speaker.enqueue(t))},[o]),q=y(async()=>{if(c.current||_.current)return;_.current=!0,E(void 0),M(""),b("");let t;try{const n=Z({agent:Q(w.__lunoraRef),httpUrl:a.url,threadKey:p,wsUrl:a.wsUrl}),S=(i??(k=>{const C=a.getWebSocketImpl();if(!C)throw new Error("useVoiceAgent: no WebSocket implementation available (pass createSocket explicitly)");return new C(k)}))(n);S.binaryType="arraybuffer",t={audioFormat:"mp3",microphone:void 0,socket:S,speaker:void 0,speaking:!1,awaitingTurn:!1,suppressAudio:!1,unwatchIdentity:void 0},c.current=t,t.unwatchIdentity=te(a,"useVoiceAgent",k=>{c.current===t&&(E(k),A())}),S.onmessage=k=>{if(typeof k.data=="string"){try{L(JSON.parse(k.data))}catch{}return}D(new Uint8Array(k.data))},S.onerror=()=>{E(new Error("useVoiceAgent: voice socket error"))},S.onclose=k=>{if(c.current!==t)return;const C=ee("useVoiceAgent",k);C&&E(C),A()};const V=await r({interruptChunks:d,interruptThreshold:l,isTurnActive:()=>(c.current?.speaking??!1)||(c.current?.awaitingTurn??!1),onAudio:k=>{S.readyState===P&&S.send(k)},onInterrupt:()=>{v({type:"interrupt"}),c.current?.speaker?.interrupt(),c.current&&(c.current.awaitingTurn=!1,c.current.speaking=!1,c.current.suppressAudio=!0),s("listening")},onLevel:R,onSilence:()=>{v({type:"commit"}),c.current&&(c.current.awaitingTurn=!0),s("thinking")},silenceDurationMs:u,silenceThreshold:g});c.current===t?(t.microphone=V,U(!1),t.speaking||s("listening")):V.stop()}catch(n){c.current===t&&(E(n instanceof Error?n:new Error(String(n))),A())}finally{_.current=!1}},[a,r,i,D,L,d,l,v,u,g,A,p,w]),K=y(()=>{const t=!I;return c.current?.microphone?.setMuted(t),U(t),t},[I]),J=y(t=>{v({text:t,type:"text"})&&(c.current&&(c.current.awaitingTurn=!0),s("thinking"))},[v]);return G(()=>A,[A]),{audioLevel:$,connected:f,endCall:A,error:B,interimTranscript:H,isMuted:I,sendText:J,startCall:q,status:h,toggleMute:K,transcript:x}};export{he as useVoiceAgent};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/react",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.85",
|
|
4
4
|
"description": "React hooks for Lunora: useQuery, useMutation, useSubscription, and useAuth",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@lunora/client": "1.0.0-alpha.
|
|
61
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
62
|
-
"@lunora/ratelimit": "1.0.0-alpha.
|
|
60
|
+
"@lunora/client": "1.0.0-alpha.80",
|
|
61
|
+
"@lunora/errors": "1.0.0-alpha.32",
|
|
62
|
+
"@lunora/ratelimit": "1.0.0-alpha.39",
|
|
63
63
|
"@visulima/storage-client": "1.0.2"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{k as u}from"./query-key-BFaqaQy8.mjs";class g{constructor(e){this.client=e}client;entries=new Map;keyOf(e){return u(e)}attach(e,c,f,b,h,k={}){const s=u(c);let r=this.entries.get(s);if(!r){r={errorCallbacks:new Set,refCount:0,unsubscribe:void 0},this.entries.set(s,r);const t=r;try{r.unsubscribe=this.client.subscribe(f,b,n=>{e.setQueryData(c,n)},{onError:n=>{for(const d of t.errorCallbacks)d(n)},shardKey:h})}catch(n){throw this.entries.delete(s),n}}r.refCount+=1;const{onError:o}=k;o&&r.errorCallbacks.add(o);let a=!1;return()=>{if(a)return;a=!0;const t=this.entries.get(s);t&&(t.refCount-=1,o&&t.errorCallbacks.delete(o),t.refCount<=0&&(t.unsubscribe?.(),this.entries.delete(s)))}}}const l=new WeakMap,C=i=>{let e=l.get(i);return e||(e=new g(i),l.set(i,e)),e};export{C as g};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import{initialPages as x,rebalance as N,derivePaginationStatus as D,applyLoadMore as T}from"@lunora/client/pagination";import{useQueryClient as B}from"@tanstack/react-query";import{useRef as m,useReducer as G,useState as F,useEffect as y,useCallback as J}from"react";import{g as U}from"./cache-BN5T8cAI.mjs";import{useLunora as V}from"./LunoraProvider-DC06S-p1.mjs";import{s as u,l as v}from"./query-key-BFaqaQy8.mjs";const W=function(i){const l=m(void 0);return l.current??=i(),l},te=function(i,l,C){const f=V(),c=B(),{initialNumItems:R,shardKey:p}=C,d=l==="skip",g=d?{}:l,[,O]=G(e=>e+1,0),[q,h]=F(()=>x(R)),[z,k]=F(void 0),w=m(C.onError);y(()=>{w.current=C.onError});const Q=`${u(v(i,g,p))}::${String(R)}`,A=m(Q);A.current!==Q&&(A.current=Q,h(x(R)),k(void 0));const K=q.map(e=>{const t={...g,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}},r=v(i,t,p);return{args:t,key:r}}),P=K.map(({key:e})=>u(e)).join("|"),b=m({baseArgs:g,entries:[],fn:i,shardKey:p});y(()=>{b.current={baseArgs:g,entries:K,fn:i,shardKey:p}});const L=(e,t,r)=>{k(r),h(o=>{const s=b.current,n=o.at(-1);if(o.length<=1||!n||c.getQueryData(t)!==void 0)return o;const S={...s.baseArgs,paginationOpts:{cursor:n.lower,endCursor:n.upper,numItems:n.numItems}};return u(v(s.fn,S,s.shardKey))===e?o.slice(0,-1):o}),w.current?.(r)},E=W(()=>new Map),M=m(f);y(()=>{const e=E.current;if(M.current!==f){for(const s of e.values())s();e.clear(),M.current=f}if(d){for(const s of e.values())s();e.clear();return}const t=b.current,r=U(f),o=new Set(t.entries.map(({key:s})=>u(s)));for(const[s,n]of e)o.has(s)||(n(),e.delete(s));for(const s of t.entries){const n=u(s.key);if(e.has(n))continue;c.fetchQuery({queryFn:()=>f.query(t.fn,s.args,{shardKey:t.shardKey}),queryKey:s.key,staleTime:0}).catch(a=>{L(n,s.key,a instanceof Error?{code:a.code,message:a.message}:{message:String(a)})}),e.set(n,r.attach(c,s.key,t.fn,s.args,t.shardKey,{onError:a=>{L(n,s.key,a)}}))}},[f,c,P,d]),y(()=>()=>{for(const e of E.current.values())e();E.current.clear()},[]),y(()=>c.getQueryCache().subscribe(r=>{if(r.type!=="updated")return;const o=u(r.query.queryKey);K.some(({key:s})=>u(s)===o)&&(k(void 0),O())}),[c,P]);const I=d?[]:K.map(({key:e})=>c.getQueryData(e));y(()=>{if(d)return;const e=N(q,I);e&&h(e)});const{status:$}=D(d,I),j=J(e=>{k(void 0),h(t=>{const r=b.current,o=t.map(a=>{const H={...r.baseArgs,paginationOpts:{cursor:a.lower,endCursor:a.upper,numItems:a.numItems}};return c.getQueryData(v(r.fn,H,r.shardKey))}),{nextCursor:s,status:n}=D(!1,o);return T(t,n==="CanLoadMore"?s:void 0,e)??t})},[c]);return{error:z,loadMore:j,pageResults:I,status:$}};export{te as u};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import{c as S}from"react/compiler-runtime";import{useReducer as _,useRef as v,useEffect as R}from"react";import{useLunora as b}from"./LunoraProvider-DC06S-p1.mjs";import{s as z,c as E}from"./stream-state-abygFxmy.mjs";import{s as H}from"./stable-key-B_BlboiY.mjs";const C=(t,c,o)=>{const e=S(24);let m;e[0]!==o?(m=o===void 0?{}:o,e[0]=o,e[1]=m):m=e[1];const f=m,n=b();let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={chunks:[],error:void 0,status:"idle"},e[2]=i):i=e[2];const[s,a]=_(z,i),r=c==="skip";let l;e[3]!==c||e[4]!==r?(l=r?"skip":H(c),e[3]=c,e[4]=r,e[5]=l):l=e[5];const k=l,x=v(void 0);let u;e[6]!==c||e[7]!==n||e[8]!==f.maxBuffer||e[9]!==t||e[10]!==r?(u=()=>{if(r)return a({type:"reset"}),L;a({type:"reset"}),a({type:"start"});const{cancel:B,cleanup:y}=E(n.httpStream(t,c,{maxBuffer:f.maxBuffer}),a);return x.current=B,()=>{y(),x.current=void 0}},e[6]=c,e[7]=n,e[8]=f.maxBuffer,e[9]=t,e[10]=r,e[11]=u):u=e[11];let p;e[12]!==n||e[13]!==f.maxBuffer||e[14]!==t.method||e[15]!==t.path||e[16]!==k||e[17]!==r?(p=[n,t.method,t.path,k,r,f.maxBuffer],e[12]=n,e[13]=f.maxBuffer,e[14]=t.method,e[15]=t.path,e[16]=k,e[17]=r,e[18]=p):p=e[18],R(u,p);let h;e[19]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{x.current?.()},e[19]=h):h=e[19];let d;return e[20]!==s.chunks||e[21]!==s.error||e[22]!==s.status?(d={cancel:h,chunks:s.chunks,error:s.error,status:s.status},e[20]=s.chunks,e[21]=s.error,e[22]=s.status,e[23]=d):d=e[23],d};function L(){}export{C as useHttpStream};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import{useState as w,useRef as N,useCallback as E,useEffect as G}from"react";import{useLunora as X}from"./LunoraProvider-DC06S-p1.mjs";const O="/_lunora/ws",j="/_lunora/voice/",z=4001,P=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,Q=e=>{const n=e.startsWith("agents:")?e.slice(7):e;return n.endsWith("Voice")?n.slice(0,-5):n},Y=(e,n)=>{if(n===void 0||n==="")return P(e);if(n.endsWith(O))return n.slice(0,-O.length);try{return new URL(n).origin}catch{return P(e)}},Z=e=>{const n=Y(e.httpUrl,e.wsUrl),s=n.endsWith("/")?n.slice(0,-1):n,i=new URLSearchParams({threadKey:e.threadKey});return`${s}${j}${encodeURIComponent(e.agent)}?${i.toString()}`},ee=(e,n)=>{if(n?.code===z)return new Error(`${e}: authentication token expired — refresh the credential and start a new call`)},te=16e3,ne=e=>{if(e.length===0)return 0;let n=0;for(const s of e)n+=s*s;return Math.sqrt(n/e.length)},re=(e,n)=>{const s=n/te,i=s>1?Math.floor(e.length/s):e.length,d=new ArrayBuffer(i*2),l=new DataView(d);for(let a=0;a<i;a+=1){const k=e[Math.floor(a*s)]??0,p=Math.max(-1,Math.min(1,k));l.setInt16(a*2,p<0?p*32768:p*32767,!0)}return new Uint8Array(d)},oe=async e=>{const n=globalThis,s=n.navigator?.mediaDevices?.getUserMedia.bind(n.navigator.mediaDevices),i=n.AudioContext??n.webkitAudioContext;if(!s||!i)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const d=await s({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),l=new i,a=l.createMediaStreamSource(d),k=l.createScriptProcessor(4096,1,1);let p=!1,g=!1,u=0,h=0;return k.onaudioprocess=o=>{const f=o.inputBuffer.getChannelData(0),m=p?0:ne(f);if(e.onLevel(m),p)return;if(e.onAudio(re(f,l.sampleRate)),e.isSpeaking()){h=m>=e.interruptThreshold?h+1:0,h>=e.interruptChunks&&(h=0,e.onInterrupt());return}h=0;const x=f.length/l.sampleRate*1e3;if(m>=e.silenceThreshold){g=!0,u=0;return}g&&(u+=x,u>=e.silenceDurationMs&&(g=!1,u=0,e.onSilence()))},a.connect(k),k.connect(l.destination),{setMuted:o=>{p=o},stop:()=>{k.disconnect(),a.disconnect();for(const o of d.getTracks())o.stop();l.close()}}},se=()=>{const e=globalThis,n=e.AudioContext??e.webkitAudioContext;if(!n)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const s=new n,i=new Set;let d=0,l=Promise.resolve(),a=0;const k=async(u,h)=>{if(h!==a)return;let o;try{o=await s.decodeAudioData(u.buffer)}catch{return}if(h!==a)return;const f=s.createBufferSource();f.buffer=o,f.connect(s.destination);const m=Math.max(s.currentTime,d);f.start(m),d=m+o.duration,i.add(f),f.onended=()=>{i.delete(f)}},p=u=>{const h=Uint8Array.from(u),o=a;l=l.then(()=>k(h,o))},g=()=>{a+=1;for(const u of i)try{u.stop()}catch{}i.clear(),d=s.currentTime};return{enqueue:p,interrupt:g,stop:()=>{g(),s.close()}}},V=1,ce=.01,ie=1200,ae=.15,ue=3,pe=e=>{const{createMicrophone:n=oe,createSpeaker:s=se,createSocket:i,interruptChunks:d=ue,interruptThreshold:l=ae,silenceDurationMs:a=ie,silenceThreshold:k=ce,threadKey:p,voice:g}=e,u=X(),[h,o]=w("idle"),[f,m]=w(!1),[x,R]=w(""),[H,v]=w(""),[$,U]=w(0),[M,L]=w(!1),[B,C]=w(void 0),c=N(void 0),_=N(!1),T=E(t=>{const r=c.current?.socket;return r?.readyState===V?(r.send(JSON.stringify(t)),!0):!1},[]),y=E(()=>{const t=c.current;if(c.current=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{}}_.current=!1,m(!1),o("idle"),U(0)},[]),D=E(t=>{const r=c.current;switch(t.type){case"assistant_delta":{r&&(r.speaking=!0),o("speaking"),v(F=>F+t.text);break}case"assistant_done":{r&&(r.speaking=!1),v(t.text),o("listening");break}case"error":{r&&(r.speaking=!1),C(new Error(t.message)),o("listening");break}case"interrupted":{r&&(r.speaking=!1,r.suppressAudio=!1),r?.speaker?.interrupt(),o("listening");break}case"ready":{r&&(r.audioFormat=t.audioFormat,r.suppressAudio=!1),m(!0),o("listening");break}case"user_transcript":{r&&(r.suppressAudio=!1),R(t.text),v(""),o("thinking");break}}},[]),I=E(t=>{const r=c.current;!r||r.suppressAudio||(r.speaker??=s({audioFormat:r.audioFormat}),r.speaking=!0,o("speaking"),r.speaker.enqueue(t))},[s]),q=E(async()=>{if(c.current||_.current)return;_.current=!0,C(void 0),R(""),v("");let t;try{const r=Z({agent:Q(g.__lunoraRef),httpUrl:u.url,threadKey:p,wsUrl:u.wsUrl}),A=(i??(S=>{const b=u.getWebSocketImpl();if(!b)throw new Error("useVoiceAgent: no WebSocket implementation available (pass createSocket explicitly)");return new b(S)}))(r);A.binaryType="arraybuffer",t={audioFormat:"mp3",microphone:void 0,socket:A,speaker:void 0,speaking:!1,suppressAudio:!1},c.current=t,A.onmessage=S=>{if(typeof S.data=="string"){try{D(JSON.parse(S.data))}catch{}return}I(new Uint8Array(S.data))},A.onerror=()=>{C(new Error("useVoiceAgent: voice socket error"))},A.onclose=S=>{if(c.current!==t)return;const b=ee("useVoiceAgent",S);b&&C(b),y()};const W=await n({interruptChunks:d,interruptThreshold:l,isSpeaking:()=>c.current?.speaking??!1,onAudio:S=>{A.readyState===V&&A.send(S)},onInterrupt:()=>{T({type:"interrupt"}),c.current?.speaker?.interrupt(),c.current&&(c.current.speaking=!1,c.current.suppressAudio=!0),o("listening")},onLevel:U,onSilence:()=>{T({type:"commit"}),o("thinking")},silenceDurationMs:a,silenceThreshold:k});c.current===t?(t.microphone=W,L(!1),t.speaking||o("listening")):W.stop()}catch(r){c.current===t&&(C(r instanceof Error?r:new Error(String(r))),y())}finally{_.current=!1}},[u,n,i,I,D,d,l,T,a,k,y,p,g]),K=E(()=>{const t=!M;return c.current?.microphone?.setMuted(t),L(t),t},[M]),J=E(t=>{T({text:t,type:"text"})&&o("thinking")},[T]);return G(()=>y,[y]),{audioLevel:$,connected:f,endCall:y,error:B,interimTranscript:H,isMuted:M,sendText:J,startCall:q,status:h,toggleMute:K,transcript:x}};export{pe as useVoiceAgent};
|