@lunora/svelte 1.0.0-alpha.30 → 1.0.0-alpha.301
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/README.md +7 -2
- package/dist/index.d.mts +1195 -228
- package/dist/index.d.ts +1195 -228
- package/dist/index.mjs +1 -12
- package/dist/packem_shared/action-SjeZUGhX.mjs +1 -0
- package/dist/packem_shared/agent-WMVWf1Ks.mjs +1 -0
- package/dist/packem_shared/agentChat-COq1hXPF.mjs +1 -0
- package/dist/packem_shared/agentState-Bb7y6sQO.mjs +1 -0
- package/dist/packem_shared/agentToolEvents-ClR1HAg8.mjs +1 -0
- package/dist/packem_shared/auth-Z0G_aZYz.mjs +1 -0
- package/dist/packem_shared/connectionStatus-DMx3BE5Q.mjs +1 -0
- package/dist/packem_shared/flag-Csh9LBiO.mjs +1 -0
- package/dist/packem_shared/getLunoraClient-DU7BmZy1.mjs +1 -0
- package/dist/packem_shared/hydratePreloaded-CNm2-Rha.mjs +1 -0
- package/dist/packem_shared/infiniteQuery-yXChJPfW.mjs +1 -0
- package/dist/packem_shared/is-browser-BEdfLJHK.mjs +1 -0
- package/dist/packem_shared/is-function-reference-abFdrAae.mjs +1 -0
- package/dist/packem_shared/liveTopic-DKHSwXiX.mjs +1 -0
- package/dist/packem_shared/mutation-DLBr5Op1.mjs +1 -0
- package/dist/packem_shared/mutator-DECDuo94.mjs +1 -0
- package/dist/packem_shared/presence-BCd6RN33.mjs +1 -0
- package/dist/packem_shared/query-C6B__ZRN.mjs +1 -0
- package/dist/packem_shared/rateLimit-Cli38qWO.mjs +1 -0
- package/dist/packem_shared/stream-Cxl8guzh.mjs +1 -0
- package/dist/packem_shared/subscribe-reactive-args-D0fSbP1k.mjs +1 -0
- package/dist/packem_shared/subscription-CTzqm298.mjs +1 -0
- package/dist/packem_shared/voiceAgent-B7AkAkB_.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 +9 -8
- package/dist/packem_shared/auth-BeYqYP9S.mjs +0 -28
- package/dist/packem_shared/connectionStatus-BrICpw9d.mjs +0 -14
- package/dist/packem_shared/flag-CqMU07WH.mjs +0 -56
- package/dist/packem_shared/getLunoraClient-Prczj1gU.mjs +0 -17
- package/dist/packem_shared/hydratePreloaded-Djsf_C8Q.mjs +0 -21
- package/dist/packem_shared/infiniteQuery-BFsBpXnS.mjs +0 -196
- package/dist/packem_shared/is-function-reference-ycLAcI79.mjs +0 -3
- package/dist/packem_shared/mutation-BmkCZnTd.mjs +0 -31
- package/dist/packem_shared/mutator-B5LchgMS.mjs +0 -19
- package/dist/packem_shared/presence-UJKjdcKg.mjs +0 -66
- package/dist/packem_shared/query-BsJHHnAK.mjs +0 -36
- package/dist/packem_shared/rateLimit-Cdw1kp8t.mjs +0 -66
- package/dist/packem_shared/subscription-C121AbM_.mjs +0 -46
- 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,12 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { connectionStatus } from './packem_shared/connectionStatus-BrICpw9d.mjs';
|
|
3
|
-
export { getLunoraClient, setLunoraClient } from './packem_shared/getLunoraClient-Prczj1gU.mjs';
|
|
4
|
-
export { flag, flags } from './packem_shared/flag-CqMU07WH.mjs';
|
|
5
|
-
export { hydratePreloaded } from './packem_shared/hydratePreloaded-Djsf_C8Q.mjs';
|
|
6
|
-
export { mutation } from './packem_shared/mutation-BmkCZnTd.mjs';
|
|
7
|
-
export { mutator } from './packem_shared/mutator-B5LchgMS.mjs';
|
|
8
|
-
export { infiniteQuery, paginatedQuery } from './packem_shared/infiniteQuery-BFsBpXnS.mjs';
|
|
9
|
-
export { presence } from './packem_shared/presence-UJKjdcKg.mjs';
|
|
10
|
-
export { query } from './packem_shared/query-BsJHHnAK.mjs';
|
|
11
|
-
export { rateLimit } from './packem_shared/rateLimit-Cdw1kp8t.mjs';
|
|
12
|
-
export { subscription } from './packem_shared/subscription-C121AbM_.mjs';
|
|
1
|
+
import{action as t}from"./packem_shared/action-SjeZUGhX.mjs";import{agent as m}from"./packem_shared/agent-WMVWf1Ks.mjs";import{agentChat as a}from"./packem_shared/agentChat-COq1hXPF.mjs";import{agentState as n}from"./packem_shared/agentState-Bb7y6sQO.mjs";import{agentToolEvents as i}from"./packem_shared/agentToolEvents-ClR1HAg8.mjs";import{auth as g,authGate as s}from"./packem_shared/auth-Z0G_aZYz.mjs";import{connectionStatus as l}from"./packem_shared/connectionStatus-DMx3BE5Q.mjs";import{getLunoraClient as h,setLunoraClient as y}from"./packem_shared/getLunoraClient-DU7BmZy1.mjs";import{flag as C,flags as L}from"./packem_shared/flag-Csh9LBiO.mjs";import{hydratePreloaded as S}from"./packem_shared/hydratePreloaded-CNm2-Rha.mjs";import{liveTopic as b}from"./packem_shared/liveTopic-DKHSwXiX.mjs";import{mutation as A}from"./packem_shared/mutation-DLBr5Op1.mjs";import{mutator as G}from"./packem_shared/mutator-DECDuo94.mjs";import{infiniteQuery as j,paginatedQuery as k}from"./packem_shared/infiniteQuery-yXChJPfW.mjs";import{presence as z}from"./packem_shared/presence-BCd6RN33.mjs";import{query as D}from"./packem_shared/query-C6B__ZRN.mjs";import{rateLimit as H}from"./packem_shared/rateLimit-Cli38qWO.mjs";import{stream as J}from"./packem_shared/stream-Cxl8guzh.mjs";import{subscription as M}from"./packem_shared/subscription-CTzqm298.mjs";import{voiceAgent as O}from"./packem_shared/voiceAgent-B7AkAkB_.mjs";export{t as action,m as agent,a as agentChat,n as agentState,i as agentToolEvents,g as auth,s as authGate,l as connectionStatus,C as flag,L as flags,h as getLunoraClient,S as hydratePreloaded,j as infiniteQuery,b as liveTopic,A as mutation,G as mutator,k as paginatedQuery,z as presence,D as query,H as rateLimit,y as setLunoraClient,J as stream,M as subscription,O as voiceAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createCallRunner as f}from"@lunora/client";import{writable as s}from"svelte/store";import{getLunoraClient as p}from"./getLunoraClient-DU7BmZy1.mjs";function R(n,r){const i=r!==void 0,l=i?n:p(),a=i?r:n,o=s(),e=s(),c=s(!1);return{call:f((t,d)=>l.action(a,t,d),{setError:t=>{e.set(t)},setPending:t=>{c.set(t)},setResult:t=>{o.set(t),e.set(void 0)}}),data:o,error:e,pending:c,reset:()=>{o.set(void 0),e.set(void 0)}}}export{R as action};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{writable as d}from"svelte/store";import{i as T}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as _}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as f}from"./mutation-DLBr5Op1.mjs";const A={__lunoraRef:""},C=t=>typeof t=="object"&&t!==null&&typeof t.subscribe=="function",E=(t,r)=>{const{api:e,cancel:s,onError:a,run:m,runArgs:p,threadKey:c}=r,i=f(t,m),l=f(t,s??A);let o;const u=d(),b=d(),g=T()?t.subscribe(e.agents.agentThread,{key:c},n=>{o=n,u.set(o),b.set(o?.status)},{onError:a}):()=>{},h=async(n,R)=>{await i.mutate({input:n,threadKey:c,...p,...R})},y=async()=>{const n=o?.instanceId;s===void 0||n===void 0||await l.mutate({instanceId:n,threadKey:c})},w=()=>{g()};return{cancel:y,pending:i.pending,run:h,status:{subscribe:b.subscribe},teardown:w,thread:{subscribe:u.subscribe}}};function S(t,r){const e=C(t),s=e?t:_();return E(s,e?r:t)}export{A as NO_MUTATION_REF,S as agent,C as isClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{reconcileOptimistic as R,maxSeq as _}from"@lunora/client";import{writable as l}from"svelte/store";import{i as b}from"./is-browser-BEdfLJHK.mjs";import{isClient as tt,NO_MUTATION_REF as et}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as st}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as i}from"./mutation-DLBr5Op1.mjs";import{stream as nt}from"./stream-Cxl8guzh.mjs";const rt={__lunoraRef:""},at=(n,d)=>{const{api:a,cancel:p,limit:g,onError:v,send:C,sendArgs:E,stream:S,threadKey:r}=d,I=i(n,C),G=i(n,p??et),q=i(n,a.agents.agentResolveApproval),j=i(n,a.agents.agentRevokeApprovalGrant),D=i(n,a.agents.agentSupplySecret),F=i(n,a.agents.agentDeclineSecret);let m,o=[],u=[],w=[],k=0;const y=l([]),x=l(),A=l([]),T=l(""),h=()=>{const t=R(u,o);if(t.length===0){y.set(o);return}const e=_(o);y.set([...o,...t.map((s,c)=>({content:s.content,optimistic:!0,role:"user",seq:e+1+c}))])},M=()=>{const t=o.filter(s=>s.role==="assistant").length,e=w.filter(s=>s.kind!=="progress"&&s.threadKey===r&&s.turn>=t).map(s=>s.text).join("");T.set(e)},N=S===void 0?"skip":{key:r},H=b()?nt(n,S??rt,N).chunks.subscribe(t=>{w=t,M()}):()=>{},K=g===void 0?{key:r}:{key:r,limit:g},B=b()?n.subscribe(a.agents.agentMessages,K,t=>{o=t,h(),M()},{onError:v}):()=>{},L=b()?n.subscribe(a.agents.agentThread,{key:r},t=>{m=t,x.set(m?.status)},{onError:v}):()=>{},O=b()?n.subscribe(a.agents.agentApprovalGrants,{key:r},t=>{A.set(t)},{onError:v}):()=>{},U=async(t,e)=>{const s=k;k+=1;const c=_(o);u=[...R(u,o),{content:t,id:s,maxDurableSeqAtSend:c}],h();try{await I.mutate({input:t,threadKey:r,...E,...e})}catch(Y){throw u=u.filter(Z=>Z.id!==s),h(),Y}},f=async(t,e,s)=>{const c=m?.instanceId;if(c===void 0)throw new Error(`agentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await q.mutate({decision:t,instanceId:c,threadKey:r,toolCallId:e,...s===void 0?{}:{note:s}})},$=async(t,e)=>f("approve",t,e),z=async(t,e)=>f("approve_for_thread",t,e),J=async(t,e)=>f("reject",t,e),P=async t=>{await j.mutate({threadKey:r,toolName:t})},Q=async(t,e)=>{await D.mutate({secret:e,threadKey:r,toolCallId:t},{onlineOnly:!0})},V=async t=>{await F.mutate({threadKey:r,toolCallId:t})},W=async()=>{const t=m?.instanceId;p===void 0||t===void 0||await G.mutate({instanceId:t,threadKey:r})},X=()=>{B(),L(),O(),H()};return{approvalGrants:{subscribe:A.subscribe},approve:$,approveForThread:z,cancel:W,declineSecret:V,messages:{subscribe:y.subscribe},reject:J,revokeGrant:P,send:U,status:{subscribe:x.subscribe},streamingText:{subscribe:T.subscribe},supplySecret:Q,teardown:X}};function bt(n,d){const a=tt(n),p=a?n:st();return at(p,a?d:n)}export{bt as agentChat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{derived as c}from"svelte/store";import{isClient as p}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as f}from"./getLunoraClient-DU7BmZy1.mjs";import{subscription as d}from"./subscription-CTzqm298.mjs";function h(t,r){const o=p(t),n=o?t:f(),e=o?r:t,{data:i,error:a}=d(n,e.api.agents.agentState,{key:e.threadKey}),s=c(i,m=>m);return{error:a,state:s}}export{h as agentState};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{derived as y}from"svelte/store";import{isClient as E}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as I}from"./getLunoraClient-DU7BmZy1.mjs";import{stream as N}from"./stream-Cxl8guzh.mjs";import{subscription as m}from"./subscription-CTzqm298.mjs";const _={__lunoraRef:""},h={awaiting_approval:"awaiting-approval",awaiting_secret:"awaiting-secret"},k=t=>{const o=t.status===void 0?void 0:h[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}}},q=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=k(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}}]};function x(t,o){const r=E(t),a=r?t:I(),s=r?o:t,{api:u,limit:e,stream:i,threadKey:l}=s,p=e===void 0?{key:l}:{key:l,limit:e},{data:c}=m(a,u.agents.agentMessages,p),v=N(a,i??_,i===void 0?"skip":{key:l});return{events:y([c,v.chunks],([f,C])=>{const d=(f??[]).flatMap(n=>q(n)??[]);for(const n of C)n.kind==="progress"&&n.threadKey===l&&d.push({data:n.data,toolCallId:n.toolCallId,type:"progress"});return d})}}export{x as agentToolEvents};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getIdentityStore as h,isLoadingStatus as d,isAuthenticatedStatus as m}from"@lunora/client/auth";import{readable as o,derived as a}from"svelte/store";import{i as u}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as f}from"./getLunoraClient-DU7BmZy1.mjs";const k=s=>{const r=s??f(),t=h(r),i=o(r.getAuthToken(),e=>(e(r.getAuthToken()),u()?r.onAuthTokenChange(g=>{e(g)}):()=>{})),n=o(t.getUser(),e=>(e(t.getUser()),u()?t.subscribe(()=>{e(t.getUser())}):()=>{})),c=o(t.getStatus(),e=>(e(t.getStatus()),u()?t.subscribe(()=>{e(t.getStatus())}):()=>{}));return{setToken:e=>{r.setAuthToken(e)},status:c,token:i,user:n}},l=s=>{const{status:r}=k(s),t=a(r,n=>d(n));return{isAuthenticated:a(r,n=>m(n)),isLoading:t}};export{k as auth,l as authGate};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readable as e}from"svelte/store";import{i}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as c}from"./getLunoraClient-DU7BmZy1.mjs";const m=n=>{const t=n??c();return e(t.connectionStatus(),o=>(o(t.connectionStatus()),i()?t.onConnectionStatus(r=>{o(r)}):()=>{}))};export{m as connectionStatus};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readable as l}from"svelte/store";import{i as m}from"./is-browser-BEdfLJHK.mjs";import{isClient as i}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as a}from"./getLunoraClient-DU7BmZy1.mjs";const _="__lunora_flags__:eval",g=e=>{const t=typeof e;return t==="boolean"||t==="number"||t==="string"?t:"object"},h={__lunoraRef:_},k=(e,t,n)=>{try{return e.subscribe(h,{default:t.default,key:t.key,type:g(t.default)},o=>{n(o)},{onError:()=>{n(t.default)}})}catch{return()=>{}}},b=(e,t,n,o)=>m()?k(e,{default:n,key:t},o):()=>{};function A(e,t,n){const o=i(e),s=o?e:a(),f=o?t:e,r=o?n:t;return l(r,u=>b(s,f,r,u))}function L(e,t){const n=i(e),o=n?e:a(),s=n?t:e;return l(s,f=>{let r={...s};const u=[];for(const[c,p]of Object.entries(s))u.push(b(o,c,p,d=>{r={...r,[c]:d},f(r)}));return()=>{for(const c of u)c()}})}export{A as flag,L as flags};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as o}from"@lunora/errors";import{setContext as e,getContext as r}from"svelte";const n=Symbol("lunora.client"),a=t=>(e(n,t),t),c=()=>{const t=r(n);if(!t)throw new o("INTERNAL","getLunoraClient(): no LunoraClient in context — call setLunoraClient(client) in an ancestor component first.");return t};export{c as getLunoraClient,a as setLunoraClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readable as h}from"svelte/store";import{i as m}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as p}from"./getLunoraClient-DU7BmZy1.mjs";const g=(t,e,i={})=>{const o=e??p(),{args:s,functionPath:a,shardKey:c,value:d}=t,f={__lunoraRef:a};return h(o.identityEpoch()===0?d:void 0,r=>{if(!m())return()=>{};const n=()=>{r(void 0)};o.identityEpoch()!==0&&n();const u=o.onIdentityChange(n),l=o.subscribe(f,s,b=>{r(b)},{onError:i.onError,shardKey:c});return()=>{u(),l()}})};export{g as hydratePreloaded};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{initialPages as $,derivePaginationStatus as q,applyLoadMore as J,rebalance as U}from"@lunora/client/pagination";import{stableWireKey as V}from"@lunora/wire";import{derived as v,writable as W,readable as X,get as S}from"svelte/store";import{i as Y}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as F}from"./getLunoraClient-DU7BmZy1.mjs";import{i as T}from"./is-function-reference-abFdrAae.mjs";import{i as Z,s as O}from"./subscribe-reactive-args-D0fSbP1k.mjs";const z=(n,l)=>({...l,paginationOpts:{cursor:n.lower,endCursor:n.upper,numItems:n.numItems}}),ee=(n,l)=>`${n}::${V(l)}`,_=(n,l,h,C)=>{const{initialNumItems:u,onError:I,shardKey:N}=C,i=W($(u)),w=W(),b=W([]),o=new Map,d=new Map,R=new Set;let s=Z(h)?"skip":h,k=new WeakMap;const y=(e,g)=>{let r=k.get(e);return r===void 0&&(r=ee(l.__lunoraRef,z(e,g)),k.set(e,r)),r},f=()=>{if(s==="skip"){b.set([]);return}const e=s,g=S(i).map(r=>{const t=y(r,e);return o.get(t)});b.set(g)},x=(e,g)=>{if(s==="skip")return;const r=s,t=P=>y(P,r);for(const P of g){const a=t(P);if(o.has(a))continue;const L=e.find(p=>p.lower===P.lower);if(L){const p=o.get(t(L));p&&o.set(a,p)}}},E=()=>{if(s==="skip"){for(const t of d.values())t();d.clear(),b.set([]);return}const e=s,g=S(i),r=new Set;for(const t of g)r.add(y(t,e));for(const[t,P]of d)r.has(t)||(P(),d.delete(t),R.delete(t),o.delete(t));for(const t of g){const P=z(t,e),a=y(t,e);if(d.has(a))continue;R.add(a);const L=n.subscribe(l,P,p=>{if(o.set(a,p),R.delete(a),w.set(void 0),f(),R.size===0){const M=S(i),K=U(M,S(b));K&&(x(M,K),i.set(K),m(),f())}},{onError:p=>{R.delete(a),w.set(p);const M=S(i),K=M.at(-1);M.length>1&&K&&!o.has(a)&&y(K,e)===a&&(i.set(M.slice(0,-1)),m(),f()),I?.(p)},shardKey:N});d.set(a,L)}};let A=!1,c=!1;const m=()=>{if(A){c=!0;return}A=!0;try{do c=!1,E();while(c)}finally{A=!1}},j=()=>{for(const e of d.values())e();d.clear(),o.clear(),R.clear(),k=new WeakMap},B=X([],e=>{if(!Y())return()=>{};const g=b.subscribe(e),r=O(h,t=>(s=t,m(),f(),()=>{j(),i.set($(u)),w.set(void 0)}));return()=>{r(),g(),b.set([])}}),D=v(B,e=>q(s==="skip",e).status),G=v(B,()=>s==="skip"),H=e=>{if(s==="skip")return;const g=S(b),{nextCursor:r,status:t}=q(!1,g);if(t!=="CanLoadMore")return;const P=S(i),a=J(P,r,e);if(!a)return;const L=P.at(-1),p=a.at(-2);if(L&&p){const M=y(L,s),K=y(p,s);if(M!==K){const Q=o.get(M);Q&&(o.set(K,Q),o.delete(M))}}w.set(void 0),i.set(a),m(),f()};return{error:{subscribe:w.subscribe},loadMore:H,pageResults:B,skipped:G,status:D}};function ce(n,l,h,C){const u=!T(n),I=u?n:F(),N=u?l:n,i=u?h:l,w=u?C:h,{error:b,loadMore:o,pageResults:d,skipped:R,status:s}=_(I,N,i,w),k=v(d,f=>f.flatMap(x=>x?.page??[])),y=v([s,R],([f,x])=>!x&&(f==="LoadingFirstPage"||f==="LoadingMore"));return{error:b,isLoading:y,loadMore:o,results:k,status:s}}function le(n,l,h,C){const u=!T(n),I=u?n:F(),N=u?l:n,i=u?h:l,w=u?C:h,{initialNumItems:b}=w,{error:o,loadMore:d,pageResults:R,skipped:s,status:k}=_(I,N,i,w),y=v(R,c=>c.flatMap(m=>m?[m.page]:[])),f=v([k,s],([c,m])=>!m&&c==="LoadingFirstPage"),x=v(k,c=>c==="CanLoadMore"),E=v([k,s],([c,m])=>!m&&c==="LoadingMore");return{error:o,fetchNextPage:c=>{d(c??b)},hasNextPage:x,isFetchingNextPage:E,isLoading:f,pages:y,status:k}}export{le as infiniteQuery,ce as paginatedQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=()=>globalThis.window!==void 0;export{o as i};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const n=e=>typeof e=="object"&&e!==null&&typeof e.__lunoraRef=="string";export{n as i};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{liveTopicSubscription as p,subscribeLiveTopic as y}from"@lunora/client";import{readable as c,derived as f}from"svelte/store";import{i as E}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as h}from"./getLunoraClient-DU7BmZy1.mjs";import{i as l,s as D}from"./subscribe-reactive-args-D0fSbP1k.mjs";const S=r=>({headers:r.headers,maxDelayMs:r.maxDelayMs,retryDelay:r.retryDelay,sessionKey:r.sessionKey,topic:r.topic,url:r.url,withCredentials:r.withCredentials}),g=(r,i={})=>{const v=h();return c({error:void 0,lastEvent:void 0},s=>{if(!E())return;const u=l(r)?r:c(r),a=l(i)?i:c(i);let n={};const d=a.subscribe(t=>{n=t}),m=t=>{let e;return s({error:void 0,lastEvent:e}),y({...t,onError:o=>{s({error:o,lastEvent:e}),n.onError?.(o)},onEvent:o=>{e=o,s({error:void 0,lastEvent:e}),n.onEvent?.(o)}})},b=D(f([u,a],([t,e])=>S(p(v,t,e))),m);return()=>{b(),d()}})};export{g as liveTopic};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createCallRunner as f}from"@lunora/client";import{writable as s}from"svelte/store";import{getLunoraClient as u}from"./getLunoraClient-DU7BmZy1.mjs";function R(n,r){const i=r!==void 0,c=i?n:u(),l=i?r:n,o=s(),e=s(),a=s(!1),m=f((t,d)=>c.mutation(l,t,d),{setError:t=>{e.set(t)},setPending:t=>{a.set(t)},setResult:t=>{o.set(t),e.set(void 0)}});return{data:o,error:e,mutate:m,pending:a,reset:()=>{o.set(void 0),e.set(void 0)}}}export{R as mutation};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMutatorRunner as c}from"@lunora/client";import{writable as o,derived as m}from"svelte/store";const p=n=>{const t=o(),e=o(!1),s=m(t,r=>r!==void 0),{mutate:i,reset:a}=c(n,{setError:r=>{t.set(r)},setPending:r=>{e.set(r)}});return{error:t,isError:s,mutate:i,pending:e,reset:a}};export{p as mutator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{onDestroy as I}from"svelte";import{writable as S,readable as U}from"svelte/store";import{i as h}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as C}from"./getLunoraClient-DU7BmZy1.mjs";const D=e=>{if(!Number.isFinite(e)||e<=0)throw new RangeError(`presence intervalMs must be a positive number, got ${String(e)}`)},L=()=>{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")},V=1e4,x=(e,t,n)=>{const{heartbeat:r,intervalMs:s=V,listPresent:y,shardKey:i}=n;D(s);const d=n.sessionId??L();let f=n.data,u=!1;const a=()=>{const o={roomId:t,sessionId:d,...f===void 0?{}:{data:f}};e.mutation(r,o,{shardKey:i}).catch(()=>{})},w=o=>{f=o,u&&a()},p=()=>{typeof document<"u"&&document.visibilityState==="visible"&&a()};let l,b;h()&&(u=!0,a(),l=setInterval(a,s),typeof document<"u"&&document.addEventListener("visibilitychange",p),b=e.acquireConnectionContext({roomId:t,sessionId:d},{shardKey:i}));const m=S(),E=U(void 0,o=>{if(h())return e.subscribe(y,{roomId:t},c=>{o(c),m.set(void 0)},{onError:c=>{m.set(c),n.onError?.(c)},shardKey:i})});let v=!1;const g=()=>{v||(v=!0,u=!1,l!==void 0&&clearInterval(l),typeof document<"u"&&document.removeEventListener("visibilitychange",p),b?.())};try{I(g)}catch{}return{error:{subscribe:m.subscribe},present:E,sessionId:d,setData:w,teardown:g}};function F(e,t,n){const r=typeof e!="string",s=r?e:C();return x(s,r?t:e,r?n:t)}export{F as presence};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as u}from"@lunora/client/query";import{readable as d}from"svelte/store";import{i as b}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as v}from"./getLunoraClient-DU7BmZy1.mjs";import{i as y}from"./is-function-reference-abFdrAae.mjs";import{s as R}from"./subscribe-reactive-args-D0fSbP1k.mjs";function q(o,i,t,s){const r=!y(o),a=r?o:v(),c=r?i:o,p=r?t:i,n=(r?s:t)??{};return d(void 0,e=>b()?R(p,f=>(e(void 0),u(a,c,f,{onData:m=>{e(m)},onError:n.onError,onReset:()=>{e(void 0)}},{shardKey:n.shardKey}))):()=>{})}export{q as query};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{evaluate as v}from"@lunora/ratelimit";import{writable as y,derived as o}from"svelte/store";import{i as A}from"./is-browser-BEdfLJHK.mjs";const D=(n,f={})=>{const a=f.now??Date.now,k=f.tickMs??1e3;let e;const d=y(0),u=()=>{d.update(t=>t+1)},r=o(d,()=>v(n,e,{consume:!1,count:1,now:a(),reserve:!1}).status);let s;const c=()=>{s!==void 0&&(clearInterval(s),s=void 0)};let l=!0;const w=r.subscribe(t=>{l=t.ok}),m=()=>{l||s!==void 0||(s=setInterval(()=>{u(),l&&c()},k))};A()&&m();const p=(t=1)=>{const i=v(n,e,{consume:!0,count:t,now:a(),reserve:!1});return i.value!==void 0&&(e=i.value),u(),m(),i.status},b=(t=1)=>v(n,e,{consume:!1,count:t,now:a(),reserve:!1}).status.ok,I=()=>{e=void 0,c(),u()},h=()=>{c(),w()};return{check:b,consume:p,disabled:o(r,t=>!t.ok),ok:o(r,t=>t.ok),reset:I,retryAfter:o(r,t=>t.retryAfter),teardown:h}};export{D as rateLimit};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{writable as p,readable as g}from"svelte/store";import{i as B}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as R}from"./getLunoraClient-DU7BmZy1.mjs";import{i as I}from"./is-function-reference-abFdrAae.mjs";function z(c,u,f,h){const t=!I(c),v=t?c:R(),w=t?u:c,l=t?f:u,E=(t?h:f)??{},{durable:k,maxBuffer:x,shardKey:y}=E,e=p("idle"),n=p();let s;const m=()=>{s?.()},C=g([],b=>{if(b([]),n.set(void 0),!B())return e.set("idle"),()=>{};if(l==="skip")return e.set("idle"),()=>{};e.set("streaming");let o=!0,i=[];const d=v.stream(w,l,{durable:k,maxBuffer:x,shardKey:y}),a=()=>{d.cancel()};return s=a,(async()=>{try{for await(const r of d){if(!o)return;i=[...i,r],b(i)}o&&e.set("complete")}catch(r){if(!o)return;n.set(r instanceof Error?r:new Error(String(r))),e.set("error")}})().catch(()=>{}),()=>{o=!1,a(),s===a&&(s=void 0)}}),S=()=>{m()};return{cancel:m,chunks:C,error:{subscribe:n.subscribe},status:{subscribe:e.subscribe},teardown:S}}export{z as stream};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{stableWireKey as c}from"@lunora/wire";const f=e=>typeof e?.subscribe=="function",y=(e,n)=>{if(!f(e))return n(e);let s=()=>{},i=!1,r,o;const b=e.subscribe(u=>{if(i){r=[u];return}i=!0;try{let t=[u];for(;t;){const l=c(t[0]);l!==o&&(o=l,s(),s=n(t[0])),t=r,r=void 0}}finally{i=!1}});return()=>{b(),s()}};export{f as i,y as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as g}from"@lunora/client/query";import{LunoraError as h}from"@lunora/errors";import{writable as y,readable as l}from"svelte/store";import{i as R}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as x}from"./getLunoraClient-DU7BmZy1.mjs";import{i as C}from"./is-function-reference-abFdrAae.mjs";import{s as L}from"./subscribe-reactive-args-D0fSbP1k.mjs";function z(r,n,a,i){const t=!C(r),c=t?r:x(),m=t?n:r,d=t?a:n,f=(t?i:a)??{},{shardKey:v,onError:p}=f,e=y();return{data:l(void 0,s=>{if(!R())return()=>{};const w=L(d,u=>(s(void 0),e.set(void 0),g(c,m,u,{onData:o=>{s(o),e.set(void 0)},onError:o=>{const b=Object.assign(o.code===void 0?new Error(o.message):new h(o.code,o.message),o.why===void 0?{}:{why:o.why});e.set(b),p?.(o)},onReset:()=>{s(void 0)}},{shardKey:v})));return()=>{w(),e.set(void 0)}}),error:{subscribe:e.subscribe}}}export{z as subscription};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{writable as A,get as H}from"svelte/store";import{isClient as V}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as $}from"./getLunoraClient-DU7BmZy1.mjs";const I="/_lunora/ws",O="/_lunora/voice/",B=4001,U=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,q=e=>{const s=e.startsWith("agents:")?e.slice(7):e;return s.endsWith("Voice")?s.slice(0,-5):s},K=(e,s)=>{if(s===void 0||s==="")return U(e);if(s.endsWith(I))return s.slice(0,-I.length);try{return new URL(s).origin}catch{return U(e)}},J=e=>{const s=K(e.httpUrl,e.wsUrl),r=s.endsWith("/")?s.slice(0,-1):s,a=new URLSearchParams({threadKey:e.threadKey});return`${r}${O}${encodeURIComponent(e.agent)}?${a.toString()}`},G=(e,s)=>{if(s?.code===B)return new Error(`${e}: authentication token expired — refresh the credential and start a new call`)},X=(e,s,r)=>{const a=e.currentIdentity();return e.onAuthTokenChange(()=>{e.currentIdentity()!==a&&r(new Error(`${s}: the signed-in identity changed during the call — the session was ended; start a new call`))})},j=16e3,z=e=>{if(e.length===0)return 0;let s=0;for(const r of e)s+=r*r;return Math.sqrt(s/e.length)},Q=(e,s)=>{const r=s/j,a=r>1?Math.floor(e.length/r):e.length,f=new ArrayBuffer(a*2),d=new DataView(f);for(let u=0;u<a;u+=1){const b=e[Math.floor(u*r)]??0,k=Math.max(-1,Math.min(1,b));d.setInt16(u*2,k<0?k*32768:k*32767,!0)}return new Uint8Array(f)},Y=async e=>{const s=globalThis,r=s.navigator?.mediaDevices?.getUserMedia.bind(s.navigator.mediaDevices),a=s.AudioContext??s.webkitAudioContext;if(!r||!a)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const f=await r({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),d=new a,u=d.createMediaStreamSource(f),b=d.createScriptProcessor(4096,1,1);let k=!1,w=!1,g=0,o=0;return b.onaudioprocess=c=>{const l=c.inputBuffer.getChannelData(0),p=k?0:z(l);if(e.onLevel(p),k)return;if(e.onAudio(Q(l,d.sampleRate)),e.isTurnActive()){o=p>=e.interruptThreshold?o+1:0,o>=e.interruptChunks&&(o=0,e.onInterrupt());return}o=0;const T=l.length/d.sampleRate*1e3;if(p>=e.silenceThreshold){w=!0,g=0;return}w&&(g+=T,g>=e.silenceDurationMs&&(w=!1,g=0,e.onSilence()))},u.connect(b),b.connect(d.destination),{setMuted:c=>{k=c},stop:()=>{b.disconnect(),u.disconnect();for(const c of f.getTracks())c.stop();d.close()}}},Z=()=>{const e=globalThis,s=e.AudioContext??e.webkitAudioContext;if(!s)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const r=new s,a=new Set;let f=0,d=Promise.resolve(),u=0;const b=async(g,o)=>{if(o!==u)return;let c;try{c=await r.decodeAudioData(g.buffer)}catch{return}if(o!==u)return;const l=r.createBufferSource();l.buffer=c,l.connect(r.destination);const p=Math.max(r.currentTime,f);l.start(p),f=p+c.duration,a.add(l),l.onended=()=>{a.delete(l)}},k=g=>{const o=Uint8Array.from(g),c=u;d=d.then(()=>b(o,c))},w=()=>{u+=1;for(const g of a)try{g.stop()}catch{}a.clear(),f=r.currentTime};return{enqueue:k,interrupt:w,stop:()=>{w(),r.close()}}},R=1,ee=.01,te=1200,ne=.15,se=3,re=(e,s)=>{const{createMicrophone:r=Y,createSpeaker:a=Z,createSocket:f,interruptChunks:d=se,interruptThreshold:u=ne,silenceDurationMs:b=te,silenceThreshold:k=ee,threadKey:w,voice:g}=s,o=A("idle"),c=A(!1),l=A(""),p=A(""),T=A(0),v=A(!1),m=A();let i,E=!1;const _=n=>{const t=i?.socket;return t?.readyState===R?(t.send(JSON.stringify(n)),!0):!1},C=()=>{const n=i;if(i=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{}}E=!1,c.set(!1),o.set("idle"),T.set(0)},L=C,D=n=>{const t=i;switch(n.type){case"assistant_delta":{t&&(t.speaking=!0),o.set("speaking"),p.update(x=>x+n.text);break}case"assistant_discarded":{t&&(t.suppressAudio=!0),t?.speaker?.interrupt(),p.set("");break}case"assistant_done":{t&&(t.awaitingTurn=!1,t.speaking=!1),p.set(n.text),o.set("listening");break}case"error":{t&&(t.awaitingTurn=!1,t.speaking=!1),m.set(new Error(n.message)),o.set("listening");break}case"interrupted":{t&&(t.awaitingTurn=!1,t.speaking=!1,t.suppressAudio=!1),t?.speaker?.interrupt(),o.set("listening");break}case"ready":{t&&(t.audioFormat=n.audioFormat,t.suppressAudio=!1),c.set(!0),o.set("listening");break}case"user_transcript":{t&&(t.suppressAudio=!1),l.set(n.text),p.set(""),o.set("thinking");break}}},F=n=>{const t=i;!t||t.suppressAudio||(t.speaker??=a({audioFormat:t.audioFormat}),t.speaking=!0,o.set("speaking"),t.speaker.enqueue(n))},W=async()=>{if(i||E)return;E=!0,m.set(void 0),l.set(""),p.set("");let n;try{const t=J({agent:q(g.__lunoraRef),httpUrl:e.url,threadKey:w,wsUrl:e.wsUrl}),S=(f??(h=>{const y=e.getWebSocketImpl();if(!y)throw new Error("voiceAgent: no WebSocket implementation available (pass createSocket explicitly)");return new y(h)}))(t);S.binaryType="arraybuffer",n={audioFormat:"mp3",microphone:void 0,socket:S,speaker:void 0,speaking:!1,awaitingTurn:!1,suppressAudio:!1,unwatchIdentity:void 0},i=n,n.unwatchIdentity=X(e,"voiceAgent",h=>{i===n&&(m.set(h),C())}),S.onmessage=h=>{if(typeof h.data=="string"){try{D(JSON.parse(h.data))}catch{}return}F(new Uint8Array(h.data))},S.onerror=()=>{m.set(new Error("voiceAgent: voice socket error"))},S.onclose=h=>{if(i!==n)return;const y=G("voiceAgent",h);y&&m.set(y),C()};const M=await r({interruptChunks:d,interruptThreshold:u,isTurnActive:()=>(i?.speaking??!1)||(i?.awaitingTurn??!1),onAudio:h=>{S.readyState===R&&S.send(h)},onInterrupt:()=>{_({type:"interrupt"}),i?.speaker?.interrupt(),i&&(i.awaitingTurn=!1,i.speaking=!1,i.suppressAudio=!0),o.set("listening")},onLevel:h=>{T.set(h)},onSilence:()=>{_({type:"commit"}),i&&(i.awaitingTurn=!0),o.set("thinking")},silenceDurationMs:b,silenceThreshold:k});i===n?(n.microphone=M,v.set(!1),n.speaking||o.set("listening")):M.stop()}catch(t){i===n&&(m.set(t instanceof Error?t:new Error(String(t))),C())}finally{E=!1}},N=()=>{const n=!H(v);return i?.microphone?.setMuted(n),v.set(n),n},P=n=>{_({text:n,type:"text"})&&(i&&(i.awaitingTurn=!0),o.set("thinking"))};return{audioLevel:{subscribe:T.subscribe},connected:{subscribe:c.subscribe},endCall:L,error:{subscribe:m.subscribe},interimTranscript:{subscribe:p.subscribe},isMuted:{subscribe:v.subscribe},sendText:P,startCall:W,status:{subscribe:o.subscribe},toggleMute:N,transcript:{subscribe:l.subscribe}}};function ce(e,s){const r=V(e),a=r?e:$();return re(a,r?s:e)}export{ce as voiceAgent};
|
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 CreateChunkedRestUploadOptions, type CreateChunkedRestUploadReturn, type CreateFileInputOptions, type CreateFileInputReturn, type CreateMultipartUploadOptions, type CreateMultipartUploadReturn, type CreatePasteUploadOptions, type CreatePasteUploadReturn, type CreateTusUploadOptions, type CreateTusUploadReturn, type CreateUploadOptions, type CreateUploadReturn, createChunkedRestUpload, createFileInput, createMultipartUpload, createPasteUpload, createTusUpload, createUpload } from '@visulima/storage-client/svelte';
|
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 CreateChunkedRestUploadOptions, type CreateChunkedRestUploadReturn, type CreateFileInputOptions, type CreateFileInputReturn, type CreateMultipartUploadOptions, type CreateMultipartUploadReturn, type CreatePasteUploadOptions, type CreatePasteUploadReturn, type CreateTusUploadOptions, type CreateTusUploadReturn, type CreateUploadOptions, type CreateUploadReturn, createChunkedRestUpload, createFileInput, createMultipartUpload, createPasteUpload, createTusUpload, createUpload } from '@visulima/storage-client/svelte';
|
package/dist/upload.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{RestrictionError as o,UploadControl as t,UploadError as a}from"@visulima/storage-client";import{createChunkedRestUpload as l,createFileInput as d,createMultipartUpload as c,createPasteUpload as U,createTusUpload as i,createUpload as n}from"@visulima/storage-client/svelte";export{o as RestrictionError,t as UploadControl,a as UploadError,l as createChunkedRestUpload,d as createFileInput,c as createMultipartUpload,U as createPasteUpload,i as createTusUpload,n as createUpload};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/svelte",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.301",
|
|
4
4
|
"description": "Svelte adapter for Lunora — live stores, optimistic mutations, and reactive loaders",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -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,10 +54,11 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@lunora/client": "1.0.0-alpha.
|
|
58
|
-
"@lunora/errors": "1.0.0-alpha.2",
|
|
59
|
-
"@lunora/ratelimit": "1.0.0-alpha.
|
|
60
|
-
"@lunora/
|
|
57
|
+
"@lunora/client": "1.0.0-alpha.265",
|
|
58
|
+
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
59
|
+
"@lunora/ratelimit": "1.0.0-alpha.183",
|
|
60
|
+
"@lunora/wire": "1.0.0-alpha.4",
|
|
61
|
+
"@visulima/storage-client": "1.0.9"
|
|
61
62
|
},
|
|
62
63
|
"peerDependencies": {
|
|
63
64
|
"svelte": "^5.0.0"
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { getIdentityStore } from '@lunora/client/auth';
|
|
2
|
-
import { readable } from 'svelte/store';
|
|
3
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
4
|
-
|
|
5
|
-
const auth = (explicitClient) => {
|
|
6
|
-
const client = explicitClient ?? getLunoraClient();
|
|
7
|
-
const store = getIdentityStore(client);
|
|
8
|
-
const token = readable(client.getAuthToken(), (set) => {
|
|
9
|
-
set(client.getAuthToken());
|
|
10
|
-
const unsub = client.onAuthTokenChange((next) => {
|
|
11
|
-
set(next);
|
|
12
|
-
});
|
|
13
|
-
return unsub;
|
|
14
|
-
});
|
|
15
|
-
const user = readable(store.getUser(), (set) => {
|
|
16
|
-
set(store.getUser());
|
|
17
|
-
const unsub = store.subscribe(() => {
|
|
18
|
-
set(store.getUser());
|
|
19
|
-
});
|
|
20
|
-
return unsub;
|
|
21
|
-
});
|
|
22
|
-
const setToken = (next) => {
|
|
23
|
-
client.setAuthToken(next);
|
|
24
|
-
};
|
|
25
|
-
return { setToken, token, user };
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { auth };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { readable } from 'svelte/store';
|
|
2
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
3
|
-
|
|
4
|
-
const connectionStatus = (client) => {
|
|
5
|
-
const resolved = client ?? getLunoraClient();
|
|
6
|
-
return readable(resolved.connectionStatus(), (set) => {
|
|
7
|
-
set(resolved.connectionStatus());
|
|
8
|
-
return resolved.onConnectionStatus((next) => {
|
|
9
|
-
set(next);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export { connectionStatus };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { readable } from 'svelte/store';
|
|
2
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
3
|
-
|
|
4
|
-
const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
|
|
5
|
-
const flagKind = (value) => {
|
|
6
|
-
const kind = typeof value;
|
|
7
|
-
if (kind === "boolean" || kind === "number" || kind === "string") {
|
|
8
|
-
return kind;
|
|
9
|
-
}
|
|
10
|
-
return "object";
|
|
11
|
-
};
|
|
12
|
-
const flagsReference = { __lunoraRef: FLAGS_EVAL_PATH };
|
|
13
|
-
const isClient = (value) => typeof value === "object" && value !== null && typeof value.subscribe === "function";
|
|
14
|
-
const subscribeFlag = (client, key, defaultValue, context, set) => {
|
|
15
|
-
try {
|
|
16
|
-
return client.subscribe(flagsReference, { context, default: defaultValue, key, type: flagKind(defaultValue) }, (next) => {
|
|
17
|
-
set(next);
|
|
18
|
-
});
|
|
19
|
-
} catch {
|
|
20
|
-
return () => {
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
function flag(clientOrKey, keyOrDefault, defaultOrContext, maybeContext) {
|
|
25
|
-
const hasExplicitClient = isClient(clientOrKey);
|
|
26
|
-
const client = hasExplicitClient ? clientOrKey : getLunoraClient();
|
|
27
|
-
const key = hasExplicitClient ? keyOrDefault : clientOrKey;
|
|
28
|
-
const defaultValue = hasExplicitClient ? defaultOrContext : keyOrDefault;
|
|
29
|
-
const context = (hasExplicitClient ? maybeContext : defaultOrContext) ?? void 0;
|
|
30
|
-
return readable(defaultValue, (set) => subscribeFlag(client, key, defaultValue, context, set));
|
|
31
|
-
}
|
|
32
|
-
function flags(clientOrFlags, flagsOrContext, maybeContext) {
|
|
33
|
-
const hasExplicitClient = isClient(clientOrFlags);
|
|
34
|
-
const client = hasExplicitClient ? clientOrFlags : getLunoraClient();
|
|
35
|
-
const flagDefaults = hasExplicitClient ? flagsOrContext : clientOrFlags;
|
|
36
|
-
const context = (hasExplicitClient ? maybeContext : flagsOrContext) ?? void 0;
|
|
37
|
-
return readable(flagDefaults, (set) => {
|
|
38
|
-
let current = { ...flagDefaults };
|
|
39
|
-
const unsubscribes = [];
|
|
40
|
-
for (const [key, defaultValue] of Object.entries(flagDefaults)) {
|
|
41
|
-
unsubscribes.push(
|
|
42
|
-
subscribeFlag(client, key, defaultValue, context, (next) => {
|
|
43
|
-
current = { ...current, [key]: next };
|
|
44
|
-
set(current);
|
|
45
|
-
})
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
return () => {
|
|
49
|
-
for (const unsubscribe of unsubscribes) {
|
|
50
|
-
unsubscribe();
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export { flag, flags };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { LunoraError } from '@lunora/errors';
|
|
2
|
-
import { setContext, getContext } from 'svelte';
|
|
3
|
-
|
|
4
|
-
const LUNORA_CONTEXT_KEY = /* @__PURE__ */ Symbol("lunora.client");
|
|
5
|
-
const setLunoraClient = (client) => {
|
|
6
|
-
setContext(LUNORA_CONTEXT_KEY, client);
|
|
7
|
-
return client;
|
|
8
|
-
};
|
|
9
|
-
const getLunoraClient = () => {
|
|
10
|
-
const client = getContext(LUNORA_CONTEXT_KEY);
|
|
11
|
-
if (!client) {
|
|
12
|
-
throw new LunoraError("INTERNAL", "getLunoraClient(): no LunoraClient in context — call setLunoraClient(client) in an ancestor component first.");
|
|
13
|
-
}
|
|
14
|
-
return client;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export { getLunoraClient, setLunoraClient };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { readable } from 'svelte/store';
|
|
2
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
3
|
-
|
|
4
|
-
const hydratePreloaded = (preloaded, client) => {
|
|
5
|
-
const resolvedClient = client ?? getLunoraClient();
|
|
6
|
-
const { args, functionPath, shardKey, value } = preloaded;
|
|
7
|
-
const functionRef = { __lunoraRef: functionPath };
|
|
8
|
-
return readable(
|
|
9
|
-
value,
|
|
10
|
-
(set) => resolvedClient.subscribe(
|
|
11
|
-
functionRef,
|
|
12
|
-
args,
|
|
13
|
-
(next) => {
|
|
14
|
-
set(next);
|
|
15
|
-
},
|
|
16
|
-
{ shardKey }
|
|
17
|
-
)
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export { hydratePreloaded };
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { initialPages, derivePaginationStatus, rebalance, applyLoadMore } from '@lunora/client/pagination';
|
|
2
|
-
import { derived, writable, readable } from 'svelte/store';
|
|
3
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
4
|
-
import { i as isFunctionReference } from './is-function-reference-ycLAcI79.mjs';
|
|
5
|
-
|
|
6
|
-
const buildPageArgs = (page, baseArgs) => {
|
|
7
|
-
return {
|
|
8
|
-
...baseArgs,
|
|
9
|
-
paginationOpts: { cursor: page.lower, endCursor: page.upper, numItems: page.numItems }
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
const buildPageKey = (functionPath, pageArgs) => `${functionPath}::${JSON.stringify(pageArgs)}`;
|
|
13
|
-
const createPaginatedEngine = (client, function_, baseArgs, options) => {
|
|
14
|
-
const { initialNumItems, shardKey } = options;
|
|
15
|
-
const pagesStore = writable(initialPages(initialNumItems));
|
|
16
|
-
const pageResultsInternal = writable([]);
|
|
17
|
-
const resultsByKey = /* @__PURE__ */ new Map();
|
|
18
|
-
const activeSubs = /* @__PURE__ */ new Map();
|
|
19
|
-
const pendingPageKeys = /* @__PURE__ */ new Set();
|
|
20
|
-
let currentPages = initialPages(initialNumItems);
|
|
21
|
-
const currentBaseArgs = baseArgs;
|
|
22
|
-
pagesStore.subscribe((pages) => {
|
|
23
|
-
currentPages = pages;
|
|
24
|
-
});
|
|
25
|
-
const rebuildPageResults = () => {
|
|
26
|
-
if (currentBaseArgs === "skip") {
|
|
27
|
-
pageResultsInternal.set([]);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const updated = currentPages.map((page) => {
|
|
31
|
-
const key = buildPageKey(function_["__lunoraRef"], buildPageArgs(page, currentBaseArgs));
|
|
32
|
-
return resultsByKey.get(key);
|
|
33
|
-
});
|
|
34
|
-
pageResultsInternal.set(updated);
|
|
35
|
-
};
|
|
36
|
-
const syncSubscriptions = () => {
|
|
37
|
-
if (currentBaseArgs === "skip") {
|
|
38
|
-
for (const unsub of activeSubs.values()) {
|
|
39
|
-
unsub();
|
|
40
|
-
}
|
|
41
|
-
activeSubs.clear();
|
|
42
|
-
pageResultsInternal.set([]);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const baseArgsRecord = currentBaseArgs;
|
|
46
|
-
const wantedKeys = /* @__PURE__ */ new Set();
|
|
47
|
-
for (const page of currentPages) {
|
|
48
|
-
wantedKeys.add(buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgsRecord)));
|
|
49
|
-
}
|
|
50
|
-
for (const [key, unsub] of activeSubs) {
|
|
51
|
-
if (!wantedKeys.has(key)) {
|
|
52
|
-
unsub();
|
|
53
|
-
activeSubs.delete(key);
|
|
54
|
-
pendingPageKeys.delete(key);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
for (const page of currentPages) {
|
|
58
|
-
const pageArgs = buildPageArgs(page, baseArgsRecord);
|
|
59
|
-
const key = buildPageKey(function_["__lunoraRef"], pageArgs);
|
|
60
|
-
if (activeSubs.has(key)) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
pendingPageKeys.add(key);
|
|
64
|
-
const unsub = client.subscribe(
|
|
65
|
-
function_,
|
|
66
|
-
pageArgs,
|
|
67
|
-
(value) => {
|
|
68
|
-
resultsByKey.set(key, value);
|
|
69
|
-
pendingPageKeys.delete(key);
|
|
70
|
-
rebuildPageResults();
|
|
71
|
-
if (pendingPageKeys.size === 0) {
|
|
72
|
-
let updatedResults = [];
|
|
73
|
-
pageResultsInternal.subscribe((results) => {
|
|
74
|
-
updatedResults = results;
|
|
75
|
-
})();
|
|
76
|
-
const next = rebalance(currentPages, updatedResults);
|
|
77
|
-
if (next) {
|
|
78
|
-
pagesStore.set(next);
|
|
79
|
-
syncSubscriptions();
|
|
80
|
-
rebuildPageResults();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
{ shardKey }
|
|
85
|
-
);
|
|
86
|
-
activeSubs.set(key, unsub);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
const teardownAll = () => {
|
|
90
|
-
for (const unsub of activeSubs.values()) {
|
|
91
|
-
unsub();
|
|
92
|
-
}
|
|
93
|
-
activeSubs.clear();
|
|
94
|
-
resultsByKey.clear();
|
|
95
|
-
pendingPageKeys.clear();
|
|
96
|
-
};
|
|
97
|
-
const pageResults = readable([], (set) => {
|
|
98
|
-
const unsubInternal = pageResultsInternal.subscribe(set);
|
|
99
|
-
if (currentBaseArgs !== "skip") {
|
|
100
|
-
syncSubscriptions();
|
|
101
|
-
rebuildPageResults();
|
|
102
|
-
}
|
|
103
|
-
return () => {
|
|
104
|
-
unsubInternal();
|
|
105
|
-
teardownAll();
|
|
106
|
-
pagesStore.set(initialPages(initialNumItems));
|
|
107
|
-
pageResultsInternal.set([]);
|
|
108
|
-
};
|
|
109
|
-
});
|
|
110
|
-
const status = derived(
|
|
111
|
-
pageResults,
|
|
112
|
-
(results) => derivePaginationStatus(currentBaseArgs === "skip", results).status
|
|
113
|
-
);
|
|
114
|
-
const loadMore = (numberItems) => {
|
|
115
|
-
if (currentBaseArgs === "skip") {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
let currentResults = [];
|
|
119
|
-
pageResultsInternal.subscribe((results) => {
|
|
120
|
-
currentResults = results;
|
|
121
|
-
})();
|
|
122
|
-
const { nextCursor, status: currentStatus } = derivePaginationStatus(false, currentResults);
|
|
123
|
-
if (currentStatus !== "CanLoadMore") {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const next = applyLoadMore(currentPages, nextCursor, numberItems);
|
|
127
|
-
if (!next) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
const oldTail = currentPages.at(-1);
|
|
131
|
-
const newPinnedPage = next.at(-2);
|
|
132
|
-
if (oldTail && newPinnedPage) {
|
|
133
|
-
const oldKey = buildPageKey(function_["__lunoraRef"], buildPageArgs(oldTail, currentBaseArgs));
|
|
134
|
-
const newKey = buildPageKey(function_["__lunoraRef"], buildPageArgs(newPinnedPage, currentBaseArgs));
|
|
135
|
-
if (oldKey !== newKey) {
|
|
136
|
-
const carried = resultsByKey.get(oldKey);
|
|
137
|
-
if (carried) {
|
|
138
|
-
resultsByKey.set(newKey, carried);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
pagesStore.set(next);
|
|
143
|
-
syncSubscriptions();
|
|
144
|
-
rebuildPageResults();
|
|
145
|
-
};
|
|
146
|
-
return { loadMore, pageResults, status };
|
|
147
|
-
};
|
|
148
|
-
function paginatedQuery(clientOrFunction, functionOrArguments, argumentsOrOptions, maybeOptions) {
|
|
149
|
-
const hasExplicitClient = !isFunctionReference(clientOrFunction);
|
|
150
|
-
const client = hasExplicitClient ? clientOrFunction : getLunoraClient();
|
|
151
|
-
const functionRef = hasExplicitClient ? functionOrArguments : clientOrFunction;
|
|
152
|
-
const args = hasExplicitClient ? argumentsOrOptions : functionOrArguments;
|
|
153
|
-
const options = hasExplicitClient ? maybeOptions : argumentsOrOptions;
|
|
154
|
-
const { loadMore, pageResults, status } = createPaginatedEngine(client, functionRef, args, options);
|
|
155
|
-
const results = derived(pageResults, (currentResults) => {
|
|
156
|
-
const items = [];
|
|
157
|
-
for (const page of currentResults) {
|
|
158
|
-
if (page) {
|
|
159
|
-
items.push(...page.page);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return items;
|
|
163
|
-
});
|
|
164
|
-
const isLoading = derived(
|
|
165
|
-
status,
|
|
166
|
-
(currentStatus) => currentStatus === "LoadingFirstPage" || currentStatus === "LoadingMore"
|
|
167
|
-
);
|
|
168
|
-
return { isLoading, loadMore, results, status };
|
|
169
|
-
}
|
|
170
|
-
function infiniteQuery(clientOrFunction, functionOrArguments, argumentsOrOptions, maybeOptions) {
|
|
171
|
-
const hasExplicitClient = !isFunctionReference(clientOrFunction);
|
|
172
|
-
const client = hasExplicitClient ? clientOrFunction : getLunoraClient();
|
|
173
|
-
const functionRef = hasExplicitClient ? functionOrArguments : clientOrFunction;
|
|
174
|
-
const args = hasExplicitClient ? argumentsOrOptions : functionOrArguments;
|
|
175
|
-
const options = hasExplicitClient ? maybeOptions : argumentsOrOptions;
|
|
176
|
-
const { initialNumItems } = options;
|
|
177
|
-
const { loadMore, pageResults, status } = createPaginatedEngine(client, functionRef, args, options);
|
|
178
|
-
const pages = derived(pageResults, (currentResults) => {
|
|
179
|
-
const result = [];
|
|
180
|
-
for (const page of currentResults) {
|
|
181
|
-
if (page) {
|
|
182
|
-
result.push(page.page);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return result;
|
|
186
|
-
});
|
|
187
|
-
const isLoading = derived(status, (s) => s === "LoadingFirstPage");
|
|
188
|
-
const hasNextPage = derived(status, (s) => s === "CanLoadMore");
|
|
189
|
-
const isFetchingNextPage = derived(status, (s) => s === "LoadingMore");
|
|
190
|
-
const fetchNextPage = (numberItems) => {
|
|
191
|
-
loadMore(numberItems ?? initialNumItems);
|
|
192
|
-
};
|
|
193
|
-
return { fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, pages, status };
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export { infiniteQuery, paginatedQuery };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createMutationRunner } from '@lunora/client';
|
|
2
|
-
import { writable } from 'svelte/store';
|
|
3
|
-
import { getLunoraClient } from './getLunoraClient-Prczj1gU.mjs';
|
|
4
|
-
|
|
5
|
-
function mutation(clientOrFunction, maybeFunction) {
|
|
6
|
-
const hasExplicitClient = maybeFunction !== void 0;
|
|
7
|
-
const client = hasExplicitClient ? clientOrFunction : getLunoraClient();
|
|
8
|
-
const functionRef = hasExplicitClient ? maybeFunction : clientOrFunction;
|
|
9
|
-
const data = writable();
|
|
10
|
-
const error = writable();
|
|
11
|
-
const pending = writable(false);
|
|
12
|
-
const mutate = createMutationRunner(client, functionRef, {
|
|
13
|
-
setError: (next) => {
|
|
14
|
-
error.set(next);
|
|
15
|
-
},
|
|
16
|
-
setPending: (next) => {
|
|
17
|
-
pending.set(next);
|
|
18
|
-
},
|
|
19
|
-
setResult: (result) => {
|
|
20
|
-
data.set(result);
|
|
21
|
-
error.set(void 0);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
const reset = () => {
|
|
25
|
-
data.set(void 0);
|
|
26
|
-
error.set(void 0);
|
|
27
|
-
};
|
|
28
|
-
return { data, error, mutate, pending, reset };
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { mutation };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { createMutatorRunner } from '@lunora/client';
|
|
2
|
-
import { writable, derived } from 'svelte/store';
|
|
3
|
-
|
|
4
|
-
const mutator = (handle) => {
|
|
5
|
-
const error = writable();
|
|
6
|
-
const pending = writable(false);
|
|
7
|
-
const isError = derived(error, ($error) => $error !== void 0);
|
|
8
|
-
const { mutate, reset } = createMutatorRunner(handle, {
|
|
9
|
-
setError: (value) => {
|
|
10
|
-
error.set(value);
|
|
11
|
-
},
|
|
12
|
-
setPending: (value) => {
|
|
13
|
-
pending.set(value);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
return { error, isError, mutate, pending, reset };
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export { mutator };
|