@lunora/svelte 1.0.0-alpha.61 → 1.0.0-alpha.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +26 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/agent-CddTbgxO.mjs +1 -0
- package/dist/packem_shared/agentChat-DKfx2E6R.mjs +1 -0
- package/dist/packem_shared/{agentState-ZGfPOSwK.mjs → agentState-fc7KRCp9.mjs} +1 -1
- package/dist/packem_shared/{agentToolEvents-BYjBe2-X.mjs → agentToolEvents-sOUvSZsy.mjs} +1 -1
- package/dist/packem_shared/auth-BWCPnv0n.mjs +1 -0
- package/dist/packem_shared/infiniteQuery-Cm9qC-mf.mjs +1 -0
- package/dist/packem_shared/is-browser-BEdfLJHK.mjs +1 -0
- package/dist/packem_shared/presence-C2YC1KOc.mjs +1 -0
- package/dist/packem_shared/rateLimit-DtykU7F_.mjs +1 -0
- package/dist/packem_shared/{voiceAgent-BxIYZRin.mjs → voiceAgent-D-82ai_D.mjs} +1 -1
- package/package.json +5 -5
- package/dist/packem_shared/agent-BEqcvTwb.mjs +0 -1
- package/dist/packem_shared/agentChat-Dv-ubf5a.mjs +0 -1
- package/dist/packem_shared/auth-DNOb_Wm7.mjs +0 -1
- package/dist/packem_shared/infiniteQuery-CIxf7GMM.mjs +0 -1
- package/dist/packem_shared/presence-D-m3S1lu.mjs +0 -1
- package/dist/packem_shared/rateLimit-CwhxlHqx.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -475,6 +475,31 @@ interface AuthStore {
|
|
|
475
475
|
* Pass an explicit client to bypass the ambient context (useful in tests).
|
|
476
476
|
*/
|
|
477
477
|
declare const auth: (explicitClient?: ReturnType<typeof getLunoraClient>) => AuthStore;
|
|
478
|
+
/** Derived auth-gate stores for template gating (`{#if $isAuthenticated}`), built on {@link auth}. */
|
|
479
|
+
interface AuthGateStore {
|
|
480
|
+
/** Readable store, `true` once a token is set and the user has resolved. */
|
|
481
|
+
isAuthenticated: Readable<boolean>;
|
|
482
|
+
/** Readable store, `true` while a token is set but the user hasn't resolved yet. */
|
|
483
|
+
isLoading: Readable<boolean>;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Derived auth-gate stores built on {@link auth}. Svelte has no JSX-style
|
|
487
|
+
* `Authenticated` slot component the way React/Vue/Solid do (this package is
|
|
488
|
+
* plain `.ts` over stores — no `.svelte` component compiler required), so this
|
|
489
|
+
* exposes the same three-state logic as two boolean stores instead: a token
|
|
490
|
+
* with no resolved user yet is `isLoading`; a token with a resolved user is
|
|
491
|
+
* `isAuthenticated`; no token is neither (the signed-out state a template
|
|
492
|
+
* checks for with a plain `{:else}`).
|
|
493
|
+
*
|
|
494
|
+
* ```ts
|
|
495
|
+
* import { authGate } from "@lunora/svelte";
|
|
496
|
+
* const { isAuthenticated, isLoading } = authGate();
|
|
497
|
+
* // markup: {#if $isAuthenticated} signed in {:else if $isLoading} loading… {:else} signed out {/if}
|
|
498
|
+
* ```
|
|
499
|
+
*
|
|
500
|
+
* Pass an explicit client to bypass the ambient context (useful in tests).
|
|
501
|
+
*/
|
|
502
|
+
declare const authGate: (explicitClient?: ReturnType<typeof getLunoraClient>) => AuthGateStore;
|
|
478
503
|
/** The shape held by a {@link connectionStatus} store: the latest aggregate live-socket status. */
|
|
479
504
|
type ConnectionStatusStore = Readable<ConnectionStatus>;
|
|
480
505
|
/**
|
|
@@ -1036,4 +1061,4 @@ interface VoiceAgentHandle {
|
|
|
1036
1061
|
*/
|
|
1037
1062
|
declare function voiceAgent(options: VoiceAgentOptions): VoiceAgentHandle;
|
|
1038
1063
|
declare function voiceAgent(client: LunoraClient, options: VoiceAgentOptions): VoiceAgentHandle;
|
|
1039
|
-
export { type AgentApi, type AgentChatApi, type AgentChatHandle, type AgentChatMessage, type AgentChatOptions, type AgentHandle, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentStateApi, type AgentStateHandle, type AgentStateOptions, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsHandle, type AgentToolEventsOptions, type AuthStore, type ConnectionStatusStore, type FlagContext, type FlagValue, type HeartbeatReference, type InfiniteQueryHandle, type InfiniteQueryOptions, type ListPresentReference, type MutationHandle, type MutatorHandleStore, type PageItemOf, type PaginatedArgs, type PaginatedQueryHandle, type PaginatedQueryOptions, type PresenceHandle, type PresenceOptions, type QueryStore, type QueryStoreOptions, type RateLimitHandle, type RateLimitOptions, type StreamHandle, type StreamStatus, type StreamStoreOptions, type SubscriptionHandle, type SubscriptionStoreOptions, type VoiceAgentHandle, type VoiceAgentOptions, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, agent, agentChat, agentState, agentToolEvents, auth, connectionStatus, flag, flags, getLunoraClient, hydratePreloaded, infiniteQuery, mutation, mutator, paginatedQuery, presence, query, rateLimit, setLunoraClient, stream, subscription, voiceAgent };
|
|
1064
|
+
export { type AgentApi, type AgentChatApi, type AgentChatHandle, type AgentChatMessage, type AgentChatOptions, type AgentHandle, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentStateApi, type AgentStateHandle, type AgentStateOptions, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsHandle, type AgentToolEventsOptions, type AuthGateStore, type AuthStore, type ConnectionStatusStore, type FlagContext, type FlagValue, type HeartbeatReference, type InfiniteQueryHandle, type InfiniteQueryOptions, type ListPresentReference, type MutationHandle, type MutatorHandleStore, type PageItemOf, type PaginatedArgs, type PaginatedQueryHandle, type PaginatedQueryOptions, type PresenceHandle, type PresenceOptions, type QueryStore, type QueryStoreOptions, type RateLimitHandle, type RateLimitOptions, type StreamHandle, type StreamStatus, type StreamStoreOptions, type SubscriptionHandle, type SubscriptionStoreOptions, type VoiceAgentHandle, type VoiceAgentOptions, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, agent, agentChat, agentState, agentToolEvents, auth, authGate, connectionStatus, flag, flags, getLunoraClient, hydratePreloaded, infiniteQuery, mutation, mutator, paginatedQuery, presence, query, rateLimit, setLunoraClient, stream, subscription, voiceAgent };
|
package/dist/index.d.ts
CHANGED
|
@@ -475,6 +475,31 @@ interface AuthStore {
|
|
|
475
475
|
* Pass an explicit client to bypass the ambient context (useful in tests).
|
|
476
476
|
*/
|
|
477
477
|
declare const auth: (explicitClient?: ReturnType<typeof getLunoraClient>) => AuthStore;
|
|
478
|
+
/** Derived auth-gate stores for template gating (`{#if $isAuthenticated}`), built on {@link auth}. */
|
|
479
|
+
interface AuthGateStore {
|
|
480
|
+
/** Readable store, `true` once a token is set and the user has resolved. */
|
|
481
|
+
isAuthenticated: Readable<boolean>;
|
|
482
|
+
/** Readable store, `true` while a token is set but the user hasn't resolved yet. */
|
|
483
|
+
isLoading: Readable<boolean>;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Derived auth-gate stores built on {@link auth}. Svelte has no JSX-style
|
|
487
|
+
* `Authenticated` slot component the way React/Vue/Solid do (this package is
|
|
488
|
+
* plain `.ts` over stores — no `.svelte` component compiler required), so this
|
|
489
|
+
* exposes the same three-state logic as two boolean stores instead: a token
|
|
490
|
+
* with no resolved user yet is `isLoading`; a token with a resolved user is
|
|
491
|
+
* `isAuthenticated`; no token is neither (the signed-out state a template
|
|
492
|
+
* checks for with a plain `{:else}`).
|
|
493
|
+
*
|
|
494
|
+
* ```ts
|
|
495
|
+
* import { authGate } from "@lunora/svelte";
|
|
496
|
+
* const { isAuthenticated, isLoading } = authGate();
|
|
497
|
+
* // markup: {#if $isAuthenticated} signed in {:else if $isLoading} loading… {:else} signed out {/if}
|
|
498
|
+
* ```
|
|
499
|
+
*
|
|
500
|
+
* Pass an explicit client to bypass the ambient context (useful in tests).
|
|
501
|
+
*/
|
|
502
|
+
declare const authGate: (explicitClient?: ReturnType<typeof getLunoraClient>) => AuthGateStore;
|
|
478
503
|
/** The shape held by a {@link connectionStatus} store: the latest aggregate live-socket status. */
|
|
479
504
|
type ConnectionStatusStore = Readable<ConnectionStatus>;
|
|
480
505
|
/**
|
|
@@ -1036,4 +1061,4 @@ interface VoiceAgentHandle {
|
|
|
1036
1061
|
*/
|
|
1037
1062
|
declare function voiceAgent(options: VoiceAgentOptions): VoiceAgentHandle;
|
|
1038
1063
|
declare function voiceAgent(client: LunoraClient, options: VoiceAgentOptions): VoiceAgentHandle;
|
|
1039
|
-
export { type AgentApi, type AgentChatApi, type AgentChatHandle, type AgentChatMessage, type AgentChatOptions, type AgentHandle, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentStateApi, type AgentStateHandle, type AgentStateOptions, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsHandle, type AgentToolEventsOptions, type AuthStore, type ConnectionStatusStore, type FlagContext, type FlagValue, type HeartbeatReference, type InfiniteQueryHandle, type InfiniteQueryOptions, type ListPresentReference, type MutationHandle, type MutatorHandleStore, type PageItemOf, type PaginatedArgs, type PaginatedQueryHandle, type PaginatedQueryOptions, type PresenceHandle, type PresenceOptions, type QueryStore, type QueryStoreOptions, type RateLimitHandle, type RateLimitOptions, type StreamHandle, type StreamStatus, type StreamStoreOptions, type SubscriptionHandle, type SubscriptionStoreOptions, type VoiceAgentHandle, type VoiceAgentOptions, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, agent, agentChat, agentState, agentToolEvents, auth, connectionStatus, flag, flags, getLunoraClient, hydratePreloaded, infiniteQuery, mutation, mutator, paginatedQuery, presence, query, rateLimit, setLunoraClient, stream, subscription, voiceAgent };
|
|
1064
|
+
export { type AgentApi, type AgentChatApi, type AgentChatHandle, type AgentChatMessage, type AgentChatOptions, type AgentHandle, type AgentLiveEvent, type AgentOptions, type AgentProgressEvent, type AgentStateApi, type AgentStateHandle, type AgentStateOptions, type AgentThreadRecord, type AgentThreadStatus, type AgentTokenDelta, type AgentToolEvent, type AgentToolEventsApi, type AgentToolEventsHandle, type AgentToolEventsOptions, type AuthGateStore, type AuthStore, type ConnectionStatusStore, type FlagContext, type FlagValue, type HeartbeatReference, type InfiniteQueryHandle, type InfiniteQueryOptions, type ListPresentReference, type MutationHandle, type MutatorHandleStore, type PageItemOf, type PaginatedArgs, type PaginatedQueryHandle, type PaginatedQueryOptions, type PresenceHandle, type PresenceOptions, type QueryStore, type QueryStoreOptions, type RateLimitHandle, type RateLimitOptions, type StreamHandle, type StreamStatus, type StreamStoreOptions, type SubscriptionHandle, type SubscriptionStoreOptions, type VoiceAgentHandle, type VoiceAgentOptions, type VoiceAudioFormat, type VoiceReference, type VoiceStatus, agent, agentChat, agentState, agentToolEvents, auth, authGate, connectionStatus, flag, flags, getLunoraClient, hydratePreloaded, infiniteQuery, mutation, mutator, paginatedQuery, presence, query, rateLimit, setLunoraClient, stream, subscription, voiceAgent };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{agent as
|
|
1
|
+
import{agent as o}from"./packem_shared/agent-CddTbgxO.mjs";import{agentChat as a}from"./packem_shared/agentChat-DKfx2E6R.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-kAz4soTW.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-Cm9qC-mf.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-D-82ai_D.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 x,maxSeq as j}from"@lunora/client";import{writable as h}from"svelte/store";import{i as b}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 g}from"./mutation-fa0Bj5Bo.mjs";import{stream as $}from"./stream-DItOnXt6.mjs";const z={__lunoraRef:""},G=(s,m)=>{const{api:o,cancel:d,limit:f,send:A,sendArgs:T,stream:y,threadKey:a}=m,_=g(s,A),q=g(s,d??U),v=g(s,o.agents.agentResolveApproval);let r,i=[],c=[],w=[],I=0;const u=h([]),k=h(),C=h(""),l=()=>{const t=x(c,i);if(t.length===0){u.set(i);return}const n=j(i);u.set([...i,...t.map((e,p)=>({content:e.content,optimistic:!0,role:"user",seq:n+1+p}))])},K=()=>{const t=i.filter(e=>e.role==="assistant").length,n=w.filter(e=>e.kind!=="progress"&&e.threadKey===a&&e.turn>=t).map(e=>e.text).join("");C.set(n)},E=y===void 0?"skip":{key:a},O=b()?$(s,y??z,E).chunks.subscribe(t=>{w=t,K()}):()=>{},R=f===void 0?{key:a}:{key:a,limit:f},S=b()?s.subscribe(o.agents.agentMessages,R,t=>{i=t,l(),K()}):()=>{},N=b()?s.subscribe(o.agents.agentThread,{key:a},t=>{r=t,k.set(r?.status)}):()=>{},D=async(t,n)=>{const e=I;I+=1;const p=j(i);c=[...x(c,i),{content:t,id:e,maxDurableSeqAtSend:p}],l();try{await _.mutate({input:t,threadKey:a,...T,...n})}catch(H){throw c=c.filter(P=>P.id!==e),l(),H}},F=async(t,n)=>{const e=r?.instanceId;if(e===void 0)throw new Error("agentChat: cannot approve — no in-flight run (thread has no instanceId)");await v.mutate({decision:"approve",instanceId:e,threadKey:a,toolCallId:t,...n===void 0?{}:{note:n}})},L=async(t,n)=>{const e=r?.instanceId;if(e===void 0)throw new Error("agentChat: cannot reject — no in-flight run (thread has no instanceId)");await v.mutate({decision:"reject",instanceId:e,threadKey:a,toolCallId:t,...n===void 0?{}:{note:n}})},M=async()=>{const t=r?.instanceId;d===void 0||t===void 0||await q.mutate({instanceId:t,threadKey:a})},B=()=>{S(),N(),O()};return{approve:F,cancel:M,messages:{subscribe:u.subscribe},reject:L,send:D,status:{subscribe:k.subscribe},streamingText:{subscribe:C.subscribe},teardown:B}};function nt(s,m){const o=Q(s),d=o?s:V();return G(d,o?m:s)}export{nt as agentChat};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{derived as p}from"svelte/store";import{isClient as f}from"./agent-
|
|
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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{derived as c}from"svelte/store";import{isClient as g}from"./agent-
|
|
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{initialPages as K,derivePaginationStatus as T,applyLoadMore as V,rebalance as q}from"@lunora/client/pagination";import{derived as A,writable as B,readable as G,get as N}from"svelte/store";import{getLunoraClient as I}from"./getLunoraClient-DU7BmZy1.mjs";import{i as Q}from"./is-function-reference-ByqJF30w.mjs";const H=(e,n)=>e<n?-1:e>n?1:0,U=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(c=>U(c)).join(",")}]`;const n=Object.getPrototypeOf(e);if(n!==null&&n!==Object.prototype){const c=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${c} 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 c of b){const t=s[c];t!==void 0&&i.push(`${JSON.stringify(c)}:${U(t)}`)}return`{${i.join(",")}}`},E=e=>{let n="";for(let s=0;s<e.length;s+=32768)n+=String.fromCharCode(...e.subarray(s,s+32768));return btoa(n)},l="$lunora.wire$",D=64,S=(e,n=0)=>{if(n>D)throw new RangeError(`wire-codec: value nesting exceeds the ${D}-level limit`);if(e===void 0)return[l,"undefined"];if(e===null)return null;const s=typeof e;if(s==="bigint")return[l,"bigint",e.toString()];if(s==="number"){const t=e;return Number.isNaN(t)?[l,"nan"]:t===1/0?[l,"inf"]:t===-1/0?[l,"-inf"]:t}if(s!=="object")return e;if(e instanceof Date)return[l,"date",S(e.getTime(),n+1)];if(e instanceof Error){const t=e,r={};for(const u of Object.keys(t))t[u]!==void 0&&(r[u]=S(t[u],n+1));const o=[l,"error",t.name,t.message,r];return t.cause!==void 0&&o.push(S(t.cause,n+1)),o}if(e instanceof URL)return[l,"url",e.href];if(e instanceof Map)return[l,"map",[...e.entries()].map(([t,r])=>[S(t,n+1),S(r,n+1)])];if(e instanceof Set)return[l,"set",[...e].map(t=>S(t,n+1))];if(e instanceof ArrayBuffer)return[l,"bytes",E(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,r=t.constructor.name,o=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return r==="Uint8Array"?[l,"bytes",E(o)]:[l,"bytes",E(o),r]}if(Array.isArray(e)){const t=e.map(r=>S(r,n+1));return t.length>0&&t[0]===l?[l,"arr",t]:t}const b=Object.getPrototypeOf(e);if(b!==null&&b!==Object.prototype){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 i=e,c={};for(const t of Object.keys(i)){const r=i[t];r!==void 0&&(c[t]=S(r,n+1))}return c},X=e=>U(S(e)),$=(e,n)=>({...n,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),P=(e,n)=>`${e}::${X(n)}`,W=(e,n,s,b)=>{const{initialNumItems:i,shardKey:c}=b,t=B(K(i)),r=B([]),o=new Map,u=new Map,w=new Set,f=s,g=()=>{if(f==="skip"){r.set([]);return}const p=N(t).map(m=>{const v=P(n.__lunoraRef,$(m,f));return o.get(v)});r.set(p)},O=(p,m)=>{if(f==="skip")return;const v=a=>P(n.__lunoraRef,$(a,f));for(const a of m){const h=v(a);if(o.has(h))continue;const y=p.find(R=>R.lower===a.lower);if(y){const R=o.get(v(y));R&&o.set(h,R)}}},L=()=>{if(f==="skip"){for(const a of u.values())a();u.clear(),r.set([]);return}const p=f,m=N(t),v=new Set;for(const a of m)v.add(P(n.__lunoraRef,$(a,p)));for(const[a,h]of u)v.has(a)||(h(),u.delete(a),w.delete(a),o.delete(a));for(const a of m){const h=$(a,p),y=P(n.__lunoraRef,h);if(u.has(y))continue;w.add(y);const R=e.subscribe(n,h,F=>{if(o.set(y,F),w.delete(y),g(),w.size===0){const M=N(t),j=q(M,N(r));j&&(O(M,j),t.set(j),d(),g())}},{shardKey:c});u.set(y,R)}};let k=!1,_=!1;const d=()=>{if(k){_=!0;return}k=!0;try{do _=!1,L();while(_)}finally{k=!1}},x=()=>{for(const p of u.values())p();u.clear(),o.clear(),w.clear()},C=G([],p=>{const m=r.subscribe(p);return f!=="skip"&&(d(),g()),()=>{m(),x(),t.set(K(i)),r.set([])}}),z=A(C,p=>T(f==="skip",p).status);return{loadMore:p=>{if(f==="skip")return;const m=N(r),{nextCursor:v,status:a}=T(!1,m);if(a!=="CanLoadMore")return;const h=N(t),y=V(h,v,p);if(!y)return;const R=h.at(-1),F=y.at(-2);if(R&&F){const M=P(n.__lunoraRef,$(R,f)),j=P(n.__lunoraRef,$(F,f));if(M!==j){const J=o.get(M);J&&(o.set(j,J),o.delete(M))}}t.set(y),d(),g()},pageResults:C,status:z}};function ne(e,n,s,b){const i=!Q(e),c=i?e:I(),t=i?n:e,r=i?s:n,o=i?b:s,{loadMore:u,pageResults:w,status:f}=W(c,t,r,o),g=A(w,O=>{const L=[];for(const k of O)k&&L.push(...k.page);return L});return{isLoading:A(f,O=>O==="LoadingFirstPage"||O==="LoadingMore"),loadMore:u,results:g,status:f}}function re(e,n,s,b){const i=!Q(e),c=i?e:I(),t=i?n:e,r=i?s:n,o=i?b:s,{initialNumItems:u}=o,{loadMore:w,pageResults:f,status:g}=W(c,t,r,o),O=A(f,d=>{const x=[];for(const C of d)C&&x.push(C.page);return x}),L=A(g,d=>d==="LoadingFirstPage"),k=A(g,d=>d==="CanLoadMore"),_=A(g,d=>d==="LoadingMore");return{fetchNextPage:d=>{w(d??u)},hasNextPage:k,isFetchingNextPage:_,isLoading:L,pages:O,status:g}}export{re as infiniteQuery,ne as paginatedQuery};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o=()=>globalThis.window!==void 0;export{o as i};
|
|
@@ -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{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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{writable as w,get as L}from"svelte/store";import{isClient as R}from"./agent-
|
|
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/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.63",
|
|
4
4
|
"description": "Svelte adapter for Lunora — live stores, optimistic mutations, and reactive loaders",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -58,10 +58,10 @@
|
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@lunora/client": "1.0.0-alpha.
|
|
62
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
63
|
-
"@lunora/ratelimit": "1.0.0-alpha.
|
|
64
|
-
"@lunora/runtime": "1.0.0-alpha.
|
|
61
|
+
"@lunora/client": "1.0.0-alpha.36",
|
|
62
|
+
"@lunora/errors": "1.0.0-alpha.12",
|
|
63
|
+
"@lunora/ratelimit": "1.0.0-alpha.15",
|
|
64
|
+
"@lunora/runtime": "1.0.0-alpha.51",
|
|
65
65
|
"@visulima/storage-client": "1.0.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{writable as b}from"svelte/store";import{getLunoraClient as T}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as d}from"./mutation-fa0Bj5Bo.mjs";const _={__lunoraRef:""},A=t=>typeof t=="object"&&t!==null&&typeof t.subscribe=="function",C=(t,a)=>{const{api:e,cancel:s,run:l,runArgs:m,threadKey:i}=a,o=d(t,l),p=d(t,s??_);let r;const c=b(),u=b(),f=t.subscribe(e.agents.agentThread,{key:i},n=>{r=n,c.set(r),u.set(r?.status)}),y=async(n,w)=>{await o.mutate({input:n,threadKey:i,...m,...w})},g=async()=>{const n=r?.instanceId;s===void 0||n===void 0||await p.mutate({instanceId:n,threadKey:i})},h=()=>{f()};return{cancel:g,pending:o.pending,run:y,status:{subscribe:u.subscribe},teardown:h,thread:{subscribe:c.subscribe}}};function v(t,a){const e=A(t),s=e?t:T();return C(s,e?a:t)}export{_ as NO_MUTATION_REF,v as agent,A as isClient};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{reconcileOptimistic as x,maxSeq as K}from"@lunora/client";import{writable as h}from"svelte/store";import{isClient as H,NO_MUTATION_REF as J}from"./agent-BEqcvTwb.mjs";import{getLunoraClient as P}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as b}from"./mutation-fa0Bj5Bo.mjs";import{stream as U}from"./stream-DItOnXt6.mjs";const $={__lunoraRef:""},z=(a,u)=>{const{api:i,cancel:d,limit:g,send:j,sendArgs:A,stream:f,threadKey:s}=u,_=b(a,j),q=b(a,d??J),y=b(a,i.agents.agentResolveApproval);let o,r=[],c=[],v=[],w=0;const l=h([]),I=h(),k=h(""),m=()=>{const t=x(c,r);if(t.length===0){l.set(r);return}const n=K(r);l.set([...r,...t.map((e,p)=>({content:e.content,optimistic:!0,role:"user",seq:n+1+p}))])},C=()=>{const t=r.filter(e=>e.role==="assistant").length,n=v.filter(e=>e.kind!=="progress"&&e.threadKey===s&&e.turn>=t).map(e=>e.text).join("");k.set(n)},E=U(a,f??$,f===void 0?"skip":{key:s}).chunks.subscribe(t=>{v=t,C()}),O=g===void 0?{key:s}:{key:s,limit:g},R=a.subscribe(i.agents.agentMessages,O,t=>{r=t,m(),C()}),S=a.subscribe(i.agents.agentThread,{key:s},t=>{o=t,I.set(o?.status)}),T=async(t,n)=>{const e=w;w+=1;const p=K(r);c=[...x(c,r),{content:t,id:e,maxDurableSeqAtSend:p}],m();try{await _.mutate({input:t,threadKey:s,...A,...n})}catch(N){throw c=c.filter(G=>G.id!==e),m(),N}},M=async(t,n)=>{const e=o?.instanceId;if(e===void 0)throw new Error("agentChat: cannot approve — no in-flight run (thread has no instanceId)");await y.mutate({decision:"approve",instanceId:e,threadKey:s,toolCallId:t,...n===void 0?{}:{note:n}})},D=async(t,n)=>{const e=o?.instanceId;if(e===void 0)throw new Error("agentChat: cannot reject — no in-flight run (thread has no instanceId)");await y.mutate({decision:"reject",instanceId:e,threadKey:s,toolCallId:t,...n===void 0?{}:{note:n}})},F=async()=>{const t=o?.instanceId;d===void 0||t===void 0||await q.mutate({instanceId:t,threadKey:s})},L=()=>{R(),S(),E()};return{approve:M,cancel:F,messages:{subscribe:l.subscribe},reject:D,send:T,status:{subscribe:I.subscribe},streamingText:{subscribe:k.subscribe},teardown:L}};function Z(a,u){const i=H(a),d=i?a:P();return z(d,i?u:a)}export{Z as agentChat};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{getIdentityStore as a}from"@lunora/client/auth";import{readable as r}from"svelte/store";import{getLunoraClient as h}from"./getLunoraClient-DU7BmZy1.mjs";const T=n=>{const e=n??h(),o=a(e),s=r(e.getAuthToken(),t=>(t(e.getAuthToken()),e.onAuthTokenChange(g=>{t(g)}))),u=r(o.getUser(),t=>(t(o.getUser()),o.subscribe(()=>{t(o.getUser())})));return{setToken:t=>{e.setAuthToken(t)},token:s,user:u}};export{T as auth};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{initialPages as K,derivePaginationStatus as Q,applyLoadMore as j,rebalance as q}from"@lunora/client/pagination";import{derived as w,writable as $,readable as B,get as k}from"svelte/store";import{getLunoraClient as z}from"./getLunoraClient-DU7BmZy1.mjs";import{i as J}from"./is-function-reference-ByqJF30w.mjs";const C=(o,e)=>({...e,paginationOpts:{cursor:o.lower,endCursor:o.upper,numItems:o.numItems}}),F=(o,e)=>`${o}::${JSON.stringify(e)}`,T=(o,e,b,N)=>{const{initialNumItems:i,shardKey:v}=N,c=$(K(i)),l=$([]),n=new Map,u=new Map,m=new Set,s=b,d=()=>{if(s==="skip"){l.set([]);return}const r=k(c).map(p=>{const R=F(e.__lunoraRef,C(p,s));return n.get(R)});l.set(r)},M=(r,p)=>{if(s==="skip")return;const R=t=>F(e.__lunoraRef,C(t,s));for(const t of p){const g=R(t);if(n.has(g))continue;const f=r.find(h=>h.lower===t.lower);if(f){const h=n.get(R(f));h&&n.set(g,h)}}},L=()=>{if(s==="skip"){for(const t of u.values())t();u.clear(),l.set([]);return}const r=s,p=k(c),R=new Set;for(const t of p)R.add(F(e.__lunoraRef,C(t,r)));for(const[t,g]of u)R.has(t)||(g(),u.delete(t),m.delete(t),n.delete(t));for(const t of p){const g=C(t,r),f=F(e.__lunoraRef,g);if(u.has(f))continue;m.add(f);const h=o.subscribe(e,g,A=>{if(n.set(f,A),m.delete(f),d(),m.size===0){const P=k(c),y=q(P,k(l));y&&(M(P,y),c.set(y),a(),d())}},{shardKey:v});u.set(f,h)}};let _=!1,S=!1;const a=()=>{if(_){S=!0;return}_=!0;try{do S=!1,L();while(S)}finally{_=!1}},O=()=>{for(const r of u.values())r();u.clear(),n.clear(),m.clear()},x=B([],r=>{const p=l.subscribe(r);return s!=="skip"&&(a(),d()),()=>{p(),O(),c.set(K(i)),l.set([])}}),U=w(x,r=>Q(s==="skip",r).status);return{loadMore:r=>{if(s==="skip")return;const p=k(l),{nextCursor:R,status:t}=Q(!1,p);if(t!=="CanLoadMore")return;const g=k(c),f=j(g,R,r);if(!f)return;const h=g.at(-1),A=f.at(-2);if(h&&A){const P=F(e.__lunoraRef,C(h,s)),y=F(e.__lunoraRef,C(A,s));if(P!==y){const I=n.get(P);I&&(n.set(y,I),n.delete(P))}}c.set(f),a(),d()},pageResults:x,status:U}};function V(o,e,b,N){const i=!J(o),v=i?o:z(),c=i?e:o,l=i?b:e,n=i?N:b,{loadMore:u,pageResults:m,status:s}=T(v,c,l,n),d=w(m,M=>{const L=[];for(const _ of M)_&&L.push(..._.page);return L});return{isLoading:w(s,M=>M==="LoadingFirstPage"||M==="LoadingMore"),loadMore:u,results:d,status:s}}function W(o,e,b,N){const i=!J(o),v=i?o:z(),c=i?e:o,l=i?b:e,n=i?N:b,{initialNumItems:u}=n,{loadMore:m,pageResults:s,status:d}=T(v,c,l,n),M=w(s,a=>{const O=[];for(const x of a)x&&O.push(x.page);return O}),L=w(d,a=>a==="LoadingFirstPage"),_=w(d,a=>a==="CanLoadMore"),S=w(d,a=>a==="LoadingMore");return{fetchNextPage:a=>{m(a??u)},hasNextPage:_,isFetchingNextPage:S,isLoading:L,pages:M,status:d}}export{W as infiniteQuery,V as paginatedQuery};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{onDestroy as h}from"svelte";import{readable as g}from"svelte/store";import{getLunoraClient as D}from"./getLunoraClient-DU7BmZy1.mjs";const U=(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)}`},$=1e4,C=(t,e,o)=>{const{heartbeat:r,intervalMs:i=$,listPresent:p,shardKey:a}=o,c=o.sessionId??U();let d=o.data;const s=()=>{const n={roomId:e,sessionId:c,...d===void 0?{}:{data:d}};t.mutation(r,n,{shardKey:a}).catch(()=>{})},f=n=>{d=n,s()};s();const l=setInterval(s,i),u=()=>{typeof document<"u"&&document.visibilityState==="visible"&&s()};typeof document<"u"&&document.addEventListener("visibilitychange",u);const v=t.acquireConnectionContext({roomId:e,sessionId:c},{shardKey:a}),I=g(void 0,n=>t.subscribe(p,{roomId:e},b=>{n(b)},{shardKey:a}));let y=!1;const m=()=>{y||(y=!0,clearInterval(l),typeof document<"u"&&document.removeEventListener("visibilitychange",u),v())};try{h(m)}catch{}return{present:I,sessionId:c,setData:f,teardown:m}};function w(t,e,o){const r=typeof t!="string",i=r?t:D();return C(i,r?e:t,r?o:e)}export{w as presence};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{evaluate as v}from"@lunora/ratelimit";import{writable as I,derived as r}from"svelte/store";const x=(n,d={})=>{const a=d.now??Date.now,k=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 l=!0;const w=s.subscribe(e=>{l=e.ok}),m=()=>{l||o!==void 0||(o=setInterval(()=>{u(),l&&c()},k))};m();const b=(e=1)=>{const i=v(n,t,{consume:!0,count:e,now:a(),reserve:!1});return i.value!==void 0&&(t=i.value),u(),m(),i.status},p=(e=1)=>v(n,t,{consume:!1,count:e,now:a(),reserve:!1}).status.ok,y=()=>{t=void 0,c(),u()},A=()=>{c(),w()};return{check:p,consume:b,disabled:r(s,e=>!e.ok),ok:r(s,e=>e.ok),reset:y,retryAfter:r(s,e=>e.retryAfter),teardown:A}};export{x as rateLimit};
|