@lunora/vue 1.0.0-alpha.67 → 1.0.0-alpha.69
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.mjs +1 -1
- package/dist/packem_shared/{hydratePreloaded-MzAWyyJQ.mjs → hydratePreloaded-C-yIiam2.mjs} +1 -1
- package/dist/packem_shared/scope-dispose-Dn0gQ2SS.mjs +1 -0
- package/dist/packem_shared/subscribeToQuery-Sz46o9Xt.mjs +1 -0
- package/dist/packem_shared/useAgentChat-B5mq0x66.mjs +1 -0
- package/dist/packem_shared/useConnectionStatus-1brbiHgc.mjs +1 -0
- package/dist/packem_shared/useInfiniteQuery-CD_dnvES.mjs +1 -0
- package/dist/packem_shared/usePresence-D2d4BqBJ.mjs +1 -0
- package/dist/packem_shared/{useVoiceAgent-Ba0SIP06.mjs → useVoiceAgent-1gtd9RU3.mjs} +1 -1
- package/package.json +5 -5
- package/dist/packem_shared/subscribeToQuery-Db5cXvHm.mjs +0 -1
- package/dist/packem_shared/useAgentChat-D59p-Qf3.mjs +0 -1
- package/dist/packem_shared/useConnectionStatus-BwLyL_L_.mjs +0 -1
- package/dist/packem_shared/useInfiniteQuery-DAHD8KKk.mjs +0 -1
- package/dist/packem_shared/usePresence-CfBwepyW.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AuthLoading as o,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-CST_mkXL.mjs";import{hydratePreloaded as a}from"./packem_shared/hydratePreloaded-
|
|
1
|
+
import{AuthLoading as o,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-CST_mkXL.mjs";import{hydratePreloaded as a}from"./packem_shared/hydratePreloaded-C-yIiam2.mjs";import{LUNORA_INJECTION_KEY as f,createLunora as m,provideLunora as p,useLunora as x}from"./packem_shared/LUNORA_INJECTION_KEY-CswQb5zb.mjs";import{useAgent as d}from"./packem_shared/useAgent-CeAYhGZA.mjs";import{useAgentChat as A}from"./packem_shared/useAgentChat-B5mq0x66.mjs";import{useAgentState as h}from"./packem_shared/useAgentState-Cs1VcKQj.mjs";import{useAgentToolEvents as l}from"./packem_shared/useAgentToolEvents-BhjZrNSJ.mjs";import{useAuth as Q}from"./packem_shared/useAuth-DwDFjvto.mjs";import{default as b}from"./packem_shared/useConnectionStatus-1brbiHgc.mjs";import{useFlag as E,useFlags as I}from"./packem_shared/useFlag-Bxoq8mH9.mjs";import{useMutation as P}from"./packem_shared/useMutation-MdgW9pRE.mjs";import{useMutator as v}from"./packem_shared/useMutator-DRVDOhcj.mjs";import{useInfiniteQuery as M,usePaginatedQuery as O}from"./packem_shared/useInfiniteQuery-CD_dnvES.mjs";import{usePresence as U}from"./packem_shared/usePresence-D2d4BqBJ.mjs";import{subscribeToQuery as J,useQuery as K}from"./packem_shared/subscribeToQuery-Sz46o9Xt.mjs";import{useRateLimit as Y}from"./packem_shared/useRateLimit-z8EUFuYJ.mjs";import{useStream as k}from"./packem_shared/useStream-CYkKEcDf.mjs";import{useSubscription as w}from"./packem_shared/useSubscription-3X8pNJ6P.mjs";import{useVoiceAgent as B}from"./packem_shared/useVoiceAgent-1gtd9RU3.mjs";export{o as AuthLoading,t as Authenticated,f as LUNORA_INJECTION_KEY,u as Unauthenticated,m as createLunora,a as hydratePreloaded,p as provideLunora,J as subscribeToQuery,d as useAgent,A as useAgentChat,h as useAgentState,l as useAgentToolEvents,Q as useAuth,b as useConnectionStatus,E as useFlag,I as useFlags,M as useInfiniteQuery,x as useLunora,P as useMutation,v as useMutator,O as usePaginatedQuery,U as usePresence,K as useQuery,Y as useRateLimit,k as useStream,w as useSubscription,B as useVoiceAgent};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useLunora as n}from"./LUNORA_INJECTION_KEY-CswQb5zb.mjs";import{subscribeToQuery as u}from"./subscribeToQuery-
|
|
1
|
+
import{useLunora as n}from"./LUNORA_INJECTION_KEY-CswQb5zb.mjs";import{subscribeToQuery as u}from"./subscribeToQuery-Sz46o9Xt.mjs";const f=r=>{const e=n(),{args:o,functionPath:t,shardKey:a,value:s}=r;return u(e,{__lunoraRef:t},o,{seed:s,shardKey:a})};export{f as hydratePreloaded};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getCurrentScope as e,onScopeDispose as p}from"vue";const c=(o,r)=>{e()&&p(o)};export{c as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as f}from"@lunora/client/query";import{shallowRef as a,watch as p,toValue as y}from"vue";import{i as m}from"./is-browser-BEdfLJHK.mjs";import{useLunora as h}from"./LUNORA_INJECTION_KEY-CswQb5zb.mjs";import{e as l}from"./scope-dispose-Dn0gQ2SS.mjs";const R=(o,s,t,r={})=>{const e=a(r.seed);if(m()){const u=o.subscribe(s,t,i=>{e.value=i},{shardKey:r.shardKey});l(u)}return e},x=(o,s,t={})=>{const r=h(),e=a(void 0);return p(()=>y(s),(u,i,n)=>{if(!m())return;const c=f(r,o,u,{onData:d=>{e.value=d},onReset:()=>{e.value=void 0}},{shardKey:t.shardKey});n(c)},{immediate:!0}),e};export{R as subscribeToQuery,x as useQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{reconcileOptimistic as y,maxSeq as I}from"@lunora/client";import{ref as N,computed as i,toValue as s}from"vue";import{NO_MUTATION_REF as R}from"./useAgent-CeAYhGZA.mjs";import{useMutation as m}from"./useMutation-MdgW9pRE.mjs";import{useStream as U}from"./useStream-CYkKEcDf.mjs";import{useSubscription as k}from"./useSubscription-3X8pNJ6P.mjs";const F={__lunoraRef:""},H=w=>{const{api:c,cancel:v,limit:p,send:A,sendArgs:x,stream:g,threadKey:n}=w,{data:S}=k(c.agents.agentMessages,()=>{const e=s(n);return p===void 0?{key:e}:{key:e,limit:p}}),{data:K}=k(c.agents.agentThread,()=>({key:s(n)})),O=g===void 0?"skip":()=>({key:s(n)}),{chunks:T}=U(g??F,O),_=m(A),C=m(v??R),M=m(c.agents.agentResolveApproval),o=N([]);let h=0;const l=i(()=>K.value),$=i(()=>l.value?.status),u=i(()=>S.value??[]),b=i(()=>{const e=u.value,a=y(o.value,e);if(a.length===0)return e;const t=I(e);return[...e,...a.map((r,d)=>({content:r.content,optimistic:!0,role:"user",seq:t+1+d}))]}),j=i(()=>{const e=s(n),a=u.value.filter(t=>t.role==="assistant").length;return T.value.filter(t=>t.kind!=="progress"&&t.threadKey===e&&t.turn>=a).map(t=>t.text).join("")}),q=async(e,a)=>{const t=h;h+=1;const r=I(u.value);o.value=[...y(o.value,u.value),{content:e,id:t,maxDurableSeqAtSend:r}];try{await _.mutate({input:e,threadKey:s(n),...x,...a})}catch(d){throw o.value=o.value.filter(E=>E.id!==t),d}},f=async(e,a,t)=>{const r=l.value?.instanceId;if(r===void 0)throw new Error(`useAgentChat: cannot ${e} — no in-flight run (thread has no instanceId)`);await M.mutate({decision:e,instanceId:r,threadKey:s(n),toolCallId:a,...t===void 0?{}:{note:t}})};return{approve:async(e,a)=>f("approve",e,a),cancel:async()=>{const e=l.value?.instanceId;v===void 0||e===void 0||await C.mutate({instanceId:e,threadKey:s(n)})},messages:b,reject:async(e,a)=>f("reject",e,a),send:q,status:$,streamingText:j}};export{H as useAgentChat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{shallowRef as r}from"vue";import{useLunora as a}from"./LUNORA_INJECTION_KEY-CswQb5zb.mjs";import{e as s}from"./scope-dispose-Dn0gQ2SS.mjs";const f=()=>{const o=a(),t=r(o.connectionStatus()),n=o.onConnectionStatus(e=>{t.value=e});return s(n),t};export{f as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{shallowRef as N,watch as $,toValue as L,onScopeDispose as z,computed as K}from"vue";import{initialPages as U,derivePaginationStatus as E,applyLoadMore as Q,rebalance as q}from"@lunora/client/pagination";import{i as G}from"./is-browser-BEdfLJHK.mjs";import{e as H}from"./stable-key-BSG0zK_E.mjs";import{useLunora as J}from"./LUNORA_INJECTION_KEY-CswQb5zb.mjs";const k=e=>{let r="";for(let i=0;i<e.length;i+=32768)r+=String.fromCharCode(...e.subarray(i,i+32768));return btoa(r)},f="$lunora.wire$",F=64,W="__proto__",X=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},h=(e,r=0)=>{if(r>F)throw new RangeError(`wire-codec: value nesting exceeds the ${F}-level limit`);if(e===void 0)return[f,"undefined"];if(e===null)return null;const i=typeof e;if(i==="bigint")return[f,"bigint",e.toString()];if(i==="number"){const t=e;return Number.isNaN(t)?[f,"nan"]:t===1/0?[f,"inf"]:t===-1/0?[f,"-inf"]:t}if(i!=="object")return e;if(e instanceof Date)return[f,"date",h(e.getTime(),r+1)];if(e instanceof Error){const t=e,o={};for(const b of Object.keys(t))t[b]!==void 0&&(o[b]=h(t[b],r+1));const a=[f,"error",t.name,t.message,o];return t.cause!==void 0&&a.push(h(t.cause,r+1)),a}if(e instanceof URL)return[f,"url",e.href];if(e instanceof Map)return[f,"map",[...e.entries()].map(([t,o])=>[h(t,r+1),h(o,r+1)])];if(e instanceof Set)return[f,"set",[...e].map(t=>h(t,r+1))];if(e instanceof ArrayBuffer)return[f,"bytes",k(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,o=t.constructor.name,a=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return o==="Uint8Array"?[f,"bytes",k(a)]:[f,"bytes",k(a),o]}if(Array.isArray(e)){const t=e.map(o=>h(o,r+1));return t.length>0&&t[0]===f?[f,"arr",t]:t}if(!X(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 _=e,y={};for(const t of Object.keys(_)){const o=_[t];if(o===void 0)continue;const a=h(o,r+1);t===W?Object.defineProperty(y,t,{configurable:!0,enumerable:!0,value:a,writable:!0}):y[t]=a}return y},D=e=>H(h(e)),R=(e,r)=>`${e}::${D(r)}`,P=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),T=(e,r,i)=>{const _=J(),{initialNumItems:y,shardKey:t}=i,o=N(U(y)),a=N([]);let b;const p=new Map,d=new Map,m=new Set,S=(n,s)=>{a.value=n.map(v=>{const w=R(e.__lunoraRef,P(v,s));return d.get(w)})},V=(n,s,v)=>{const w=u=>R(e.__lunoraRef,P(u,v));for(const u of s){const l=w(u);if(d.has(l))continue;const g=n.find(c=>c.lower===u.lower);if(g){const c=d.get(w(g));c&&d.set(l,c)}}},x=(n,s)=>{const v=new Set;for(const u of n)v.add(R(e.__lunoraRef,P(u,s)));for(const[u,l]of p)v.has(l.currentKey)||(l.unsub(),p.delete(u),d.delete(l.currentKey),m.delete(l.currentKey));const w=new Set([...p.values()].map(u=>u.currentKey));for(const u of n){const l=P(u,s),g=R(e.__lunoraRef,l);if(w.has(g))continue;const c={currentKey:g,unsub:void 0};m.add(g);const M=_.subscribe(e,l,A=>{d.set(c.currentKey,A),m.delete(c.currentKey);const O=L(r);if(S(o.value,O),m.size===0){const I=o.value,j=q(I,a.value);j&&(V(I,j,O),o.value=j)}},{shardKey:t});c.unsub=M,p.set(g,c),w.add(g)}},C=()=>{for(const n of p.values())n.unsub();p.clear(),d.clear(),m.clear()};$(()=>D(L(r)),()=>{if(!G())return;const n=L(r);C(),o.value=U(y),a.value=[],b=void 0,n!=="skip"&&(x(o.value,n),S(o.value,n))},{immediate:!0}),$(()=>o.value,n=>{const s=L(r);s!=="skip"&&(x(n,s),S(n,s))}),z(C);const B=N("LoadingFirstPage");return $([()=>L(r),a],([n,s])=>{B.value=E(n==="skip",s).status},{immediate:!0}),{loadMore:n=>{const s=L(r);if(s==="skip")return;const{nextCursor:v,status:w}=E(!1,a.value);if(w!=="CanLoadMore"||v===b)return;const u=Q(o.value,v,n);if(!u)return;b=v;const l=o.value.at(-1),g=u.at(-2);if(l&&g){const c=R(e.__lunoraRef,P(l,s)),M=R(e.__lunoraRef,P(g,s)),A=p.get(c);if(A&&c!==M){A.currentKey=M,p.set(M,A),p.delete(c);const O=d.get(c);O&&(d.set(M,O),d.delete(c))}}o.value=u},pageResults:a,status:B}},oe=(e,r,i)=>{const{loadMore:_,pageResults:y,status:t}=T(e,r,i),o=K(()=>y.value.flatMap(a=>a?.page??[]));return{isLoading:K(()=>t.value==="LoadingFirstPage"||t.value==="LoadingMore"),loadMore:_,results:o,status:t}},ae=(e,r,i)=>{const{initialNumItems:_}=i,{loadMore:y,pageResults:t,status:o}=T(e,r,i),a=K(()=>t.value.flatMap(m=>m?[m.page]:[])),b=K(()=>o.value==="LoadingFirstPage"),p=K(()=>o.value==="CanLoadMore"),d=K(()=>o.value==="LoadingMore");return{fetchNextPage:m=>{y(m??_)},hasNextPage:p,isFetchingNextPage:d,isLoading:b,pages:a,status:o}};export{ae as useInfiniteQuery,oe as usePaginatedQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{shallowRef as I}from"vue";import{i as h}from"./is-browser-BEdfLJHK.mjs";import{useLunora as b}from"./LUNORA_INJECTION_KEY-CswQb5zb.mjs";import{e as g}from"./scope-dispose-Dn0gQ2SS.mjs";const $=(e="sess")=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const t=crypto.getRandomValues(new Uint8Array(16));return`${e}-${Array.from(t,o=>o.toString(16).padStart(2,"0")).join("")}`}}return`${e}-${Date.now().toString(36)}`},w=1e4,S=(e,t)=>{const o=b(),{heartbeat:u,intervalMs:m=w,listPresent:y,shardKey:s}=t,i=t.sessionId??$(),c=I(void 0);let a=t.data;const n=()=>{const r={roomId:e,sessionId:i,...a===void 0?{}:{data:a}};o.mutation(u,r,{shardKey:s}).catch(()=>{})},f=r=>{a=r,n()};if(h()){n();const r=setInterval(n,m),d=()=>{typeof document<"u"&&document.visibilityState==="visible"&&n()};typeof document<"u"&&document.addEventListener("visibilitychange",d);const p=o.acquireConnectionContext({roomId:e,sessionId:i},{shardKey:s}),l=o.subscribe(y,{roomId:e},v=>{c.value=v},{shardKey:s});g(()=>{clearInterval(r),typeof document<"u"&&document.removeEventListener("visibilitychange",d),p(),l()})}return{present:c,sessionId:i,setData:f}};export{S as usePresence};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ref as y,onScopeDispose as F,toValue as L}from"vue";import{useLunora as R}from"./LUNORA_INJECTION_KEY-CswQb5zb.mjs";const W=t=>{if(t.length===0)return 0;let s=0;for(const n of t)s+=n*n;return Math.sqrt(s/t.length)},B=(t,s)=>{const n=s/16e3,o=n>1?Math.floor(t.length/n):t.length,d=new ArrayBuffer(o*2),i=new DataView(d);for(let c=0;c<o;c+=1){const v=t[Math.floor(c*n)]??0,g=Math.max(-1,Math.min(1,v));i.setInt16(c*2,g<0?g*32768:g*32767,!0)}return new Uint8Array(d)},I=async t=>{const s=globalThis,n=s.navigator?.mediaDevices?.getUserMedia.bind(s.navigator.mediaDevices),o=s.AudioContext??s.webkitAudioContext;if(!n||!o)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const d=await n({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),i=new o,c=i.createMediaStreamSource(d),v=i.createScriptProcessor(4096,1,1);let g=!1,m=!1,f=0,a=0;return v.onaudioprocess=u=>{const p=u.inputBuffer.getChannelData(0),h=g?0:W(p);if(t.onLevel(h),g)return;if(t.onAudio(B(p,i.sampleRate)),t.isSpeaking()){a=h>=t.interruptThreshold?a+1:0,a>=t.interruptChunks&&(a=0,t.onInterrupt());return}a=0;const w=p.length/i.sampleRate*1e3;if(h>=t.silenceThreshold){m=!0,f=0;return}m&&(f+=w,f>=t.silenceDurationMs&&(m=!1,f=0,t.onSilence()))},c.connect(v),v.connect(i.destination),{setMuted:u=>{g=u},stop:()=>{v.disconnect(),c.disconnect();for(const u of d.getTracks())u.stop();i.close()}}},J=()=>{const t=globalThis,s=t.AudioContext??t.webkitAudioContext;if(!s)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const n=new s,o=new Set;let d=0,i=Promise.resolve(),c=0;const v=async(f,a)=>{if(a!==c)return;let u;try{u=await n.decodeAudioData(f.buffer)}catch{return}if(a!==c)return;const p=n.createBufferSource();p.buffer=u,p.connect(n.destination);const h=Math.max(n.currentTime,d);p.start(h),d=h+u.duration,o.add(p),p.onended=()=>{o.delete(p)}},g=f=>{const a=Uint8Array.from(f),u=c;i=i.then(()=>v(a,u))},m=()=>{c+=1;for(const f of o)try{f.stop()}catch{}o.clear(),d=n.currentTime};return{enqueue:g,interrupt:m,stop:()=>{m(),n.close()}}},D=1,K=.01,N=1200,P=.15,O=3,j=t=>t.startsWith("https://")?`wss://${t.slice(8)}`:t.startsWith("http://")?`ws://${t.slice(7)}`:t,G=t=>{const s=t.__lunoraRef,n=s.startsWith("agents:")?s.slice(7):s;return n.endsWith("Voice")?n.slice(0,-5):n},H=(t,s,n)=>{const o=j(t),d=o.endsWith("/")?o.slice(0,-1):o,i=new URLSearchParams({threadKey:n});return`${d}/_lunora/voice/${encodeURIComponent(s)}?${i.toString()}`},X=t=>{const{createMicrophone:s=I,createSpeaker:n=J,createSocket:o,interruptChunks:d=O,interruptThreshold:i=P,silenceDurationMs:c=N,silenceThreshold:v=K,threadKey:g,voice:m}=t,f=R(),a=y("idle"),u=y(!1),p=y(""),h=y(""),w=y(0),b=y(!1),A=y(void 0);let l,S=!1;const C=r=>{const e=l?.socket;return e?.readyState===D?(e.send(JSON.stringify(r)),!0):!1},M=()=>{const r=l;if(l=void 0,r){r.microphone?.stop(),r.speaker?.stop();try{r.socket.close()}catch{}}S=!1,u.value=!1,a.value="idle",w.value=0},U=
|
|
1
|
+
import{ref as y,onScopeDispose as F,toValue as L}from"vue";import{useLunora as R}from"./LUNORA_INJECTION_KEY-CswQb5zb.mjs";const W=t=>{if(t.length===0)return 0;let s=0;for(const n of t)s+=n*n;return Math.sqrt(s/t.length)},B=(t,s)=>{const n=s/16e3,o=n>1?Math.floor(t.length/n):t.length,d=new ArrayBuffer(o*2),i=new DataView(d);for(let c=0;c<o;c+=1){const v=t[Math.floor(c*n)]??0,g=Math.max(-1,Math.min(1,v));i.setInt16(c*2,g<0?g*32768:g*32767,!0)}return new Uint8Array(d)},I=async t=>{const s=globalThis,n=s.navigator?.mediaDevices?.getUserMedia.bind(s.navigator.mediaDevices),o=s.AudioContext??s.webkitAudioContext;if(!n||!o)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const d=await n({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),i=new o,c=i.createMediaStreamSource(d),v=i.createScriptProcessor(4096,1,1);let g=!1,m=!1,f=0,a=0;return v.onaudioprocess=u=>{const p=u.inputBuffer.getChannelData(0),h=g?0:W(p);if(t.onLevel(h),g)return;if(t.onAudio(B(p,i.sampleRate)),t.isSpeaking()){a=h>=t.interruptThreshold?a+1:0,a>=t.interruptChunks&&(a=0,t.onInterrupt());return}a=0;const w=p.length/i.sampleRate*1e3;if(h>=t.silenceThreshold){m=!0,f=0;return}m&&(f+=w,f>=t.silenceDurationMs&&(m=!1,f=0,t.onSilence()))},c.connect(v),v.connect(i.destination),{setMuted:u=>{g=u},stop:()=>{v.disconnect(),c.disconnect();for(const u of d.getTracks())u.stop();i.close()}}},J=()=>{const t=globalThis,s=t.AudioContext??t.webkitAudioContext;if(!s)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const n=new s,o=new Set;let d=0,i=Promise.resolve(),c=0;const v=async(f,a)=>{if(a!==c)return;let u;try{u=await n.decodeAudioData(f.buffer)}catch{return}if(a!==c)return;const p=n.createBufferSource();p.buffer=u,p.connect(n.destination);const h=Math.max(n.currentTime,d);p.start(h),d=h+u.duration,o.add(p),p.onended=()=>{o.delete(p)}},g=f=>{const a=Uint8Array.from(f),u=c;i=i.then(()=>v(a,u))},m=()=>{c+=1;for(const f of o)try{f.stop()}catch{}o.clear(),d=n.currentTime};return{enqueue:g,interrupt:m,stop:()=>{m(),n.close()}}},D=1,K=.01,N=1200,P=.15,O=3,j=t=>t.startsWith("https://")?`wss://${t.slice(8)}`:t.startsWith("http://")?`ws://${t.slice(7)}`:t,G=t=>{const s=t.__lunoraRef,n=s.startsWith("agents:")?s.slice(7):s;return n.endsWith("Voice")?n.slice(0,-5):n},H=(t,s,n)=>{const o=j(t),d=o.endsWith("/")?o.slice(0,-1):o,i=new URLSearchParams({threadKey:n});return`${d}/_lunora/voice/${encodeURIComponent(s)}?${i.toString()}`},X=t=>{const{createMicrophone:s=I,createSpeaker:n=J,createSocket:o,interruptChunks:d=O,interruptThreshold:i=P,silenceDurationMs:c=N,silenceThreshold:v=K,threadKey:g,voice:m}=t,f=R(),a=y("idle"),u=y(!1),p=y(""),h=y(""),w=y(0),b=y(!1),A=y(void 0);let l,S=!1;const C=r=>{const e=l?.socket;return e?.readyState===D?(e.send(JSON.stringify(r)),!0):!1},M=()=>{const r=l;if(l=void 0,r){r.microphone?.stop(),r.speaker?.stop();try{r.socket.close()}catch{}}S=!1,u.value=!1,a.value="idle",w.value=0},U=M,V=r=>{const e=l;switch(r.type){case"assistant_delta":{e&&(e.speaking=!0),a.value="speaking",h.value+=r.text;break}case"assistant_done":{e&&(e.speaking=!1),h.value=r.text,a.value="listening";break}case"error":{e&&(e.speaking=!1),A.value=new Error(r.message),a.value="listening";break}case"interrupted":{e&&(e.speaking=!1,e.suppressAudio=!1),e?.speaker?.interrupt(),a.value="listening";break}case"ready":{e&&(e.audioFormat=r.audioFormat,e.suppressAudio=!1),u.value=!0,a.value="listening";break}case"user_transcript":{e&&(e.suppressAudio=!1),p.value=r.text,h.value="",a.value="thinking";break}}},$=r=>{const e=l;!e||e.suppressAudio||(e.speaker??=n({audioFormat:e.audioFormat}),e.speaking=!0,a.value="speaking",e.speaker.enqueue(r))},E=async()=>{if(!(l||S)){S=!0,A.value=void 0,p.value="",h.value="";try{const r=H(f.url,G(m),L(g)),e=(o??(k=>new globalThis.WebSocket(k)))(r);e.binaryType="arraybuffer";const x={audioFormat:"mp3",microphone:void 0,socket:e,speaker:void 0,speaking:!1,suppressAudio:!1};l=x,e.onmessage=k=>{if(typeof k.data=="string"){try{V(JSON.parse(k.data))}catch{}return}$(new Uint8Array(k.data))},e.onerror=()=>{A.value=new Error("useVoiceAgent: voice socket error")},e.onclose=()=>{l===x&&M()};const T=await s({interruptChunks:d,interruptThreshold:i,isSpeaking:()=>l?.speaking??!1,onAudio:k=>{e.readyState===D&&e.send(k)},onInterrupt:()=>{C({type:"interrupt"}),l?.speaker?.interrupt(),l&&(l.speaking=!1,l.suppressAudio=!0),a.value="listening"},onLevel:k=>{w.value=k},onSilence:()=>{C({type:"commit"}),a.value="thinking"},silenceDurationMs:c,silenceThreshold:v});l===x?(x.microphone=T,b.value=!1,a.value="listening"):T.stop()}catch(r){A.value=r instanceof Error?r:new Error(String(r)),M()}finally{S=!1}}},_=()=>{const r=!b.value;return l?.microphone?.setMuted(r),b.value=r,r},q=r=>{C({text:r,type:"text"})&&(a.value="thinking")};return F(M),{audioLevel:w,connected:u,endCall:U,error:A,interimTranscript:h,isMuted:b,sendText:q,startCall:E,status:a,toggleMute:_,transcript:p}};export{X 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.69",
|
|
4
4
|
"description": "Vue adapter for Lunora — live composables, optimistic mutations, and reactive loaders",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -58,10 +58,10 @@
|
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@lunora/client": "1.0.0-alpha.
|
|
62
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
63
|
-
"@lunora/ratelimit": "1.0.0-alpha.
|
|
64
|
-
"@lunora/runtime": "1.0.0-alpha.
|
|
61
|
+
"@lunora/client": "1.0.0-alpha.41",
|
|
62
|
+
"@lunora/errors": "1.0.0-alpha.15",
|
|
63
|
+
"@lunora/ratelimit": "1.0.0-alpha.18",
|
|
64
|
+
"@lunora/runtime": "1.0.0-alpha.54",
|
|
65
65
|
"@visulima/storage-client": "1.0.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createQuerySubscription as d}from"@lunora/client/query";import{shallowRef as a,getCurrentScope as f,onScopeDispose as y,watch as h,toValue as l}from"vue";import{i as n}from"./is-browser-BEdfLJHK.mjs";import{useLunora as b}from"./LUNORA_INJECTION_KEY-CswQb5zb.mjs";const S=(o,s,t,r={})=>{const e=a(r.seed);if(n()){const u=o.subscribe(s,t,i=>{e.value=i},{shardKey:r.shardKey});f()&&y(u)}return e},D=(o,s,t={})=>{const r=b(),e=a(void 0);return h(()=>l(s),(u,i,c)=>{if(!n())return;const m=d(r,o,u,{onData:p=>{e.value=p},onReset:()=>{e.value=void 0}},{shardKey:t.shardKey});c(m)},{immediate:!0}),e};export{S as subscribeToQuery,D as useQuery};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{reconcileOptimistic as y,maxSeq as I}from"@lunora/client";import{ref as b,computed as s,toValue as o}from"vue";import{NO_MUTATION_REF as R}from"./useAgent-CeAYhGZA.mjs";import{useMutation as m}from"./useMutation-MdgW9pRE.mjs";import{useStream as D}from"./useStream-CYkKEcDf.mjs";import{useSubscription as w}from"./useSubscription-3X8pNJ6P.mjs";const N={__lunoraRef:""},B=A=>{const{api:u,cancel:v,limit:p,send:k,sendArgs:x,stream:h,threadKey:n}=A,{data:C}=w(u.agents.agentMessages,()=>{const e=o(n);return p===void 0?{key:e}:{key:e,limit:p}}),{data:K}=w(u.agents.agentThread,()=>({key:o(n)})),S=h===void 0?"skip":()=>({key:o(n)}),{chunks:O}=D(h??N,S),T=m(k),j=m(v??R),g=m(u.agents.agentResolveApproval),r=b([]);let f=0;const i=s(()=>K.value),q=s(()=>i.value?.status),c=s(()=>C.value??[]),E=s(()=>{const e=c.value,a=y(r.value,e);if(a.length===0)return e;const t=I(e);return[...e,...a.map((l,d)=>({content:l.content,optimistic:!0,role:"user",seq:t+1+d}))]}),M=s(()=>{const e=o(n),a=c.value.filter(t=>t.role==="assistant").length;return O.value.filter(t=>t.kind!=="progress"&&t.threadKey===e&&t.turn>=a).map(t=>t.text).join("")});return{approve:async(e,a)=>{const t=i.value?.instanceId;if(t===void 0)throw new Error("useAgentChat: cannot approve — no in-flight run (thread has no instanceId)");await g.mutate({decision:"approve",instanceId:t,threadKey:o(n),toolCallId:e,...a===void 0?{}:{note:a}})},cancel:async()=>{const e=i.value?.instanceId;v===void 0||e===void 0||await j.mutate({instanceId:e,threadKey:o(n)})},messages:E,reject:async(e,a)=>{const t=i.value?.instanceId;if(t===void 0)throw new Error("useAgentChat: cannot reject — no in-flight run (thread has no instanceId)");await g.mutate({decision:"reject",instanceId:t,threadKey:o(n),toolCallId:e,...a===void 0?{}:{note:a}})},send:async(e,a)=>{const t=f;f+=1;const l=I(c.value);r.value=[...y(r.value,c.value),{content:e,id:t,maxDurableSeqAtSend:l}];try{await T.mutate({input:e,threadKey:o(n),...x,...a})}catch(d){throw r.value=r.value.filter(_=>_.id!==t),d}},status:q,streamingText:M}};export{B as useAgentChat};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{shallowRef as r,getCurrentScope as s,onScopeDispose as a}from"vue";import{useLunora as u}from"./LUNORA_INJECTION_KEY-CswQb5zb.mjs";const i=()=>{const o=u(),t=r(o.connectionStatus()),e=o.onConnectionStatus(n=>{t.value=n});return s()&&a(e),t};export{i as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{shallowRef as N,watch as $,toValue as P,onScopeDispose as z,computed as A}from"vue";import{initialPages as U,derivePaginationStatus as E,applyLoadMore as Q,rebalance as q}from"@lunora/client/pagination";import{i as G}from"./is-browser-BEdfLJHK.mjs";import{e as H}from"./stable-key-BSG0zK_E.mjs";import{useLunora as J}from"./LUNORA_INJECTION_KEY-CswQb5zb.mjs";const k=e=>{let r="";for(let i=0;i<e.length;i+=32768)r+=String.fromCharCode(...e.subarray(i,i+32768));return btoa(r)},f="$lunora.wire$",F=64,W="__proto__",X=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},h=(e,r=0)=>{if(r>F)throw new RangeError(`wire-codec: value nesting exceeds the ${F}-level limit`);if(e===void 0)return[f,"undefined"];if(e===null)return null;const i=typeof e;if(i==="bigint")return[f,"bigint",e.toString()];if(i==="number"){const t=e;return Number.isNaN(t)?[f,"nan"]:t===1/0?[f,"inf"]:t===-1/0?[f,"-inf"]:t}if(i!=="object")return e;if(e instanceof Date)return[f,"date",h(e.getTime(),r+1)];if(e instanceof Error){const t=e,o={};for(const d of Object.keys(t))t[d]!==void 0&&(o[d]=h(t[d],r+1));const n=[f,"error",t.name,t.message,o];return t.cause!==void 0&&n.push(h(t.cause,r+1)),n}if(e instanceof URL)return[f,"url",e.href];if(e instanceof Map)return[f,"map",[...e.entries()].map(([t,o])=>[h(t,r+1),h(o,r+1)])];if(e instanceof Set)return[f,"set",[...e].map(t=>h(t,r+1))];if(e instanceof ArrayBuffer)return[f,"bytes",k(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,o=t.constructor.name,n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return o==="Uint8Array"?[f,"bytes",k(n)]:[f,"bytes",k(n),o]}if(Array.isArray(e)){const t=e.map(o=>h(o,r+1));return t.length>0&&t[0]===f?[f,"arr",t]:t}if(!X(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 _=e,m={};for(const t of Object.keys(_)){const o=_[t];if(o===void 0)continue;const n=h(o,r+1);t===W?Object.defineProperty(m,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):m[t]=n}return m},D=e=>H(h(e)),R=(e,r)=>`${e}::${D(r)}`,K=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),T=(e,r,i)=>{const _=J(),{initialNumItems:m,shardKey:t}=i,o=N(U(m)),n=N([]);let d;const g=new Map,p=new Map,v=new Set,L=(a,s)=>{n.value=a.map(b=>{const w=R(e.__lunoraRef,K(b,s));return p.get(w)})},V=(a,s,b)=>{const w=u=>R(e.__lunoraRef,K(u,b));for(const u of s){const l=w(u);if(p.has(l))continue;const y=a.find(c=>c.lower===u.lower);if(y){const c=p.get(w(y));c&&p.set(l,c)}}},x=(a,s)=>{const b=new Set;for(const u of a)b.add(R(e.__lunoraRef,K(u,s)));for(const[u,l]of g)b.has(l.currentKey)||(l.unsub(),g.delete(u),p.delete(l.currentKey),v.delete(l.currentKey));const w=new Set([...g.values()].map(u=>u.currentKey));for(const u of a){const l=K(u,s),y=R(e.__lunoraRef,l);if(w.has(y))continue;const c={currentKey:y,unsub:void 0};v.add(y);const M=_.subscribe(e,l,O=>{p.set(c.currentKey,O),v.delete(c.currentKey);const S=P(r);if(L(o.value,S),v.size===0){const I=o.value,j=q(I,n.value);j&&(V(I,j,S),o.value=j)}},{shardKey:t});c.unsub=M,g.set(y,c),w.add(y)}},C=()=>{for(const a of g.values())a.unsub();g.clear(),p.clear(),v.clear()};$(()=>D(P(r)),()=>{if(!G())return;const a=P(r);C(),o.value=U(m),n.value=[],d=void 0,a!=="skip"&&(x(o.value,a),L(o.value,a))},{immediate:!0}),$(()=>o.value,a=>{const s=P(r);s!=="skip"&&(x(a,s),L(a,s))}),z(C);const B=N("LoadingFirstPage");return $([()=>P(r),n],([a,s])=>{B.value=E(a==="skip",s).status},{immediate:!0}),{loadMore:a=>{const s=P(r);if(s==="skip")return;const{nextCursor:b,status:w}=E(!1,n.value);if(w!=="CanLoadMore"||b===d)return;const u=Q(o.value,b,a);if(!u)return;d=b;const l=o.value.at(-1),y=u.at(-2);if(l&&y){const c=R(e.__lunoraRef,K(l,s)),M=R(e.__lunoraRef,K(y,s)),O=g.get(c);if(O&&c!==M){O.currentKey=M,g.set(M,O),g.delete(c);const S=p.get(c);S&&(p.set(M,S),p.delete(c))}}o.value=u},pageResults:n,status:B}},oe=(e,r,i)=>{const{loadMore:_,pageResults:m,status:t}=T(e,r,i),o=A(()=>{const n=[];for(const d of m.value)d&&n.push(...d.page);return n});return{isLoading:A(()=>t.value==="LoadingFirstPage"||t.value==="LoadingMore"),loadMore:_,results:o,status:t}},ne=(e,r,i)=>{const{initialNumItems:_}=i,{loadMore:m,pageResults:t,status:o}=T(e,r,i),n=A(()=>{const v=[];for(const L of t.value)L&&v.push(L.page);return v}),d=A(()=>o.value==="LoadingFirstPage"),g=A(()=>o.value==="CanLoadMore"),p=A(()=>o.value==="LoadingMore");return{fetchNextPage:v=>{m(v??_)},hasNextPage:g,isFetchingNextPage:p,isLoading:d,pages:n,status:o}};export{ne as useInfiniteQuery,oe as usePaginatedQuery};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{shallowRef as h,getCurrentScope as b,onScopeDispose as g}from"vue";import{i as S}from"./is-browser-BEdfLJHK.mjs";import{useLunora as D}from"./LUNORA_INJECTION_KEY-CswQb5zb.mjs";const U=(e="sess")=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const t=crypto.getRandomValues(new Uint8Array(16));return`${e}-${Array.from(t,o=>o.toString(16).padStart(2,"0")).join("")}`}}return`${e}-${Date.now().toString(36)}`},$=1e4,C=(e,t)=>{const o=D(),{heartbeat:u,intervalMs:m=$,listPresent:p,shardKey:s}=t,i=t.sessionId??U(),c=h(void 0);let a=t.data;const r=()=>{const n={roomId:e,sessionId:i,...a===void 0?{}:{data:a}};o.mutation(u,n,{shardKey:s}).catch(()=>{})},y=n=>{a=n,r()};if(S()){r();const n=setInterval(r,m),d=()=>{typeof document<"u"&&document.visibilityState==="visible"&&r()};typeof document<"u"&&document.addEventListener("visibilitychange",d);const f=o.acquireConnectionContext({roomId:e,sessionId:i},{shardKey:s}),l=o.subscribe(p,{roomId:e},I=>{c.value=I},{shardKey:s}),v=()=>{clearInterval(n),typeof document<"u"&&document.removeEventListener("visibilitychange",d),f(),l()};b()&&g(v)}return{present:c,sessionId:i,setData:y}};export{C as usePresence};
|