@lunora/vue 1.0.0-alpha.3 → 1.0.0-alpha.300
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/LICENSE.md +6 -0
- package/README.md +23 -14
- package/__assets__/package-og.svg +1 -1
- package/dist/index.d.mts +1172 -191
- package/dist/index.d.ts +1172 -191
- package/dist/index.mjs +1 -11
- package/dist/packem_shared/AuthLoading-ZXVgXos1.mjs +1 -0
- package/dist/packem_shared/LUNORA_INJECTION_KEY-Bct9tKCj.mjs +1 -0
- package/dist/packem_shared/hydratePreloaded-DicHNxhB.mjs +1 -0
- package/dist/packem_shared/is-browser-BEdfLJHK.mjs +1 -0
- package/dist/packem_shared/scope-dispose-Mq3k4nvP.mjs +1 -0
- package/dist/packem_shared/subscribeToQuery-BvnA8ErG.mjs +1 -0
- package/dist/packem_shared/useAction-C4VLsh4M.mjs +1 -0
- package/dist/packem_shared/useAgent-Bp5UEoEp.mjs +1 -0
- package/dist/packem_shared/useAgentChat-CVgX8Z-J.mjs +1 -0
- package/dist/packem_shared/useAgentState-DpFm2lH0.mjs +1 -0
- package/dist/packem_shared/useAgentToolEvents-CWHORsCT.mjs +1 -0
- package/dist/packem_shared/useAuth-QDllAwZL.mjs +1 -0
- package/dist/packem_shared/useConnectionStatus-CCUbKnj2.mjs +1 -0
- package/dist/packem_shared/useFlag-xVfWC_c6.mjs +1 -0
- package/dist/packem_shared/useInfiniteQuery-Clqt_MYU.mjs +1 -0
- package/dist/packem_shared/useLiveTopic-B0HA04MY.mjs +1 -0
- package/dist/packem_shared/useMutation-D6PkaNaE.mjs +1 -0
- package/dist/packem_shared/useMutator-CO7nXlRf.mjs +1 -0
- package/dist/packem_shared/usePresence-Dcb5dwMf.mjs +1 -0
- package/dist/packem_shared/useRateLimit-zoPsflSG.mjs +1 -0
- package/dist/packem_shared/useStream-COVzNdKq.mjs +1 -0
- package/dist/packem_shared/useSubscription-cTKyOIAv.mjs +1 -0
- package/dist/packem_shared/useVoiceAgent-Dz1t4xgi.mjs +1 -0
- package/dist/server.mjs +1 -1
- package/dist/upload.d.mts +2 -0
- package/dist/upload.d.ts +2 -0
- package/dist/upload.mjs +1 -0
- package/package.json +10 -8
- package/dist/packem_shared/AuthLoading-_6-uOycE.mjs +0 -29
- package/dist/packem_shared/LUNORA_INJECTION_KEY-DtFXLDQ_.mjs +0 -22
- package/dist/packem_shared/hydratePreloaded-rVY68iFv.mjs +0 -14
- package/dist/packem_shared/subscribeToQuery-Cv5YL-SI.mjs +0 -51
- package/dist/packem_shared/useAuth-C2aEzXXH.mjs +0 -28
- package/dist/packem_shared/useConnectionStatus-CDgduQYe.mjs +0 -20
- package/dist/packem_shared/useInfiniteQuery-CEfbw7Nw.mjs +0 -199
- package/dist/packem_shared/useMutation-DWubV5pv.mjs +0 -29
- package/dist/packem_shared/usePresence-BeN5xaZM.mjs +0 -59
- package/dist/packem_shared/useRateLimit-DlPWjcX1.mjs +0 -67
- package/dist/packem_shared/useSubscription-Ol0AZFUv.mjs +0 -47
- package/dist/worker.d.mts +0 -1
- package/dist/worker.d.ts +0 -1
- package/dist/worker.mjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { hydratePreloaded } from './packem_shared/hydratePreloaded-rVY68iFv.mjs';
|
|
3
|
-
export { LUNORA_INJECTION_KEY, createLunora, provideLunora, useLunora } from './packem_shared/LUNORA_INJECTION_KEY-DtFXLDQ_.mjs';
|
|
4
|
-
export { useAuth } from './packem_shared/useAuth-C2aEzXXH.mjs';
|
|
5
|
-
export { default as useConnectionStatus } from './packem_shared/useConnectionStatus-CDgduQYe.mjs';
|
|
6
|
-
export { useMutation } from './packem_shared/useMutation-DWubV5pv.mjs';
|
|
7
|
-
export { useInfiniteQuery, usePaginatedQuery } from './packem_shared/useInfiniteQuery-CEfbw7Nw.mjs';
|
|
8
|
-
export { usePresence } from './packem_shared/usePresence-BeN5xaZM.mjs';
|
|
9
|
-
export { subscribeToQuery, useQuery } from './packem_shared/subscribeToQuery-Cv5YL-SI.mjs';
|
|
10
|
-
export { useRateLimit } from './packem_shared/useRateLimit-DlPWjcX1.mjs';
|
|
11
|
-
export { useSubscription } from './packem_shared/useSubscription-Ol0AZFUv.mjs';
|
|
1
|
+
import{AuthLoading as r,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-ZXVgXos1.mjs";import{hydratePreloaded as p}from"./packem_shared/hydratePreloaded-DicHNxhB.mjs";import{LUNORA_INJECTION_KEY as f,createLunora as m,provideLunora as n,useLunora as x}from"./packem_shared/LUNORA_INJECTION_KEY-Bct9tKCj.mjs";import{useAction as c}from"./packem_shared/useAction-C4VLsh4M.mjs";import{useAgent as d}from"./packem_shared/useAgent-Bp5UEoEp.mjs";import{useAgentChat as L}from"./packem_shared/useAgentChat-CVgX8Z-J.mjs";import{useAgentState as l}from"./packem_shared/useAgentState-DpFm2lH0.mjs";import{useAgentToolEvents as Q}from"./packem_shared/useAgentToolEvents-CWHORsCT.mjs";import{useAuth as T}from"./packem_shared/useAuth-QDllAwZL.mjs";import{default as v}from"./packem_shared/useConnectionStatus-CCUbKnj2.mjs";import{useFlag as E,useFlags as I}from"./packem_shared/useFlag-xVfWC_c6.mjs";import{useLiveTopic as P}from"./packem_shared/useLiveTopic-B0HA04MY.mjs";import{useMutation as M}from"./packem_shared/useMutation-D6PkaNaE.mjs";import{useMutator as R}from"./packem_shared/useMutator-CO7nXlRf.mjs";import{useInfiniteQuery as _,usePaginatedQuery as J}from"./packem_shared/useInfiniteQuery-Clqt_MYU.mjs";import{usePresence as V}from"./packem_shared/usePresence-Dcb5dwMf.mjs";import{subscribeToQuery as j,useQuery as k}from"./packem_shared/subscribeToQuery-BvnA8ErG.mjs";import{useRateLimit as w}from"./packem_shared/useRateLimit-zoPsflSG.mjs";import{useStream as B}from"./packem_shared/useStream-COVzNdKq.mjs";import{useSubscription as G}from"./packem_shared/useSubscription-cTKyOIAv.mjs";import{useVoiceAgent as W}from"./packem_shared/useVoiceAgent-Dz1t4xgi.mjs";export{r as AuthLoading,t as Authenticated,f as LUNORA_INJECTION_KEY,u as Unauthenticated,m as createLunora,p as hydratePreloaded,n as provideLunora,j as subscribeToQuery,c as useAction,d as useAgent,L as useAgentChat,l as useAgentState,Q as useAgentToolEvents,T as useAuth,v as useConnectionStatus,E as useFlag,I as useFlags,_ as useInfiniteQuery,P as useLiveTopic,x as useLunora,M as useMutation,R as useMutator,J as usePaginatedQuery,V as usePresence,k as useQuery,w as useRateLimit,B as useStream,G as useSubscription,W as useVoiceAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isAuthenticatedStatus as i,isLoadingStatus as d}from"@lunora/client/auth";import{defineComponent as n,computed as a}from"vue";import{useAuth as o}from"./useAuth-QDllAwZL.mjs";const m=n({name:"Authenticated",setup(s,{slots:t}){const{status:e}=o(),u=a(()=>i(e.value));return()=>u.value?t.default?.():void 0}}),h=n({name:"Unauthenticated",setup(s,{slots:t}){const{status:e}=o(),u=a(()=>e.value==="unauthenticated");return()=>u.value?t.default?.():void 0}}),l=n({name:"AuthLoading",setup(s,{slots:t}){const{status:e}=o(),u=a(()=>d(e.value));return()=>u.value?t.default?.():void 0}});export{l as AuthLoading,m as Authenticated,h as Unauthenticated};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as e}from"@lunora/errors";import{inject as t,provide as i}from"vue";const o=Symbol("lunora.client"),c=r=>({install(n){n.provide(o,r)}}),p=r=>{i(o,r)},l=()=>{const r=t(o,void 0);if(!r)throw new e("INTERNAL","useLunora(): no LunoraClient provided — call app.use(createLunora(client)) or provideLunora(client) in a parent setup().");return r};export{o as LUNORA_INJECTION_KEY,c as createLunora,p as provideLunora,l as useLunora};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as c}from"./is-browser-BEdfLJHK.mjs";import{useLunora as f}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";import{o as u}from"./scope-dispose-Mq3k4nvP.mjs";import{subscribeToQuery as d}from"./subscribeToQuery-BvnA8ErG.mjs";const v=(e,n={})=>{const o=f(),{args:t,functionPath:i,shardKey:s,value:a}=e,r=d(o,{__lunoraRef:i},t,{onError:n.onError,seed:o.identityEpoch()===0?a:void 0,shardKey:s});return c()&&u(o.onIdentityChange(()=>{r.value=void 0})),r};export{v as hydratePreloaded};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=()=>globalThis.window!==void 0;export{o as i};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getCurrentScope as e,onScopeDispose as r}from"vue";const s=(o,n)=>{e()&&r(o)};export{s as o};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as y}from"@lunora/client/query";import{stableWireKey as f}from"@lunora/wire";import{shallowRef as n,watch as l,toValue as i}from"vue";import{i as c}from"./is-browser-BEdfLJHK.mjs";import{useLunora as p}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";import{o as v}from"./scope-dispose-Mq3k4nvP.mjs";const R=(t,o,s,e={})=>{const r=n(e.seed);if(c()){const a=t.subscribe(o,s,u=>{r.value=u},{onError:e.onError,shardKey:e.shardKey});v(a)}return r},S=(t,o,s={})=>{const e=p(),r=n(void 0);return l(()=>f(i(o)),(a,u,m)=>{if(!c())return;r.value=void 0;const d=y(e,t,i(o),{onData:b=>{r.value=b},onError:s.onError,onReset:()=>{r.value=void 0}},{shardKey:s.shardKey});m(d)},{immediate:!0}),r};export{R as subscribeToQuery,S as useQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createCallRunner as i}from"@lunora/client";import{shallowRef as n,ref as u}from"vue";import{useLunora as v}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const R=l=>{const a=v(),t=n(void 0),o=n(void 0),r=u(!1),s=()=>{t.value=void 0,o.value=void 0};return{call:i((e,c)=>a.action(l,e,c),{setError:e=>{o.value=e},setPending:e=>{r.value=e},setResult:e=>{t.value=e,o.value=void 0}}),data:t,error:o,pending:r,reset:s}};export{R as useAction};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{computed as c,toValue as a}from"vue";import{useMutation as s}from"./useMutation-D6PkaNaE.mjs";import{useSubscription as M}from"./useSubscription-cTKyOIAv.mjs";const R={__lunoraRef:""},T=u=>{const{api:i,cancel:r,onError:d,run:l,runArgs:m,threadKey:e}=u,o=s(l),p=s(r??R),{data:f,error:g}=M(i.agents.agentThread,()=>({key:a(e)}),{onError:d}),n=c(()=>f.value),h=c(()=>n.value?.status),y=async(t,v)=>{await o.mutate({input:t,threadKey:a(e),...m,...v})};return{cancel:async()=>{const t=n.value?.instanceId;r===void 0||t===void 0||await p.mutate({instanceId:t,threadKey:a(e)})},error:g,pending:o.pending,run:y,status:h,thread:n}};export{R as NO_MUTATION_REF,T as useAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{reconcileOptimistic as A,maxSeq as k}from"@lunora/client";import{computed as s,ref as X,watch as Z,toValue as n}from"vue";import{NO_MUTATION_REF as tt}from"./useAgent-Bp5UEoEp.mjs";import{useMutation as u}from"./useMutation-D6PkaNaE.mjs";import{useStream as et}from"./useStream-COVzNdKq.mjs";import{useSubscription as y}from"./useSubscription-cTKyOIAv.mjs";const at={__lunoraRef:""},rt=[],lt=w=>{const{api:o,cancel:h,limit:g,onError:p,send:M,sendArgs:E,stream:f,threadKey:r}=w,{data:R,error:_}=y(o.agents.agentMessages,()=>{const t=n(r);return g===void 0?{key:t}:{key:t,limit:g}},{onError:p}),{data:K,error:T}=y(o.agents.agentThread,()=>({key:n(r)}),{onError:p}),{data:x,error:I}=y(o.agents.agentApprovalGrants,()=>({key:n(r)}),{onError:p}),b=s(()=>_.value??T.value??I.value),D=f===void 0?"skip":()=>({key:n(r)}),{chunks:G}=et(f??at,D),O=u(M),q=u(h??tt),N=u(o.agents.agentResolveApproval),j=u(o.agents.agentRevokeApprovalGrant),C=u(o.agents.agentSupplySecret),F=u(o.agents.agentDeclineSecret),c=X([]);let S=0;Z(()=>n(r),()=>{c.value=[]});const d=s(()=>K.value),P=s(()=>d.value?.status),l=s(()=>R.value??[]),U=s(()=>{const t=l.value,e=A(c.value,t);if(e.length===0)return t;const a=k(t);return[...t,...e.map((i,m)=>({content:i.content,optimistic:!0,role:"user",seq:a+1+m}))]}),V=s(()=>{const t=n(r),e=l.value.filter(a=>a.role==="assistant").length;return G.value.filter(a=>a.kind!=="progress"&&a.threadKey===t&&a.turn>=e).map(a=>a.text).join("")}),Y=async(t,e)=>{const a=S;S+=1;const i=k(l.value);c.value=[...A(c.value,l.value),{content:t,id:a,maxDurableSeqAtSend:i}];try{await O.mutate({input:t,threadKey:n(r),...E,...e})}catch(m){throw c.value=c.value.filter(W=>W.id!==a),m}},v=async(t,e,a)=>{const i=d.value?.instanceId;if(i===void 0)throw new Error(`useAgentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await N.mutate({decision:t,instanceId:i,threadKey:n(r),toolCallId:e,...a===void 0?{}:{note:a}})},$=async(t,e)=>v("approve",t,e),z=async(t,e)=>v("approve_for_thread",t,e),B=async(t,e)=>v("reject",t,e),H=async t=>{await j.mutate({threadKey:n(r),toolName:t})},J=async(t,e)=>{await C.mutate({secret:e,threadKey:n(r),toolCallId:t},{onlineOnly:!0})},L=async t=>{await F.mutate({threadKey:n(r),toolCallId:t})},Q=async()=>{const t=d.value?.instanceId;h===void 0||t===void 0||await q.mutate({instanceId:t,threadKey:n(r)})};return{approvalGrants:s(()=>x.value??rt),approve:$,approveForThread:z,cancel:Q,declineSecret:L,error:b,messages:U,reject:B,revokeGrant:H,send:Y,status:P,streamingText:V,supplySecret:J}};export{lt as useAgentChat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{computed as o,toValue as n}from"vue";import{useSubscription as u}from"./useSubscription-cTKyOIAv.mjs";const m=t=>{const{data:e,error:r}=u(t.api.agents.agentState,()=>({key:n(t.threadKey)})),a=o(()=>e.value);return{error:r,state:a}};export{m as useAgentState};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{computed as v,toValue as a}from"vue";import{useStream as f}from"./useStream-COVzNdKq.mjs";import{useSubscription as E}from"./useSubscription-cTKyOIAv.mjs";const C={__lunoraRef:""},y=[],I={awaiting_approval:"awaiting-approval",awaiting_secret:"awaiting-secret"},N=t=>{const o=t.status===void 0?void 0:I[t.status];if(o!==void 0)return{seq:t.seq,type:o,...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}},_=t=>{if(t.role==="assistant"&&t.toolCalls)return t.toolCalls.map(r=>({input:r.input,seq:t.seq,toolCallId:r.id,toolName:r.name,type:"call"}));if(t.role!=="tool")return;const o=N(t);return o!==void 0?[o]:[{output:t.content,seq:t.seq,type:"result",...t.status==="approved"||t.status==="rejected"?{status:t.status}:{},...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}]},M=t=>{const{api:o,limit:r,stream:i,threadKey:e}=t,d=()=>{const l=a(e);return r===void 0?{key:l}:{key:l,limit:r}},{data:s}=E(o.agents.agentMessages,d),p=i===void 0?"skip":()=>({key:a(e)}),{chunks:c}=f(i??C,p);return{events:v(()=>{const l=a(e),u=(s.value??y).flatMap(n=>_(n)??[]);for(const n of c.value)n.kind==="progress"&&n.threadKey===l&&u.push({data:n.data,toolCallId:n.toolCallId,type:"progress"});return u})}};export{M as useAgentToolEvents};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getIdentityStore as h}from"@lunora/client/auth";import{ref as u,readonly as e,onScopeDispose as m}from"vue";import{i as p}from"./is-browser-BEdfLJHK.mjs";import{useLunora as T}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const U=()=>{const t=T(),o=h(t),s=u(t.getAuthToken()),n=u(o.getUser()),r=u(o.getStatus()),c=()=>{s.value=t.getAuthToken()},i=()=>{n.value=o.getUser(),r.value=o.getStatus()},a=f=>{t.setAuthToken(f)};if(!p())return{setToken:a,status:e(r),token:e(s),user:e(n)};const g=t.onAuthTokenChange(c),k=o.subscribe(i);return m(()=>{g(),k()}),{setToken:a,status:e(r),token:e(s),user:e(n)}};export{U as useAuth};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{shallowRef as r}from"vue";import{i as e}from"./is-browser-BEdfLJHK.mjs";import{useLunora as i}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";import{o as u}from"./scope-dispose-Mq3k4nvP.mjs";const p=()=>{const t=i(),o=r(t.connectionStatus());if(!e())return o;const n=t.onConnectionStatus(s=>{o.value=s});return u(n),o};export{p as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{shallowRef as c,watch as b,toValue as m}from"vue";import{i as a}from"./is-browser-BEdfLJHK.mjs";import{useLunora as l}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";import{o as p}from"./scope-dispose-Mq3k4nvP.mjs";const _="__lunora_flags__:eval",d=t=>{const e=typeof t;return e==="boolean"||e==="number"||e==="string"?e:"object"},v={__lunoraRef:_},i=(t,e,r)=>{try{return t.subscribe(v,{default:e.default,key:e.key,type:d(e.default)},o=>{r(o)},{onError:()=>{r(e.default)}})}catch{return()=>{}}},g=(t,e)=>{const r=l(),o=c(e);return b(()=>m(t),(n,u,s)=>{o.value=e,a()&&s(i(r,{default:e,key:n},f=>{o.value=f}))},{immediate:!0}),o},w=t=>{const e=l(),r=c(t);if(!a())return r;const o=[];for(const[n,u]of Object.entries(t))o.push(i(e,{default:u,key:n},s=>{r.value={...r.value,[n]:s}}));return p(()=>{for(const n of o)n()}),r};export{g as useFlag,w as useFlags};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{shallowRef as _,watch as N,toValue as m,onScopeDispose as D,computed as K}from"vue";import{initialPages as B,derivePaginationStatus as O,rebalance as E,applyLoadMore as T}from"@lunora/client/pagination";import{stableWireKey as Q}from"@lunora/wire";import{i as V}from"./is-browser-BEdfLJHK.mjs";import{useLunora as W}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const M=(o,s)=>`${o}::${Q(s)}`,R=(o,s)=>({...s,paginationOpts:{cursor:o.lower,endCursor:o.upper,numItems:o.numItems}}),$=(o,s,h)=>{const x=W(),{initialNumItems:L,onError:S,shardKey:P}=h,e=_(B(L)),d=_([]),p=_(void 0);let b;const f=new Map,i=new Map,c=new Set,C=(t,a)=>{d.value=t.map(v=>{const r=M(o.__lunoraRef,R(v,a));return i.get(r)})},z=(t,a,v)=>{const r=l=>M(o.__lunoraRef,R(l,v));for(const l of a){const u=r(l);if(i.has(u))continue;const w=t.find(n=>n.lower===l.lower);if(w){const n=i.get(r(w));n&&i.set(u,n)}}},F=(t,a)=>{const v=new Set;for(const r of t)v.add(M(o.__lunoraRef,R(r,a)));for(const[r,l]of f)v.has(r)||(l(),f.delete(r),i.delete(r),c.delete(r));for(const r of t){const l=R(r,a),u=M(o.__lunoraRef,l);if(f.has(u))continue;c.add(u);const w=x.subscribe(o,l,n=>{i.set(u,n),c.delete(u),p.value=void 0;const g=m(s);if(C(e.value,g),c.size===0){const y=e.value,k=E(y,d.value);k&&(z(y,k,g),e.value=k)}},{onError:n=>{c.delete(u),p.value=n;const g=e.value,y=g.at(-1);g.length>1&&y&&!i.has(u)&&M(o.__lunoraRef,R(y,a))===u&&(e.value=g.slice(0,-1)),S?.(n)},shardKey:P});f.set(u,w)}},I=()=>{for(const t of f.values())t();f.clear(),i.clear(),c.clear()};N(()=>Q(m(s)),()=>{if(!V())return;const t=m(s);I(),e.value=B(L),d.value=[],p.value=void 0,b=void 0,t!=="skip"&&(F(e.value,t),C(e.value,t))},{immediate:!0}),N(()=>e.value,t=>{const a=m(s);b=void 0,a!=="skip"&&(F(t,a),C(t,a))}),D(I);const A=_("LoadingFirstPage");return N([()=>m(s),d],([t,a])=>{A.value=O(t==="skip",a).status},{immediate:!0}),{error:p,loadMore:t=>{const a=m(s);if(a==="skip")return;const{nextCursor:v,status:r}=O(!1,d.value);if(r!=="CanLoadMore"||v===b)return;const l=T(e.value,v,t);if(!l)return;b=v,p.value=void 0;const u=e.value.at(-1),w=l.at(-2);if(u&&w){const n=M(o.__lunoraRef,R(u,a)),g=M(o.__lunoraRef,R(w,a)),y=f.get(n);if(y&&n!==g){const k=i.get(n);k&&i.set(g,k),y(),f.delete(n),i.delete(n),c.delete(n)}}e.value=l},pageResults:d,status:A}},X=(o,s,h)=>{const{error:x,loadMore:L,pageResults:S,status:P}=$(o,s,h),e=K(()=>S.value.flatMap(p=>p?.page??[])),d=K(()=>m(s)!=="skip"&&(P.value==="LoadingFirstPage"||P.value==="LoadingMore"));return{error:x,isLoading:d,loadMore:L,results:e,status:P}},Y=(o,s,h)=>{const{initialNumItems:x}=h,{error:L,loadMore:S,pageResults:P,status:e}=$(o,s,h),d=K(()=>P.value.flatMap(c=>c?[c.page]:[])),p=K(()=>m(s)!=="skip"&&e.value==="LoadingFirstPage"),b=K(()=>e.value==="CanLoadMore"),f=K(()=>m(s)!=="skip"&&e.value==="LoadingMore");return{error:L,fetchNextPage:c=>{S(c??x)},hasNextPage:b,isFetchingNextPage:f,isLoading:p,pages:d,status:e}};export{Y as useInfiniteQuery,X as usePaginatedQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{subscribeLiveTopic as b,liveTopicSubscription as y}from"@lunora/client";import{stableWireKey as E}from"@lunora/wire";import{shallowRef as a,watch as w,toValue as l}from"vue";import{i as h}from"./is-browser-BEdfLJHK.mjs";import{useLunora as K}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";import{o as T}from"./scope-dispose-Mq3k4nvP.mjs";const D=i=>{const r={};for(const[o,t]of Object.entries(i))o!=="onError"&&o!=="onEvent"&&(r[o]=l(t));return r},_=(i,r={})=>{const o=a(void 0),t=a(void 0);if(h()){const p=K(),c=()=>y(p,l(i),D(r)),m=w(()=>{const{headers:u,maxDelayMs:v,retryDelay:n,sessionKey:s,topic:e,url:f,withCredentials:d}=c();return E({headers:u,maxDelayMs:v,retryDelay:n,sessionKey:s,topic:e,url:f,withCredentials:d})},(u,v,n)=>{o.value=void 0,t.value=void 0;const s=b({...c(),onError:e=>{t.value=e,r.onError?.(e)},onEvent:e=>{o.value=e,t.value=void 0,r.onEvent?.(e)}});n(s)},{immediate:!0});T(m)}return{error:t,lastEvent:o}};export{_ as useLiveTopic};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createCallRunner as v}from"@lunora/client";import{shallowRef as n,ref as c}from"vue";import{useLunora as d}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const R=a=>{const s=d(),o=n(void 0),t=n(void 0),r=c(!1),u=()=>{o.value=void 0,t.value=void 0},i=v((e,l)=>s.mutation(a,e,l),{setError:e=>{t.value=e},setPending:e=>{r.value=e},setResult:e=>{o.value=e,t.value=void 0}});return{data:o,error:t,mutate:i,pending:r,reset:u}};export{R as useMutation};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMutatorRunner as c}from"@lunora/client";import{shallowRef as o,computed as i}from"vue";const d=n=>{const r=o(void 0),t=o(!1),s=i(()=>r.value!==void 0),{mutate:u,reset:a}=c(n,{setError:e=>{r.value=e},setPending:e=>{t.value=e}});return{error:r,isError:s,mutate:u,pending:t,reset:a}};export{d as useMutator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{shallowRef as p}from"vue";import{i as I}from"./is-browser-BEdfLJHK.mjs";import{useLunora as h}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";import{o as S}from"./scope-dispose-Mq3k4nvP.mjs";const U=e=>{if(!Number.isFinite(e)||e<=0)throw new RangeError(`presence intervalMs must be a positive number, got ${String(e)}`)},D=()=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const e=crypto.getRandomValues(new Uint8Array(16));return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}}throw new Error("randomSessionId: no Web Crypto available — a session id needs crypto.randomUUID or crypto.getRandomValues")},E=1e4,x=(e,t)=>{const s=h(),{heartbeat:v,intervalMs:f=E,listPresent:y,shardKey:i}=t;U(f);const a=t.sessionId??D(),l=p(void 0),c=p(void 0);let d=t.data,u=!1;const o=()=>{const n={roomId:e,sessionId:a,...d===void 0?{}:{data:d}};s.mutation(v,n,{shardKey:i}).catch(()=>{})},b=n=>{d=n,u&&o()};if(I()){u=!0,o();const n=setInterval(o,f),m=()=>{typeof document<"u"&&document.visibilityState==="visible"&&o()};typeof document<"u"&&document.addEventListener("visibilitychange",m);const g=s.acquireConnectionContext({roomId:e,sessionId:a},{shardKey:i}),w=s.subscribe(y,{roomId:e},r=>{l.value=r,c.value=void 0},{onError:r=>{c.value=r,t.onError?.(r)},shardKey:i});S(()=>{u=!1,clearInterval(n),typeof document<"u"&&document.removeEventListener("visibilitychange",m),g(),w()})}return{error:c,present:l,sessionId:a,setData:b}};export{x as usePresence};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{evaluate as r}from"@lunora/ratelimit";import{shallowRef as k,toValue as l,watchEffect as b,onScopeDispose as A,computed as f}from"vue";const M=(o,i={})=>{const a=i.now??Date.now,p=i.tickMs??1e3;let e;const m=k(0),u=()=>{m.value+=1},t=k(r(l(o),e,{consume:!1,count:1,now:a(),reserve:!1}).status),w=b(()=>{m.value,t.value=r(l(o),e,{consume:!1,count:1,now:a(),reserve:!1}).status},{flush:"sync"});let s;const n=()=>{s!==void 0&&(clearInterval(s),s=void 0)},d=()=>{t.value.ok||s!==void 0||(s=setInterval(()=>{u(),t.value.ok&&n()},p))};A(()=>{n(),w()}),d();const h=(c=1)=>{const v=r(l(o),e,{consume:!0,count:c,now:a(),reserve:!1});return v.value!==void 0&&(e=v.value),u(),d(),v.status},I=(c=1)=>r(l(o),e,{consume:!1,count:c,now:a(),reserve:!1}).status.ok,y=()=>{e=void 0,n(),u()};return{check:I,consume:h,disabled:f(()=>!t.value.ok),ok:f(()=>t.value.ok),reset:y,retryAfter:f(()=>t.value.retryAfter)}};export{M as useRateLimit};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ref as s,watch as p,toValue as b,onScopeDispose as w}from"vue";import{i as y}from"./is-browser-BEdfLJHK.mjs";import{useLunora as k}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const K=(m,v,c={})=>{const d=k(),a=s([]),u=s(void 0),e=s("idle");let t;const i=()=>{t?.()};return p(()=>b(v),(l,x,h)=>{if(a.value=[],u.value=void 0,l==="skip"||!y()){e.value="idle";return}e.value="streaming";let o=!0;const f=d.stream(m,l,{durable:c.durable,maxBuffer:c.maxBuffer,shardKey:c.shardKey}),n=()=>{f.cancel()};t=n,(async()=>{try{for await(const r of f){if(!o)return;a.value=[...a.value,r]}o&&(e.value="complete")}catch(r){if(!o)return;u.value=r instanceof Error?r:new Error(String(r)),e.value="error"}})().catch(()=>{}),h(()=>{o=!1,n(),t===n&&(t=void 0)})},{immediate:!0}),w(()=>{i()}),{cancel:i,chunks:a,error:u,status:e}};export{K as useStream};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as l}from"@lunora/client/query";import{LunoraError as c}from"@lunora/errors";import{stableWireKey as f}from"@lunora/wire";import{ref as v,watch as y,toValue as u,onScopeDispose as w}from"vue";import{i as h}from"./is-browser-BEdfLJHK.mjs";import{useLunora as p}from"./LUNORA_INJECTION_KEY-Bct9tKCj.mjs";const x=(d,a,t={})=>{const n=p(),o=v(void 0),r=v(void 0);return y(()=>f(u(a)),(K,g,m)=>{const i=u(a);if(o.value=void 0,r.value=void 0,i==="skip"||!h())return;const s=l(n,d,i,{onData:e=>{o.value=e,r.value=void 0},onError:e=>{r.value=Object.assign(e.code===void 0?new Error(e.message):new c(e.code,e.message),e.why===void 0?{}:{why:e.why}),o.value=void 0,t.onError?.(e)},onReset:()=>{o.value=void 0}},{shardKey:t.shardKey});m(s)},{immediate:!0}),w(()=>{o.value=void 0,r.value=void 0}),{data:o,error:r}};export{x as useSubscription};
|
|
@@ -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),h=v?0:j(d);if(e.onLevel(h),v)return;if(e.onAudio(z(d,p.sampleRate)),e.isTurnActive()){o=h>=e.interruptThreshold?o+1:0,o>=e.interruptChunks&&(o=0,e.onInterrupt());return}o=0;const S=d.length/p.sampleRate*1e3;if(h>=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 h=Math.max(s.currentTime,g);d.start(h),g=h+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(""),h=y(""),S=y(0),b=y(!1),m=y(void 0);let a,C=!1;const _=n=>{const t=a?.socket;return t?.readyState===U?(t.send(JSON.stringify(n)),!0):!1},T=()=>{const n=a;if(a=void 0,n){n.unwatchIdentity?.(),n.microphone?.stop(),n.speaker?.stop(),n.socket.onmessage=null,n.socket.onerror=null,n.socket.onclose=null;try{n.socket.close()}catch{}}C=!1,u.value=!1,o.value="idle",S.value=0},R=T,D=n=>{const t=a;switch(n.type){case"assistant_delta":{t&&(t.speaking=!0),o.value="speaking",h.value+=n.text;break}case"assistant_discarded":{t&&(t.suppressAudio=!0),t?.speaker?.interrupt(),h.value="";break}case"assistant_done":{t&&(t.awaitingTurn=!1,t.speaking=!1),h.value=n.text,o.value="listening";break}case"error":{t&&(t.awaitingTurn=!1,t.speaking=!1),m.value=new Error(n.message),o.value="listening";break}case"interrupted":{t&&(t.awaitingTurn=!1,t.speaking=!1,t.suppressAudio=!1),t?.speaker?.interrupt(),o.value="listening";break}case"ready":{t&&(t.audioFormat=n.audioFormat,t.suppressAudio=!1),u.value=!0,o.value="listening";break}case"user_transcript":{t&&(t.suppressAudio=!1),d.value=n.text,h.value="",o.value="thinking";break}}},L=n=>{const t=a;!t||t.suppressAudio||(t.speaker??=s({audioFormat:t.audioFormat}),t.speaking=!0,o.value="speaking",t.speaker.enqueue(n))},V=async()=>{if(a||C)return;C=!0,m.value=void 0,d.value="",h.value="";let n;try{const t=q({agent:B(w.__lunoraRef),httpUrl:c.url,threadKey:O(v),wsUrl:c.wsUrl}),A=(i??(f=>{const E=c.getWebSocketImpl();if(!E)throw new Error("useVoiceAgent: no WebSocket implementation available (pass createSocket explicitly)");return new E(f)}))(t);A.binaryType="arraybuffer",n={audioFormat:"mp3",microphone:void 0,socket:A,speaker:void 0,speaking:!1,awaitingTurn:!1,suppressAudio:!1,unwatchIdentity:void 0},a=n,n.unwatchIdentity=G(c,"useVoiceAgent",f=>{a===n&&(m.value=f,T())}),A.onmessage=f=>{if(typeof f.data=="string"){try{D(JSON.parse(f.data))}catch{}return}L(new Uint8Array(f.data))},A.onerror=()=>{m.value=new Error("useVoiceAgent: voice socket error")},A.onclose=f=>{if(a!==n)return;const E=J("useVoiceAgent",f);E&&(m.value=E),T()};const x=await r({interruptChunks:g,interruptThreshold:p,isTurnActive:()=>(a?.speaking??!1)||(a?.awaitingTurn??!1),onAudio:f=>{A.readyState===U&&A.send(f)},onInterrupt:()=>{_({type:"interrupt"}),a?.speaker?.interrupt(),a&&(a.awaitingTurn=!1,a.speaking=!1,a.suppressAudio=!0),o.value="listening"},onLevel:f=>{S.value=f},onSilence:()=>{_({type:"commit"}),a&&(a.awaitingTurn=!0),o.value="thinking"},silenceDurationMs:l,silenceThreshold:k});a===n?(n.microphone=x,b.value=!1,n.speaking||(o.value="listening")):x.stop()}catch(t){a===n&&(m.value=t instanceof Error?t:new Error(String(t)),T())}finally{C=!1}},F=()=>{const n=!b.value;return a?.microphone?.setMuted(n),b.value=n,n},W=n=>{_({text:n,type:"text"})&&(a&&(a.awaitingTurn=!0),o.value="thinking")};return N(T),{audioLevel:S,connected:u,endCall:R,error:m,interimTranscript:h,isMuted:b,sendText:W,startCall:V,status:o,toggleMute:F,transcript:d}};export{ae as useVoiceAgent};
|
package/dist/server.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{createServerClient as d,deserializePreloaded as l,getServerSession as a,preloadQuery as o,preloadedQueryResult as i,serializePreloaded as s}from"@lunora/client/ssr";export{d as createServerClient,l as deserializePreloaded,a as getServerSession,o as preloadQuery,i as preloadedQueryResult,s as serializePreloaded};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { RestrictionError, UploadControl, UploadError, type UploadMethod, type UploadRestrictions, type UploadResult } from '@visulima/storage-client';
|
|
2
|
+
export { type UseChunkedRestUploadOptions, type UseChunkedRestUploadReturn, type UseFileInputOptions, type UseFileInputReturn, type UseMultipartUploadOptions, type UseMultipartUploadReturn, type UsePasteUploadOptions, type UsePasteUploadReturn, type UseTusUploadOptions, type UseTusUploadReturn, type UseUploadOptions, type UseUploadReturn, useChunkedRestUpload, useFileInput, useMultipartUpload, usePasteUpload, useTusUpload, useUpload } from '@visulima/storage-client/vue';
|
package/dist/upload.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { RestrictionError, UploadControl, UploadError, type UploadMethod, type UploadRestrictions, type UploadResult } from '@visulima/storage-client';
|
|
2
|
+
export { type UseChunkedRestUploadOptions, type UseChunkedRestUploadReturn, type UseFileInputOptions, type UseFileInputReturn, type UseMultipartUploadOptions, type UseMultipartUploadReturn, type UsePasteUploadOptions, type UsePasteUploadReturn, type UseTusUploadOptions, type UseTusUploadReturn, type UseUploadOptions, type UseUploadReturn, useChunkedRestUpload, useFileInput, useMultipartUpload, usePasteUpload, useTusUpload, useUpload } from '@visulima/storage-client/vue';
|
package/dist/upload.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{RestrictionError as r,UploadControl as p,UploadError as l}from"@visulima/storage-client";import{useChunkedRestUpload as t,useFileInput as u,useMultipartUpload as a,usePasteUpload as d,useTusUpload as U,useUpload as i}from"@visulima/storage-client/vue";export{r as RestrictionError,p as UploadControl,l as UploadError,t as useChunkedRestUpload,u as useFileInput,a as useMultipartUpload,d as usePasteUpload,U as useTusUpload,i as useUpload};
|
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.300",
|
|
4
4
|
"description": "Vue adapter for Lunora — live composables, optimistic mutations, and reactive loaders",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"directory": "packages/vue"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"dist",
|
|
28
|
+
"./dist",
|
|
29
29
|
"README.md",
|
|
30
30
|
"LICENSE.md",
|
|
31
31
|
"__assets__"
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"types": "./dist/server.d.ts",
|
|
45
45
|
"import": "./dist/server.mjs"
|
|
46
46
|
},
|
|
47
|
-
"./
|
|
48
|
-
"types": "./dist/
|
|
49
|
-
"import": "./dist/
|
|
47
|
+
"./upload": {
|
|
48
|
+
"types": "./dist/upload.d.ts",
|
|
49
|
+
"import": "./dist/upload.mjs"
|
|
50
50
|
},
|
|
51
51
|
"./package.json": "./package.json"
|
|
52
52
|
},
|
|
@@ -54,9 +54,11 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@lunora/client": "1.0.0-alpha.
|
|
58
|
-
"@lunora/
|
|
59
|
-
"@lunora/
|
|
57
|
+
"@lunora/client": "1.0.0-alpha.263",
|
|
58
|
+
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
59
|
+
"@lunora/ratelimit": "1.0.0-alpha.181",
|
|
60
|
+
"@lunora/wire": "1.0.0-alpha.3",
|
|
61
|
+
"@visulima/storage-client": "1.0.9"
|
|
60
62
|
},
|
|
61
63
|
"peerDependencies": {
|
|
62
64
|
"vue": "^3.5.0"
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { defineComponent, computed } from 'vue';
|
|
2
|
-
import { useAuth } from './useAuth-C2aEzXXH.mjs';
|
|
3
|
-
|
|
4
|
-
const Authenticated = defineComponent({
|
|
5
|
-
name: "Authenticated",
|
|
6
|
-
setup(_props, { slots }) {
|
|
7
|
-
const { token, user } = useAuth();
|
|
8
|
-
const isAuthenticated = computed(() => token.value !== null && user.value !== null);
|
|
9
|
-
return () => isAuthenticated.value ? slots.default?.() : void 0;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
const Unauthenticated = defineComponent({
|
|
13
|
-
name: "Unauthenticated",
|
|
14
|
-
setup(_props, { slots }) {
|
|
15
|
-
const { token, user } = useAuth();
|
|
16
|
-
const isLoading = computed(() => token.value !== null && user.value === null);
|
|
17
|
-
return () => !isLoading.value && token.value === null ? slots.default?.() : void 0;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
const AuthLoading = defineComponent({
|
|
21
|
-
name: "AuthLoading",
|
|
22
|
-
setup(_props, { slots }) {
|
|
23
|
-
const { token, user } = useAuth();
|
|
24
|
-
const isLoading = computed(() => token.value !== null && user.value === null);
|
|
25
|
-
return () => isLoading.value ? slots.default?.() : void 0;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
export { AuthLoading, Authenticated, Unauthenticated };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { inject, provide } from 'vue';
|
|
2
|
-
|
|
3
|
-
const LUNORA_INJECTION_KEY = /* @__PURE__ */ Symbol("lunora.client");
|
|
4
|
-
const createLunora = (client) => {
|
|
5
|
-
return {
|
|
6
|
-
install(app) {
|
|
7
|
-
app.provide(LUNORA_INJECTION_KEY, client);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
const provideLunora = (client) => {
|
|
12
|
-
provide(LUNORA_INJECTION_KEY, client);
|
|
13
|
-
};
|
|
14
|
-
const useLunora = () => {
|
|
15
|
-
const client = inject(LUNORA_INJECTION_KEY, void 0);
|
|
16
|
-
if (!client) {
|
|
17
|
-
throw new Error("useLunora(): no LunoraClient provided — call app.use(createLunora(client)) or provideLunora(client) in a parent setup().");
|
|
18
|
-
}
|
|
19
|
-
return client;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export { LUNORA_INJECTION_KEY, createLunora, provideLunora, useLunora };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useLunora } from './LUNORA_INJECTION_KEY-DtFXLDQ_.mjs';
|
|
2
|
-
import { subscribeToQuery } from './subscribeToQuery-Cv5YL-SI.mjs';
|
|
3
|
-
|
|
4
|
-
const hydratePreloaded = (preloaded) => {
|
|
5
|
-
const client = useLunora();
|
|
6
|
-
const { args, functionPath, shardKey, value } = preloaded;
|
|
7
|
-
const functionReference = { __lunoraRef: functionPath };
|
|
8
|
-
return subscribeToQuery(client, functionReference, args, {
|
|
9
|
-
seed: value,
|
|
10
|
-
shardKey
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export { hydratePreloaded };
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { createQuerySubscription } from '@lunora/client/query';
|
|
2
|
-
import { shallowRef, getCurrentScope, onScopeDispose, watch, toValue } from 'vue';
|
|
3
|
-
import { useLunora } from './LUNORA_INJECTION_KEY-DtFXLDQ_.mjs';
|
|
4
|
-
|
|
5
|
-
const subscribeToQuery = (client, function_, args, options = {}) => {
|
|
6
|
-
const data = shallowRef(options.seed);
|
|
7
|
-
const unsubscribe = client.subscribe(
|
|
8
|
-
function_,
|
|
9
|
-
args,
|
|
10
|
-
(value) => {
|
|
11
|
-
data.value = value;
|
|
12
|
-
},
|
|
13
|
-
{ shardKey: options.shardKey }
|
|
14
|
-
);
|
|
15
|
-
if (getCurrentScope()) {
|
|
16
|
-
onScopeDispose(unsubscribe);
|
|
17
|
-
} else {
|
|
18
|
-
console.warn(
|
|
19
|
-
"[@lunora/vue] subscribeToQuery called with no active effect scope — its subscription will not be cleaned up automatically. Call it inside setup()/an effect scope, or call the returned teardown yourself."
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
const useQuery = (function_, args, options = {}) => {
|
|
25
|
-
const client = useLunora();
|
|
26
|
-
const data = shallowRef(void 0);
|
|
27
|
-
watch(
|
|
28
|
-
() => toValue(args),
|
|
29
|
-
(current, _previous, onCleanup) => {
|
|
30
|
-
const unsubscribe = createQuerySubscription(
|
|
31
|
-
client,
|
|
32
|
-
function_,
|
|
33
|
-
current,
|
|
34
|
-
{
|
|
35
|
-
onData: (value) => {
|
|
36
|
-
data.value = value;
|
|
37
|
-
},
|
|
38
|
-
onReset: () => {
|
|
39
|
-
data.value = void 0;
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
{ shardKey: options.shardKey }
|
|
43
|
-
);
|
|
44
|
-
onCleanup(unsubscribe);
|
|
45
|
-
},
|
|
46
|
-
{ immediate: true }
|
|
47
|
-
);
|
|
48
|
-
return data;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export { subscribeToQuery, useQuery };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { getIdentityStore } from '@lunora/client/auth';
|
|
2
|
-
import { ref, onScopeDispose, readonly } from 'vue';
|
|
3
|
-
import { useLunora } from './LUNORA_INJECTION_KEY-DtFXLDQ_.mjs';
|
|
4
|
-
|
|
5
|
-
const useAuth = () => {
|
|
6
|
-
const client = useLunora();
|
|
7
|
-
const store = getIdentityStore(client);
|
|
8
|
-
const tokenRef = ref(client.getAuthToken());
|
|
9
|
-
const userRef = ref(store.getUser());
|
|
10
|
-
const onTokenChange = () => {
|
|
11
|
-
tokenRef.value = client.getAuthToken();
|
|
12
|
-
};
|
|
13
|
-
const onUserChange = () => {
|
|
14
|
-
userRef.value = store.getUser();
|
|
15
|
-
};
|
|
16
|
-
const unsubToken = client.onAuthTokenChange(onTokenChange);
|
|
17
|
-
const unsubUser = store.subscribe(onUserChange);
|
|
18
|
-
onScopeDispose(() => {
|
|
19
|
-
unsubToken();
|
|
20
|
-
unsubUser();
|
|
21
|
-
});
|
|
22
|
-
const setToken = (next) => {
|
|
23
|
-
client.setAuthToken(next);
|
|
24
|
-
};
|
|
25
|
-
return { setToken, token: readonly(tokenRef), user: readonly(userRef) };
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { useAuth };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { shallowRef, getCurrentScope, onScopeDispose } from 'vue';
|
|
2
|
-
import { useLunora } from './LUNORA_INJECTION_KEY-DtFXLDQ_.mjs';
|
|
3
|
-
|
|
4
|
-
const useConnectionStatus = () => {
|
|
5
|
-
const client = useLunora();
|
|
6
|
-
const status = shallowRef(client.connectionStatus());
|
|
7
|
-
const unsubscribe = client.onConnectionStatus((next) => {
|
|
8
|
-
status.value = next;
|
|
9
|
-
});
|
|
10
|
-
if (getCurrentScope()) {
|
|
11
|
-
onScopeDispose(unsubscribe);
|
|
12
|
-
} else {
|
|
13
|
-
console.warn(
|
|
14
|
-
"[@lunora/vue] useConnectionStatus called with no active effect scope — its listener will not be cleaned up automatically. Call it inside setup()/an effect scope."
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
return status;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export { useConnectionStatus as default };
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { shallowRef, watch, toValue, onScopeDispose, computed } from 'vue';
|
|
2
|
-
import { initialPages, derivePaginationStatus, rebalance, applyLoadMore } from '@lunora/client/pagination';
|
|
3
|
-
import { useLunora } from './LUNORA_INJECTION_KEY-DtFXLDQ_.mjs';
|
|
4
|
-
|
|
5
|
-
const buildPageKey = (functionPath, pageArgs) => `${functionPath}::${JSON.stringify(pageArgs)}`;
|
|
6
|
-
const buildPageArgs = (page, baseArgs) => {
|
|
7
|
-
return {
|
|
8
|
-
...baseArgs,
|
|
9
|
-
paginationOpts: { cursor: page.lower, endCursor: page.upper, numItems: page.numItems }
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
const usePaginatedCore = (function_, args, options) => {
|
|
13
|
-
const client = useLunora();
|
|
14
|
-
const { initialNumItems, shardKey } = options;
|
|
15
|
-
const pages = shallowRef(initialPages(initialNumItems));
|
|
16
|
-
const pageResults = shallowRef([]);
|
|
17
|
-
const activeSubs = /* @__PURE__ */ new Map();
|
|
18
|
-
const resultsByKey = /* @__PURE__ */ new Map();
|
|
19
|
-
const pendingPageKeys = /* @__PURE__ */ new Set();
|
|
20
|
-
const rebuildPageResults = (currentPages, baseArgs) => {
|
|
21
|
-
pageResults.value = currentPages.map((page) => {
|
|
22
|
-
const key = buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs));
|
|
23
|
-
return resultsByKey.get(key);
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
const migrateResultsForRebalance = (oldPages, newPages, baseArgs) => {
|
|
27
|
-
const keyOf = (page) => buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs));
|
|
28
|
-
for (const newPage of newPages) {
|
|
29
|
-
const newKey = keyOf(newPage);
|
|
30
|
-
if (resultsByKey.has(newKey)) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
const donor = oldPages.find((op) => op.lower === newPage.lower);
|
|
34
|
-
if (donor) {
|
|
35
|
-
const carried = resultsByKey.get(keyOf(donor));
|
|
36
|
-
if (carried) {
|
|
37
|
-
resultsByKey.set(newKey, carried);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const syncSubscriptions = (currentPages, baseArgs) => {
|
|
43
|
-
const wantedKeys = /* @__PURE__ */ new Set();
|
|
44
|
-
for (const page of currentPages) {
|
|
45
|
-
wantedKeys.add(buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs)));
|
|
46
|
-
}
|
|
47
|
-
for (const [originalKey, entry] of activeSubs) {
|
|
48
|
-
if (!wantedKeys.has(entry.currentKey)) {
|
|
49
|
-
entry.unsub();
|
|
50
|
-
activeSubs.delete(originalKey);
|
|
51
|
-
resultsByKey.delete(entry.currentKey);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const coveredKeys = new Set([...activeSubs.values()].map((subEntry) => subEntry.currentKey));
|
|
55
|
-
for (const page of currentPages) {
|
|
56
|
-
const pageArgs = buildPageArgs(page, baseArgs);
|
|
57
|
-
const key = buildPageKey(function_["__lunoraRef"], pageArgs);
|
|
58
|
-
if (coveredKeys.has(key)) {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
const entry = {
|
|
62
|
-
currentKey: key,
|
|
63
|
-
unsub: void 0
|
|
64
|
-
};
|
|
65
|
-
pendingPageKeys.add(key);
|
|
66
|
-
const unsub = client.subscribe(
|
|
67
|
-
function_,
|
|
68
|
-
pageArgs,
|
|
69
|
-
(value) => {
|
|
70
|
-
resultsByKey.set(entry.currentKey, value);
|
|
71
|
-
pendingPageKeys.delete(entry.currentKey);
|
|
72
|
-
const currentBaseArgs = toValue(args);
|
|
73
|
-
rebuildPageResults(pages.value, currentBaseArgs);
|
|
74
|
-
if (pendingPageKeys.size === 0) {
|
|
75
|
-
const latestPages = pages.value;
|
|
76
|
-
const next = rebalance(latestPages, pageResults.value);
|
|
77
|
-
if (next) {
|
|
78
|
-
migrateResultsForRebalance(latestPages, next, currentBaseArgs);
|
|
79
|
-
pages.value = next;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
{ shardKey }
|
|
84
|
-
);
|
|
85
|
-
entry.unsub = unsub;
|
|
86
|
-
activeSubs.set(key, entry);
|
|
87
|
-
coveredKeys.add(key);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
const teardownAll = () => {
|
|
91
|
-
for (const entry of activeSubs.values()) {
|
|
92
|
-
entry.unsub();
|
|
93
|
-
}
|
|
94
|
-
activeSubs.clear();
|
|
95
|
-
resultsByKey.clear();
|
|
96
|
-
};
|
|
97
|
-
watch(
|
|
98
|
-
() => toValue(args),
|
|
99
|
-
(current) => {
|
|
100
|
-
teardownAll();
|
|
101
|
-
pages.value = initialPages(initialNumItems);
|
|
102
|
-
pageResults.value = [];
|
|
103
|
-
if (current !== "skip") {
|
|
104
|
-
syncSubscriptions(pages.value, current);
|
|
105
|
-
rebuildPageResults(pages.value, current);
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
{ immediate: true }
|
|
109
|
-
);
|
|
110
|
-
watch(
|
|
111
|
-
() => pages.value,
|
|
112
|
-
(currentPages) => {
|
|
113
|
-
const current = toValue(args);
|
|
114
|
-
if (current !== "skip") {
|
|
115
|
-
syncSubscriptions(currentPages, current);
|
|
116
|
-
rebuildPageResults(currentPages, current);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
);
|
|
120
|
-
onScopeDispose(teardownAll);
|
|
121
|
-
const status = shallowRef("LoadingFirstPage");
|
|
122
|
-
watch(
|
|
123
|
-
[() => toValue(args), pageResults],
|
|
124
|
-
([currentArgs, currentResults]) => {
|
|
125
|
-
status.value = derivePaginationStatus(currentArgs === "skip", currentResults).status;
|
|
126
|
-
},
|
|
127
|
-
{ immediate: true }
|
|
128
|
-
);
|
|
129
|
-
const loadMore = (numberItems) => {
|
|
130
|
-
const currentArgs = toValue(args);
|
|
131
|
-
if (currentArgs === "skip") {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
const { nextCursor, status: currentStatus } = derivePaginationStatus(false, pageResults.value);
|
|
135
|
-
if (currentStatus !== "CanLoadMore") {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const next = applyLoadMore(pages.value, nextCursor, numberItems);
|
|
139
|
-
if (!next) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
const oldTail = pages.value.at(-1);
|
|
143
|
-
const newPinnedPage = next.at(-2);
|
|
144
|
-
if (oldTail && newPinnedPage) {
|
|
145
|
-
const oldKey = buildPageKey(function_["__lunoraRef"], buildPageArgs(oldTail, currentArgs));
|
|
146
|
-
const newKey = buildPageKey(function_["__lunoraRef"], buildPageArgs(newPinnedPage, currentArgs));
|
|
147
|
-
const entry = activeSubs.get(oldKey);
|
|
148
|
-
if (entry && oldKey !== newKey) {
|
|
149
|
-
entry.currentKey = newKey;
|
|
150
|
-
activeSubs.set(newKey, entry);
|
|
151
|
-
activeSubs.delete(oldKey);
|
|
152
|
-
const carried = resultsByKey.get(oldKey);
|
|
153
|
-
if (carried) {
|
|
154
|
-
resultsByKey.set(newKey, carried);
|
|
155
|
-
resultsByKey.delete(oldKey);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
pages.value = next;
|
|
160
|
-
};
|
|
161
|
-
return { loadMore, pageResults, status };
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const usePaginatedQuery = (function_, args, options) => {
|
|
165
|
-
const { loadMore, pageResults, status } = usePaginatedCore(function_, args, options);
|
|
166
|
-
const results = computed(() => {
|
|
167
|
-
const items = [];
|
|
168
|
-
for (const result of pageResults.value) {
|
|
169
|
-
if (result) {
|
|
170
|
-
items.push(...result.page);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return items;
|
|
174
|
-
});
|
|
175
|
-
const isLoading = computed(() => status.value === "LoadingFirstPage" || status.value === "LoadingMore");
|
|
176
|
-
return { isLoading, loadMore, results, status };
|
|
177
|
-
};
|
|
178
|
-
const useInfiniteQuery = (function_, args, options) => {
|
|
179
|
-
const { initialNumItems } = options;
|
|
180
|
-
const { loadMore, pageResults, status } = usePaginatedCore(function_, args, options);
|
|
181
|
-
const pages = computed(() => {
|
|
182
|
-
const result = [];
|
|
183
|
-
for (const page of pageResults.value) {
|
|
184
|
-
if (page) {
|
|
185
|
-
result.push(page.page);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
return result;
|
|
189
|
-
});
|
|
190
|
-
const isLoading = computed(() => status.value === "LoadingFirstPage");
|
|
191
|
-
const hasNextPage = computed(() => status.value === "CanLoadMore");
|
|
192
|
-
const isFetchingNextPage = computed(() => status.value === "LoadingMore");
|
|
193
|
-
const fetchNextPage = (numberItems) => {
|
|
194
|
-
loadMore(numberItems ?? initialNumItems);
|
|
195
|
-
};
|
|
196
|
-
return { fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, pages, status };
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
export { useInfiniteQuery, usePaginatedQuery };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { createMutationRunner } from '@lunora/client';
|
|
2
|
-
import { shallowRef, ref } from 'vue';
|
|
3
|
-
import { useLunora } from './LUNORA_INJECTION_KEY-DtFXLDQ_.mjs';
|
|
4
|
-
|
|
5
|
-
const useMutation = (function_) => {
|
|
6
|
-
const client = useLunora();
|
|
7
|
-
const data = shallowRef(void 0);
|
|
8
|
-
const error = shallowRef(void 0);
|
|
9
|
-
const pending = ref(false);
|
|
10
|
-
const reset = () => {
|
|
11
|
-
data.value = void 0;
|
|
12
|
-
error.value = void 0;
|
|
13
|
-
};
|
|
14
|
-
const mutate = createMutationRunner(client, function_, {
|
|
15
|
-
setError: (next) => {
|
|
16
|
-
error.value = next;
|
|
17
|
-
},
|
|
18
|
-
setPending: (next) => {
|
|
19
|
-
pending.value = next;
|
|
20
|
-
},
|
|
21
|
-
setResult: (result) => {
|
|
22
|
-
data.value = result;
|
|
23
|
-
error.value = void 0;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
return { data, error, mutate, pending, reset };
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export { useMutation };
|