@lunora/svelte 1.0.0-alpha.7 → 1.0.0-alpha.71
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 +2 -0
- package/dist/index.d.mts +897 -168
- package/dist/index.d.ts +897 -168
- package/dist/index.mjs +1 -10
- package/dist/packem_shared/agent-CddTbgxO.mjs +1 -0
- package/dist/packem_shared/agentChat-BmvA3u8B.mjs +1 -0
- package/dist/packem_shared/agentState-fc7KRCp9.mjs +1 -0
- package/dist/packem_shared/agentToolEvents-sOUvSZsy.mjs +1 -0
- package/dist/packem_shared/auth-BWCPnv0n.mjs +1 -0
- package/dist/packem_shared/connectionStatus-BHVAskxU.mjs +1 -0
- package/dist/packem_shared/flag-5trRaaSv.mjs +1 -0
- package/dist/packem_shared/getLunoraClient-DU7BmZy1.mjs +1 -0
- package/dist/packem_shared/hydratePreloaded-Bbm6vwbA.mjs +1 -0
- package/dist/packem_shared/infiniteQuery-s_5r8MQZ.mjs +1 -0
- package/dist/packem_shared/is-browser-BEdfLJHK.mjs +1 -0
- package/dist/packem_shared/is-function-reference-ByqJF30w.mjs +1 -0
- package/dist/packem_shared/mutation-fa0Bj5Bo.mjs +1 -0
- package/dist/packem_shared/mutator-cvH3UrNm.mjs +1 -0
- package/dist/packem_shared/presence-C2YC1KOc.mjs +1 -0
- package/dist/packem_shared/query-BEQBdOJ2.mjs +1 -0
- package/dist/packem_shared/rateLimit-DtykU7F_.mjs +1 -0
- package/dist/packem_shared/stream-DItOnXt6.mjs +1 -0
- package/dist/packem_shared/subscription-Dbz9sy8N.mjs +1 -0
- package/dist/packem_shared/voiceAgent-CPQvbrxT.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/dist/worker.mjs +1 -1
- package/package.json +10 -4
- package/dist/packem_shared/auth-DLPf_bK9.mjs +0 -28
- package/dist/packem_shared/connectionStatus-CRsOMeYl.mjs +0 -14
- package/dist/packem_shared/getLunoraClient--bwSz7F6.mjs +0 -16
- package/dist/packem_shared/hydratePreloaded-D5rUJdXy.mjs +0 -21
- package/dist/packem_shared/infiniteQuery-jPMQw8Vz.mjs +0 -196
- package/dist/packem_shared/is-function-reference-ycLAcI79.mjs +0 -3
- package/dist/packem_shared/mutation-CnDkAaLH.mjs +0 -31
- package/dist/packem_shared/presence-BQWixJ2T.mjs +0 -66
- package/dist/packem_shared/query-D8Pct9Qe.mjs +0 -36
- package/dist/packem_shared/rateLimit-Cdw1kp8t.mjs +0 -66
- package/dist/packem_shared/subscription-twuBT_Wb.mjs +0 -46
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { connectionStatus } from './packem_shared/connectionStatus-CRsOMeYl.mjs';
|
|
3
|
-
export { getLunoraClient, setLunoraClient } from './packem_shared/getLunoraClient--bwSz7F6.mjs';
|
|
4
|
-
export { hydratePreloaded } from './packem_shared/hydratePreloaded-D5rUJdXy.mjs';
|
|
5
|
-
export { mutation } from './packem_shared/mutation-CnDkAaLH.mjs';
|
|
6
|
-
export { infiniteQuery, paginatedQuery } from './packem_shared/infiniteQuery-jPMQw8Vz.mjs';
|
|
7
|
-
export { presence } from './packem_shared/presence-BQWixJ2T.mjs';
|
|
8
|
-
export { query } from './packem_shared/query-D8Pct9Qe.mjs';
|
|
9
|
-
export { rateLimit } from './packem_shared/rateLimit-Cdw1kp8t.mjs';
|
|
10
|
-
export { subscription } from './packem_shared/subscription-twuBT_Wb.mjs';
|
|
1
|
+
import{agent as o}from"./packem_shared/agent-CddTbgxO.mjs";import{agentChat as a}from"./packem_shared/agentChat-BmvA3u8B.mjs";import{agentState as f}from"./packem_shared/agentState-fc7KRCp9.mjs";import{agentToolEvents as n}from"./packem_shared/agentToolEvents-sOUvSZsy.mjs";import{auth as i,authGate as u}from"./packem_shared/auth-BWCPnv0n.mjs";import{connectionStatus as s}from"./packem_shared/connectionStatus-BHVAskxU.mjs";import{getLunoraClient as c,setLunoraClient as d}from"./packem_shared/getLunoraClient-DU7BmZy1.mjs";import{flag as y,flags as C}from"./packem_shared/flag-5trRaaSv.mjs";import{hydratePreloaded as v}from"./packem_shared/hydratePreloaded-Bbm6vwbA.mjs";import{mutation as S}from"./packem_shared/mutation-fa0Bj5Bo.mjs";import{mutator as q}from"./packem_shared/mutator-cvH3UrNm.mjs";import{infiniteQuery as E,paginatedQuery as G}from"./packem_shared/infiniteQuery-s_5r8MQZ.mjs";import{presence as T}from"./packem_shared/presence-C2YC1KOc.mjs";import{query as k}from"./packem_shared/query-BEQBdOJ2.mjs";import{rateLimit as z}from"./packem_shared/rateLimit-DtykU7F_.mjs";import{stream as D}from"./packem_shared/stream-DItOnXt6.mjs";import{subscription as H}from"./packem_shared/subscription-Dbz9sy8N.mjs";import{voiceAgent as J}from"./packem_shared/voiceAgent-CPQvbrxT.mjs";export{o as agent,a as agentChat,f as agentState,n as agentToolEvents,i as auth,u as authGate,s as connectionStatus,y as flag,C as flags,c as getLunoraClient,v as hydratePreloaded,E as infiniteQuery,S as mutation,q as mutator,G as paginatedQuery,T as presence,k as query,z as rateLimit,d as setLunoraClient,D as stream,H as subscription,J as voiceAgent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{writable as b}from"svelte/store";import{i as T}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as _}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as d}from"./mutation-fa0Bj5Bo.mjs";const A={__lunoraRef:""},I=t=>typeof t=="object"&&t!==null&&typeof t.subscribe=="function",K=(t,a)=>{const{api:e,cancel:r,run:m,runArgs:p,threadKey:i}=a,o=d(t,m),f=d(t,r??A);let s;const c=b(),u=b(),l=T()?t.subscribe(e.agents.agentThread,{key:i},n=>{s=n,c.set(s),u.set(s?.status)}):()=>{},y=async(n,w)=>{await o.mutate({input:n,threadKey:i,...p,...w})},g=async()=>{const n=s?.instanceId;r===void 0||n===void 0||await f.mutate({instanceId:n,threadKey:i})},h=()=>{l()};return{cancel:g,pending:o.pending,run:y,status:{subscribe:u.subscribe},teardown:h,thread:{subscribe:c.subscribe}}};function N(t,a){const e=I(t),r=e?t:_();return K(r,e?a:t)}export{A as NO_MUTATION_REF,N as agent,I as isClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{reconcileOptimistic as K,maxSeq as A}from"@lunora/client";import{writable as b}from"svelte/store";import{i as g}from"./is-browser-BEdfLJHK.mjs";import{isClient as Q,NO_MUTATION_REF as U}from"./agent-CddTbgxO.mjs";import{getLunoraClient as V}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as h}from"./mutation-fa0Bj5Bo.mjs";import{stream as z}from"./stream-DItOnXt6.mjs";const G={__lunoraRef:""},J=(n,u)=>{const{api:r,cancel:m,limit:y,send:T,sendArgs:_,stream:f,threadKey:a}=u,j=h(n,T),q=h(n,m??U),O=h(n,r.agents.agentResolveApproval);let d,i=[],c=[],v=[],w=0;const l=b([]),k=b(),I=b(""),p=()=>{const t=K(c,i);if(t.length===0){l.set(i);return}const s=A(i);l.set([...i,...t.map((e,o)=>({content:e.content,optimistic:!0,role:"user",seq:s+1+o}))])},x=()=>{const t=i.filter(e=>e.role==="assistant").length,s=v.filter(e=>e.kind!=="progress"&&e.threadKey===a&&e.turn>=t).map(e=>e.text).join("");I.set(s)},R=f===void 0?"skip":{key:a},S=g()?z(n,f??G,R).chunks.subscribe(t=>{v=t,x()}):()=>{},E=y===void 0?{key:a}:{key:a,limit:y},N=g()?n.subscribe(r.agents.agentMessages,E,t=>{i=t,p(),x()}):()=>{},B=g()?n.subscribe(r.agents.agentThread,{key:a},t=>{d=t,k.set(d?.status)}):()=>{},D=async(t,s)=>{const e=w;w+=1;const o=A(i);c=[...K(c,i),{content:t,id:e,maxDurableSeqAtSend:o}],p();try{await j.mutate({input:t,threadKey:a,..._,...s})}catch(H){throw c=c.filter(P=>P.id!==e),p(),H}},C=async(t,s,e)=>{const o=d?.instanceId;if(o===void 0)throw new Error(`agentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await O.mutate({decision:t,instanceId:o,threadKey:a,toolCallId:s,...e===void 0?{}:{note:e}})},F=async(t,s)=>C("approve",t,s),L=async(t,s)=>C("reject",t,s),M=async()=>{const t=d?.instanceId;m===void 0||t===void 0||await q.mutate({instanceId:t,threadKey:a})},$=()=>{N(),B(),S()};return{approve:F,cancel:M,messages:{subscribe:l.subscribe},reject:L,send:D,status:{subscribe:k.subscribe},streamingText:{subscribe:I.subscribe},teardown:$}};function nt(n,u){const r=Q(n),m=r?n:V();return J(m,r?u:n)}export{nt as agentChat};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{derived as p}from"svelte/store";import{isClient as f}from"./agent-CddTbgxO.mjs";import{getLunoraClient as d}from"./getLunoraClient-DU7BmZy1.mjs";import{subscription as g}from"./subscription-Dbz9sy8N.mjs";function C(r,o){const t=f(r),a=t?r:d(),e=t?o:r,{data:i,error:n}=g(a,e.api.agents.agentState,{key:e.threadKey}),s=p(i,m=>m);return{error:n,state:s}}export{C as agentState};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{derived as c}from"svelte/store";import{isClient as g}from"./agent-CddTbgxO.mjs";import{getLunoraClient as y}from"./getLunoraClient-DU7BmZy1.mjs";import{stream as I}from"./stream-DItOnXt6.mjs";import{subscription as N}from"./subscription-Dbz9sy8N.mjs";const k={__lunoraRef:""},q=o=>{if(o.role==="assistant"&&o.toolCalls)return o.toolCalls.map(t=>({input:t.input,seq:o.seq,toolCallId:t.id,toolName:t.name,type:"call"}));if(o.role==="tool")return o.status==="awaiting_approval"?[{seq:o.seq,type:"awaiting-approval",...o.toolCallId===void 0?{}:{toolCallId:o.toolCallId},...o.toolName===void 0?{}:{toolName:o.toolName}}]:[{output:o.content,seq:o.seq,type:"result",...o.status==="approved"||o.status==="rejected"?{status:o.status}:{},...o.toolCallId===void 0?{}:{toolCallId:o.toolCallId},...o.toolName===void 0?{}:{toolName:o.toolName}}]};function M(o,t){const l=g(o),s=l?o:y(),p=l?t:o,{api:d,limit:r,stream:i,threadKey:e}=p,m=r===void 0?{key:e}:{key:e,limit:r},{data:u}=N(s,d.agents.agentMessages,m),C=I(s,i??k,i===void 0?"skip":{key:e});return{events:c([u,C.chunks],([f,v])=>{const n=(f??[]).flatMap(a=>q(a)??[]);for(const a of v)a.kind==="progress"&&a.threadKey===e&&n.push({data:a.data,toolCallId:a.toolCallId,type:"progress"});return n})}}export{M as agentToolEvents};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getIdentityStore as l}from"@lunora/client/auth";import{readable as s,derived as i}from"svelte/store";import{getLunoraClient as g}from"./getLunoraClient-DU7BmZy1.mjs";const h=r=>{const e=r??g(),n=l(e),u=s(e.getAuthToken(),t=>(t(e.getAuthToken()),e.onAuthTokenChange(a=>{t(a)}))),o=s(n.getUser(),t=>(t(n.getUser()),n.subscribe(()=>{t(n.getUser())})));return{setToken:t=>{e.setAuthToken(t)},token:u,user:o}},c=r=>{const{token:e,user:n}=h(r),u=i([e,n],([o,t])=>o!==null&&t===null);return{isAuthenticated:i([e,n],([o,t])=>o!==null&&t!==null),isLoading:u}};export{h as auth,c as authGate};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readable as c}from"svelte/store";import{getLunoraClient as r}from"./getLunoraClient-DU7BmZy1.mjs";const s=o=>{const t=o??r();return c(t.connectionStatus(),n=>(n(t.connectionStatus()),t.onConnectionStatus(e=>{n(e)})))};export{s as connectionStatus};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{readable as a}from"svelte/store";import{isClient as p}from"./agent-CddTbgxO.mjs";import{getLunoraClient as b}from"./getLunoraClient-DU7BmZy1.mjs";const g="__lunora_flags__:eval",y=r=>{const t=typeof r;return t==="boolean"||t==="number"||t==="string"?t:"object"},v={__lunoraRef:g},m=(r,t,e,n,o)=>{try{return r.subscribe(v,{context:n,default:e,key:t,type:y(e)},c=>{o(c)})}catch{return()=>{}}};function j(r,t,e,n){const o=p(r),c=o?r:b(),l=o?t:r,u=o?e:t,s=(o?n:e)??void 0;return a(u,f=>m(c,l,u,s,f))}function k(r,t,e){const n=p(r),o=n?r:b(),c=n?t:r,l=(n?e:t)??void 0;return a(c,u=>{let s={...c};const f=[];for(const[i,_]of Object.entries(c))f.push(m(o,i,_,l,d=>{s={...s,[i]:d},u(s)}));return()=>{for(const i of f)i()}})}export{j as flag,k 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 u}from"svelte/store";import{getLunoraClient as c}from"./getLunoraClient-DU7BmZy1.mjs";const m=(r,e)=>{const a=e??c(),{args:o,functionPath:t,shardKey:n,value:s}=r,d={__lunoraRef:t};return u(s,i=>a.subscribe(d,o,l=>{i(l)},{shardKey:n}))};export{m as hydratePreloaded};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{initialPages as J,derivePaginationStatus as T,applyLoadMore as V,rebalance as q}from"@lunora/client/pagination";import{derived as S,writable as I,readable as G,get as k}from"svelte/store";import{getLunoraClient as Q}from"./getLunoraClient-DU7BmZy1.mjs";import{i as D}from"./is-function-reference-ByqJF30w.mjs";const H=(e,r)=>e<r?-1:e>r?1:0,F=e=>{if(e===void 0)return"null";if(typeof e=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(t=>F(t)).join(",")}]`;const r=Object.getPrototypeOf(e);if(r!==null&&r!==Object.prototype){const t=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${t} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const s=e,b=Object.keys(s).toSorted(H),i=[];for(const t of b){const n=s[t];n!==void 0&&i.push(`${JSON.stringify(t)}:${F(n)}`)}return`{${i.join(",")}}`},E=e=>{let r="";for(let s=0;s<e.length;s+=32768)r+=String.fromCharCode(...e.subarray(s,s+32768));return btoa(r)},c="$lunora.wire$",K=64,X="__proto__",Y=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},M=(e,r=0)=>{if(r>K)throw new RangeError(`wire-codec: value nesting exceeds the ${K}-level limit`);if(e===void 0)return[c,"undefined"];if(e===null)return null;const s=typeof e;if(s==="bigint")return[c,"bigint",e.toString()];if(s==="number"){const t=e;return Number.isNaN(t)?[c,"nan"]:t===1/0?[c,"inf"]:t===-1/0?[c,"-inf"]:t}if(s!=="object")return e;if(e instanceof Date)return[c,"date",M(e.getTime(),r+1)];if(e instanceof Error){const t=e,n={};for(const a of Object.keys(t))t[a]!==void 0&&(n[a]=M(t[a],r+1));const o=[c,"error",t.name,t.message,n];return t.cause!==void 0&&o.push(M(t.cause,r+1)),o}if(e instanceof URL)return[c,"url",e.href];if(e instanceof Map)return[c,"map",[...e.entries()].map(([t,n])=>[M(t,r+1),M(n,r+1)])];if(e instanceof Set)return[c,"set",[...e].map(t=>M(t,r+1))];if(e instanceof ArrayBuffer)return[c,"bytes",E(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,n=t.constructor.name,o=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return n==="Uint8Array"?[c,"bytes",E(o)]:[c,"bytes",E(o),n]}if(Array.isArray(e)){const t=e.map(n=>M(n,r+1));return t.length>0&&t[0]===c?[c,"arr",t]:t}if(!Y(e)){const t=e.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${t} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`)}const b=e,i={};for(const t of Object.keys(b)){const n=b[t];if(n===void 0)continue;const o=M(n,r+1);t===X?Object.defineProperty(i,t,{configurable:!0,enumerable:!0,value:o,writable:!0}):i[t]=o}return i},Z=e=>F(M(e)),A=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),L=(e,r)=>`${e}::${Z(r)}`,W=(e,r,s,b)=>{const{initialNumItems:i,shardKey:t}=b,n=I(J(i)),o=I([]),a=new Map,d=new Map,w=new Set,f=s,g=()=>{if(f==="skip"){o.set([]);return}const l=k(n).map(m=>{const v=L(r.__lunoraRef,A(m,f));return a.get(v)});o.set(l)},R=(l,m)=>{if(f==="skip")return;const v=u=>L(r.__lunoraRef,A(u,f));for(const u of m){const h=v(u);if(a.has(h))continue;const y=l.find(O=>O.lower===u.lower);if(y){const O=a.get(v(y));O&&a.set(h,O)}}},$=()=>{if(f==="skip"){for(const u of d.values())u();d.clear(),o.set([]);return}const l=f,m=k(n),v=new Set;for(const u of m)v.add(L(r.__lunoraRef,A(u,l)));for(const[u,h]of d)v.has(u)||(h(),d.delete(u),w.delete(u),a.delete(u));for(const u of m){const h=A(u,l),y=L(r.__lunoraRef,h);if(d.has(y))continue;w.add(y);const O=e.subscribe(r,h,x=>{if(a.set(y,x),w.delete(y),g(),w.size===0){const _=k(n),j=q(_,k(o));j&&(R(_,j),n.set(j),p(),g())}},{shardKey:t});d.set(y,O)}};let N=!1,P=!1;const p=()=>{if(N){P=!0;return}N=!0;try{do P=!1,$();while(P)}finally{N=!1}},C=()=>{for(const l of d.values())l();d.clear(),a.clear(),w.clear()},U=G([],l=>{const m=o.subscribe(l);return f!=="skip"&&(p(),g()),()=>{m(),C(),n.set(J(i)),o.set([])}}),z=S(U,l=>T(f==="skip",l).status);return{loadMore:l=>{if(f==="skip")return;const m=k(o),{nextCursor:v,status:u}=T(!1,m);if(u!=="CanLoadMore")return;const h=k(n),y=V(h,v,l);if(!y)return;const O=h.at(-1),x=y.at(-2);if(O&&x){const _=L(r.__lunoraRef,A(O,f)),j=L(r.__lunoraRef,A(x,f));if(_!==j){const B=a.get(_);B&&(a.set(j,B),a.delete(_))}}n.set(y),p(),g()},pageResults:U,status:z}};function oe(e,r,s,b){const i=!D(e),t=i?e:Q(),n=i?r:e,o=i?s:r,a=i?b:s,{loadMore:d,pageResults:w,status:f}=W(t,n,o,a),g=S(w,R=>R.flatMap($=>$?.page??[]));return{isLoading:S(f,R=>R==="LoadingFirstPage"||R==="LoadingMore"),loadMore:d,results:g,status:f}}function se(e,r,s,b){const i=!D(e),t=i?e:Q(),n=i?r:e,o=i?s:r,a=i?b:s,{initialNumItems:d}=a,{loadMore:w,pageResults:f,status:g}=W(t,n,o,a),R=S(f,p=>p.flatMap(C=>C?[C.page]:[])),$=S(g,p=>p==="LoadingFirstPage"),N=S(g,p=>p==="CanLoadMore"),P=S(g,p=>p==="LoadingMore");return{fetchNextPage:p=>{w(p??d)},hasNextPage:N,isFetchingNextPage:P,isLoading:$,pages:R,status:g}}export{se as infiniteQuery,oe as paginatedQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=()=>globalThis.window!==void 0;export{o as i};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=e=>typeof e=="object"&&e!==null&&typeof e.__lunoraRef=="string";export{o as i};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMutationRunner as f}from"@lunora/client";import{writable as o}from"svelte/store";import{getLunoraClient as p}from"./getLunoraClient-DU7BmZy1.mjs";function g(n,s){const i=s!==void 0,u=i?n:p(),d=i?s:n,r=o(),e=o(),a=o(!1),m=f(u,d,{setError:t=>{e.set(t)},setPending:t=>{a.set(t)},setResult:t=>{r.set(t),e.set(void 0)}});return{data:r,error:e,mutate:m,pending:a,reset:()=>{r.set(void 0),e.set(void 0)}}}export{g as mutation};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMutatorRunner as m}from"@lunora/client";import{writable as o,derived as d}from"svelte/store";const c=s=>{const e=o(),t=o(!1),n=d(e,r=>r!==void 0),{mutate:a,reset:i}=m(s,{setError:r=>{e.set(r)},setPending:r=>{t.set(r)}});return{error:e,isError:n,mutate:a,pending:t,reset:i}};export{c as mutator};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{onDestroy as b}from"svelte";import{readable as D}from"svelte/store";import{i as l}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as U}from"./getLunoraClient-DU7BmZy1.mjs";const $=(t="sess")=>{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`${t}-${Array.from(e,o=>o.toString(16).padStart(2,"0")).join("")}`}}return`${t}-${Date.now().toString(36)}`},w=1e4,C=(t,e,o)=>{const{heartbeat:r,intervalMs:i=w,listPresent:v,shardKey:a}=o,c=o.sessionId??$();let d=o.data;const s=()=>{const n={roomId:e,sessionId:c,...d===void 0?{}:{data:d}};t.mutation(r,n,{shardKey:a}).catch(()=>{})},I=n=>{d=n,s()},m=()=>{typeof document<"u"&&document.visibilityState==="visible"&&s()};let u,y;l()&&(s(),u=setInterval(s,i),typeof document<"u"&&document.addEventListener("visibilitychange",m),y=t.acquireConnectionContext({roomId:e,sessionId:c},{shardKey:a}));const g=D(void 0,n=>{if(l())return t.subscribe(v,{roomId:e},h=>{n(h)},{shardKey:a})});let f=!1;const p=()=>{f||(f=!0,u!==void 0&&clearInterval(u),typeof document<"u"&&document.removeEventListener("visibilitychange",m),y?.())};try{b(p)}catch{}return{present:g,sessionId:c,setData:I,teardown:p}};function A(t,e,o){const r=typeof t!="string",i=r?t:U();return C(i,r?e:t,r?o:e)}export{A as presence};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as s}from"@lunora/client/query";import{readable as c}from"svelte/store";import{getLunoraClient as d}from"./getLunoraClient-DU7BmZy1.mjs";import{i as y}from"./is-function-reference-ByqJF30w.mjs";function E(o,e,t,a){const r=!y(o),m=r?o:d(),u=r?e:o,f=r?t:e,n=(r?a:t)??{};return c(void 0,i=>s(m,u,f,{onData:p=>{i(p)},onError:n.onError,onReset:()=>{i(void 0)}},{shardKey:n.shardKey}))}export{E as query};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{evaluate as v}from"@lunora/ratelimit";import{writable as I,derived as r}from"svelte/store";import{i as L}from"./is-browser-BEdfLJHK.mjs";const D=(n,d={})=>{const a=d.now??Date.now,w=d.tickMs??1e3;let t;const f=I(0),u=()=>{f.update(e=>e+1)},s=r(f,()=>v(n,t,{consume:!1,count:1,now:a(),reserve:!1}).status);let o;const c=()=>{o!==void 0&&(clearInterval(o),o=void 0)};let i=!0;const k=s.subscribe(e=>{i=e.ok}),m=()=>{i||o!==void 0||(o=setInterval(()=>{u(),i&&c()},w))};L()&&m();const p=(e=1)=>{const l=v(n,t,{consume:!0,count:e,now:a(),reserve:!1});return l.value!==void 0&&(t=l.value),u(),m(),l.status},b=(e=1)=>v(n,t,{consume:!1,count:e,now:a(),reserve:!1}).status.ok,y=()=>{t=void 0,c(),u()},A=()=>{c(),k()};return{check:b,consume:p,disabled:r(s,e=>!e.ok),ok:r(s,e=>e.ok),reset:y,retryAfter:r(s,e=>e.retryAfter),teardown:A}};export{D as rateLimit};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{writable as h,readable as E}from"svelte/store";import{getLunoraClient as K}from"./getLunoraClient-DU7BmZy1.mjs";import{i as R}from"./is-function-reference-ByqJF30w.mjs";function L(i,u,f,p){const t=!R(i),w=t?i:K(),y=t?u:i,m=t?f:u,g=(t?p:f)??{},{maxBuffer:k,shardKey:x}=g,r=h("idle"),a=h();let s;const b=()=>{s?.()},v=E([],l=>{if(l([]),a.set(void 0),m==="skip")return r.set("idle"),()=>{};r.set("streaming");let n=!0,c=[];const d=w.stream(y,m,{maxBuffer:k,shardKey:x}),o=()=>{d.cancel()};return s=o,(async()=>{try{for await(const e of d){if(!n)return;c=[...c,e],l(c)}n&&r.set("complete")}catch(e){if(!n)return;a.set(e instanceof Error?e:new Error(String(e))),r.set("error")}})().catch(()=>{}),()=>{n=!1,o(),s===o&&(s=void 0)}}),B=()=>{b()};return{cancel:b,chunks:v,error:{subscribe:a.subscribe},status:{subscribe:r.subscribe},teardown:B}}export{L as stream};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createQuerySubscription as E}from"@lunora/client/query";import{writable as l,readable as y}from"svelte/store";import{getLunoraClient as g}from"./getLunoraClient-DU7BmZy1.mjs";import{i as h}from"./is-function-reference-ByqJF30w.mjs";function S(o,n,s,c){const r=!h(o),u=r?o:g(),b=r?n:o,d=r?s:n,m=(r?c:s)??{},{shardKey:p,onError:f}=m,e=l();return{data:y(void 0,i=>{const v=E(u,b,d,{onData:t=>{i(t),e.set(void 0)},onError:t=>{const a=new Error(t.message);e.set(a),f?.(a)},onReset:()=>{i(void 0)}},{shardKey:p});return()=>{v(),e.set(void 0)}}),error:{subscribe:e.subscribe}}}export{S as subscription};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{writable as w,get as L}from"svelte/store";import{isClient as R}from"./agent-CddTbgxO.mjs";import{getLunoraClient as W}from"./getLunoraClient-DU7BmZy1.mjs";const V=e=>{if(e.length===0)return 0;let o=0;for(const s of e)o+=s*s;return Math.sqrt(o/e.length)},B=(e,o)=>{const s=o/16e3,i=s>1?Math.floor(e.length/s):e.length,d=new ArrayBuffer(i*2),a=new DataView(d);for(let l=0;l<i;l+=1){const g=e[Math.floor(l*s)]??0,b=Math.max(-1,Math.min(1,g));a.setInt16(l*2,b<0?b*32768:b*32767,!0)}return new Uint8Array(d)},I=async e=>{const o=globalThis,s=o.navigator?.mediaDevices?.getUserMedia.bind(o.navigator.mediaDevices),i=o.AudioContext??o.webkitAudioContext;if(!s||!i)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const d=await s({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),a=new i,l=a.createMediaStreamSource(d),g=a.createScriptProcessor(4096,1,1);let b=!1,m=!1,f=0,n=0;return g.onaudioprocess=c=>{const p=c.inputBuffer.getChannelData(0),h=b?0:V(p);if(e.onLevel(h),b)return;if(e.onAudio(B(p,a.sampleRate)),e.isSpeaking()){n=h>=e.interruptThreshold?n+1:0,n>=e.interruptChunks&&(n=0,e.onInterrupt());return}n=0;const A=p.length/a.sampleRate*1e3;if(h>=e.silenceThreshold){m=!0,f=0;return}m&&(f+=A,f>=e.silenceDurationMs&&(m=!1,f=0,e.onSilence()))},l.connect(g),g.connect(a.destination),{setMuted:c=>{b=c},stop:()=>{g.disconnect(),l.disconnect();for(const c of d.getTracks())c.stop();a.close()}}},P=()=>{const e=globalThis,o=e.AudioContext??e.webkitAudioContext;if(!o)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const s=new o,i=new Set;let d=0,a=Promise.resolve(),l=0;const g=async(f,n)=>{if(n!==l)return;let c;try{c=await s.decodeAudioData(f.buffer)}catch{return}if(n!==l)return;const p=s.createBufferSource();p.buffer=c,p.connect(s.destination);const h=Math.max(s.currentTime,d);p.start(h),d=h+c.duration,i.add(p),p.onended=()=>{i.delete(p)}},b=f=>{const n=Uint8Array.from(f),c=l;a=a.then(()=>g(n,c))},m=()=>{l+=1;for(const f of i)try{f.stop()}catch{}i.clear(),d=s.currentTime};return{enqueue:b,interrupt:m,stop:()=>{m(),s.close()}}},D=1,J=.01,K=1200,N=.15,O=3,j=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,z=e=>{const o=e.__lunoraRef,s=o.startsWith("agents:")?o.slice(7):o;return s.endsWith("Voice")?s.slice(0,-5):s},H=(e,o,s)=>{const i=j(e),d=i.endsWith("/")?i.slice(0,-1):i,a=new URLSearchParams({threadKey:s});return`${d}/_lunora/voice/${encodeURIComponent(o)}?${a.toString()}`},G=(e,o)=>{const{createMicrophone:s=I,createSpeaker:i=P,createSocket:d,interruptChunks:a=O,interruptThreshold:l=N,silenceDurationMs:g=K,silenceThreshold:b=J,threadKey:m,voice:f}=o,n=w("idle"),c=w(!1),p=w(""),h=w(""),A=w(0),S=w(!1),v=w();let u,C=!1;const M=r=>{const t=u?.socket;return t?.readyState===D?(t.send(JSON.stringify(r)),!0):!1},x=()=>{const r=u;if(u=void 0,r){r.microphone?.stop(),r.speaker?.stop();try{r.socket.close()}catch{}}C=!1,c.set(!1),n.set("idle"),A.set(0)},U=x,$=r=>{const t=u;switch(r.type){case"assistant_delta":{t&&(t.speaking=!0),n.set("speaking"),h.update(y=>y+r.text);break}case"assistant_done":{t&&(t.speaking=!1),h.set(r.text),n.set("listening");break}case"error":{t&&(t.speaking=!1),v.set(new Error(r.message)),n.set("listening");break}case"interrupted":{t&&(t.speaking=!1,t.suppressAudio=!1),t?.speaker?.interrupt(),n.set("listening");break}case"ready":{t&&(t.audioFormat=r.audioFormat,t.suppressAudio=!1),c.set(!0),n.set("listening");break}case"user_transcript":{t&&(t.suppressAudio=!1),p.set(r.text),h.set(""),n.set("thinking");break}}},E=r=>{const t=u;!t||t.suppressAudio||(t.speaker??=i({audioFormat:t.audioFormat}),t.speaking=!0,n.set("speaking"),t.speaker.enqueue(r))},_=async()=>{if(!(u||C)){C=!0,v.set(void 0),p.set(""),h.set("");try{const r=H(e.url,z(f),m),t=(d??(k=>new globalThis.WebSocket(k)))(r);t.binaryType="arraybuffer";const y={audioFormat:"mp3",microphone:void 0,socket:t,speaker:void 0,speaking:!1,suppressAudio:!1};u=y,t.onmessage=k=>{if(typeof k.data=="string"){try{$(JSON.parse(k.data))}catch{}return}E(new Uint8Array(k.data))},t.onerror=()=>{v.set(new Error("voiceAgent: voice socket error"))},t.onclose=()=>{u===y&&x()};const T=await s({interruptChunks:a,interruptThreshold:l,isSpeaking:()=>u?.speaking??!1,onAudio:k=>{t.readyState===D&&t.send(k)},onInterrupt:()=>{M({type:"interrupt"}),u?.speaker?.interrupt(),u&&(u.speaking=!1,u.suppressAudio=!0),n.set("listening")},onLevel:k=>{A.set(k)},onSilence:()=>{M({type:"commit"}),n.set("thinking")},silenceDurationMs:g,silenceThreshold:b});u===y?(y.microphone=T,S.set(!1),n.set("listening")):T.stop()}catch(r){v.set(r instanceof Error?r:new Error(String(r))),x()}finally{C=!1}}},q=()=>{const r=!L(S);return u?.microphone?.setMuted(r),S.set(r),r},F=r=>{M({text:r,type:"text"})&&n.set("thinking")};return{audioLevel:{subscribe:A.subscribe},connected:{subscribe:c.subscribe},endCall:U,error:{subscribe:v.subscribe},interimTranscript:{subscribe:h.subscribe},isMuted:{subscribe:S.subscribe},sendText:F,startCall:_,status:{subscribe:n.subscribe},toggleMute:q,transcript:{subscribe:p.subscribe}}};function Z(e,o){const s=R(e),i=s?e:W();return G(i,s?o:e)}export{Z 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/dist/worker.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{withFrameworkWorker as a}from"@lunora/runtime";export{a as withLunora};
|
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.71",
|
|
4
4
|
"description": "Svelte adapter for Lunora — live stores, optimistic mutations, and reactive loaders",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -48,15 +48,21 @@
|
|
|
48
48
|
"types": "./dist/worker.d.ts",
|
|
49
49
|
"import": "./dist/worker.mjs"
|
|
50
50
|
},
|
|
51
|
+
"./upload": {
|
|
52
|
+
"types": "./dist/upload.d.ts",
|
|
53
|
+
"import": "./dist/upload.mjs"
|
|
54
|
+
},
|
|
51
55
|
"./package.json": "./package.json"
|
|
52
56
|
},
|
|
53
57
|
"publishConfig": {
|
|
54
58
|
"access": "public"
|
|
55
59
|
},
|
|
56
60
|
"dependencies": {
|
|
57
|
-
"@lunora/client": "1.0.0-alpha.
|
|
58
|
-
"@lunora/
|
|
59
|
-
"@lunora/
|
|
61
|
+
"@lunora/client": "1.0.0-alpha.43",
|
|
62
|
+
"@lunora/errors": "1.0.0-alpha.16",
|
|
63
|
+
"@lunora/ratelimit": "1.0.0-alpha.19",
|
|
64
|
+
"@lunora/runtime": "1.0.0-alpha.57",
|
|
65
|
+
"@visulima/storage-client": "1.0.0"
|
|
60
66
|
},
|
|
61
67
|
"peerDependencies": {
|
|
62
68
|
"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--bwSz7F6.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--bwSz7F6.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,16 +0,0 @@
|
|
|
1
|
-
import { setContext, getContext } from 'svelte';
|
|
2
|
-
|
|
3
|
-
const LUNORA_CONTEXT_KEY = /* @__PURE__ */ Symbol("lunora.client");
|
|
4
|
-
const setLunoraClient = (client) => {
|
|
5
|
-
setContext(LUNORA_CONTEXT_KEY, client);
|
|
6
|
-
return client;
|
|
7
|
-
};
|
|
8
|
-
const getLunoraClient = () => {
|
|
9
|
-
const client = getContext(LUNORA_CONTEXT_KEY);
|
|
10
|
-
if (!client) {
|
|
11
|
-
throw new Error("getLunoraClient(): no LunoraClient in context — call setLunoraClient(client) in an ancestor component first.");
|
|
12
|
-
}
|
|
13
|
-
return client;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export { getLunoraClient, setLunoraClient };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { readable } from 'svelte/store';
|
|
2
|
-
import { getLunoraClient } from './getLunoraClient--bwSz7F6.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--bwSz7F6.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--bwSz7F6.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,66 +0,0 @@
|
|
|
1
|
-
import { readable } from 'svelte/store';
|
|
2
|
-
import { getLunoraClient } from './getLunoraClient--bwSz7F6.mjs';
|
|
3
|
-
|
|
4
|
-
const makeSessionId = () => {
|
|
5
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
6
|
-
return crypto.randomUUID();
|
|
7
|
-
}
|
|
8
|
-
return `sess-${Math.random().toString(36).slice(2)}-${String(Date.now())}`;
|
|
9
|
-
};
|
|
10
|
-
const DEFAULT_INTERVAL_MS = 1e4;
|
|
11
|
-
const createPresenceHandle = (client, roomId, options) => {
|
|
12
|
-
const { heartbeat, intervalMs = DEFAULT_INTERVAL_MS, listPresent, shardKey } = options;
|
|
13
|
-
const sessionId = options.sessionId ?? makeSessionId();
|
|
14
|
-
let latestData = options.data;
|
|
15
|
-
const sendHeartbeat = () => {
|
|
16
|
-
const args = {
|
|
17
|
-
roomId,
|
|
18
|
-
sessionId,
|
|
19
|
-
...latestData === void 0 ? {} : { data: latestData }
|
|
20
|
-
};
|
|
21
|
-
client.mutation(heartbeat, args, { shardKey }).catch(() => void 0);
|
|
22
|
-
};
|
|
23
|
-
const setData = (next) => {
|
|
24
|
-
latestData = next;
|
|
25
|
-
sendHeartbeat();
|
|
26
|
-
};
|
|
27
|
-
sendHeartbeat();
|
|
28
|
-
const intervalHandle = setInterval(sendHeartbeat, intervalMs);
|
|
29
|
-
const onVisible = () => {
|
|
30
|
-
if (typeof document !== "undefined" && document.visibilityState === "visible") {
|
|
31
|
-
sendHeartbeat();
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
if (typeof document !== "undefined") {
|
|
35
|
-
document.addEventListener("visibilitychange", onVisible);
|
|
36
|
-
}
|
|
37
|
-
const releaseConnectionContext = client.acquireConnectionContext({ roomId, sessionId }, { shardKey });
|
|
38
|
-
const present = readable(void 0, (set) => {
|
|
39
|
-
const unsubscribe = client.subscribe(
|
|
40
|
-
listPresent,
|
|
41
|
-
{ roomId },
|
|
42
|
-
(value) => {
|
|
43
|
-
set(value);
|
|
44
|
-
},
|
|
45
|
-
{ shardKey }
|
|
46
|
-
);
|
|
47
|
-
return unsubscribe;
|
|
48
|
-
});
|
|
49
|
-
const teardown = () => {
|
|
50
|
-
clearInterval(intervalHandle);
|
|
51
|
-
if (typeof document !== "undefined") {
|
|
52
|
-
document.removeEventListener("visibilitychange", onVisible);
|
|
53
|
-
}
|
|
54
|
-
releaseConnectionContext();
|
|
55
|
-
};
|
|
56
|
-
return { present, sessionId, setData, teardown };
|
|
57
|
-
};
|
|
58
|
-
function presence(clientOrRoomId, roomIdOrOptions, maybeOptions) {
|
|
59
|
-
const hasExplicitClient = typeof clientOrRoomId !== "string";
|
|
60
|
-
const client = hasExplicitClient ? clientOrRoomId : getLunoraClient();
|
|
61
|
-
const roomId = hasExplicitClient ? roomIdOrOptions : clientOrRoomId;
|
|
62
|
-
const options = hasExplicitClient ? maybeOptions : roomIdOrOptions;
|
|
63
|
-
return createPresenceHandle(client, roomId, options);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export { presence };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { createQuerySubscription } from '@lunora/client/query';
|
|
2
|
-
import { readable } from 'svelte/store';
|
|
3
|
-
import { getLunoraClient } from './getLunoraClient--bwSz7F6.mjs';
|
|
4
|
-
import { i as isFunctionReference } from './is-function-reference-ycLAcI79.mjs';
|
|
5
|
-
|
|
6
|
-
function query(clientOrFunction, functionOrArguments, argumentsOrOptions, maybeOptions) {
|
|
7
|
-
const hasExplicitClient = !isFunctionReference(clientOrFunction);
|
|
8
|
-
const client = hasExplicitClient ? clientOrFunction : getLunoraClient();
|
|
9
|
-
const functionRef = hasExplicitClient ? functionOrArguments : clientOrFunction;
|
|
10
|
-
const args = hasExplicitClient ? argumentsOrOptions : functionOrArguments;
|
|
11
|
-
const options = (hasExplicitClient ? maybeOptions : argumentsOrOptions) ?? {};
|
|
12
|
-
return readable(
|
|
13
|
-
void 0,
|
|
14
|
-
(set) => (
|
|
15
|
-
// The shared `@lunora/client/query` state machine owns the subscribe +
|
|
16
|
-
// cleanup: it replays the last value synchronously when one exists and
|
|
17
|
-
// pushes every subsequent delta into the store, and its returned teardown
|
|
18
|
-
// is the store's stop callback, so the WS subscription closes when the
|
|
19
|
-
// last `$`-reader detaches.
|
|
20
|
-
createQuerySubscription(
|
|
21
|
-
client,
|
|
22
|
-
functionRef,
|
|
23
|
-
args,
|
|
24
|
-
{
|
|
25
|
-
onData: (value) => {
|
|
26
|
-
set(value);
|
|
27
|
-
},
|
|
28
|
-
onError: options.onError
|
|
29
|
-
},
|
|
30
|
-
{ shardKey: options.shardKey }
|
|
31
|
-
)
|
|
32
|
-
)
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { query };
|