@lunora/svelte 1.0.0-alpha.105 → 1.0.0-alpha.106

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 CHANGED
@@ -104,7 +104,7 @@ All functions that require a component lifecycle (presence, rate-limit) return a
104
104
  | `query` | `useQuery` | Live readable store — updates on every server delta. |
105
105
  | `mutation` | `useMutation` | Optimistic mutation handle (`data`, `error`, `pending`, `mutate`, `reset` stores). |
106
106
  | `subscription` | `useSubscription` | Raw subscription readable — unbounded live stream. |
107
- | `paginatedQuery` | `usePaginatedQuery` | Cursor-paginated query with `loadMore`, `status`, and `results` stores. |
107
+ | `paginatedQuery` | `usePaginatedQuery` | Cursor-paginated query with `loadMore`, `status`, `results`, and `error` stores. |
108
108
  | `infiniteQuery` | `useInfiniteQuery` | Infinite-scroll variant of `paginatedQuery`. |
109
109
  | `auth` | `useAuth` | Reactive auth stores (`user`, `token`) plus `setToken`. |
110
110
  | `presence` | `usePresence` | Collaborative-awareness — heartbeat + live present-members readable + `teardown`. |
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { FunctionReference, ArgsOf, ActionCallOptions, ReturnOf, LunoraClient, User, ConnectionStatus, Preloaded, MutationCallOptions, MutatorHandle, SubscriptionErrorCallback } from '@lunora/client';
1
+ import { FunctionReference, ArgsOf, ActionCallOptions, ReturnOf, LunoraClient, SubscriptionErrorCallback, User, ConnectionStatus, Preloaded, MutationCallOptions, MutatorHandle, SubscriptionError } from '@lunora/client';
2
2
  export type { ArgsOf, ConnectionStatus, FunctionReference, LunoraClient, MutationCallOptions, MutatorHandle, MutatorTransaction, Preloaded, ReturnOf } from '@lunora/client';
3
3
  import { Readable } from 'svelte/store';
4
4
  import { PaginationStatus } from '@lunora/client/pagination';
@@ -96,6 +96,12 @@ interface AgentOptions {
96
96
  * When omitted (or no run is in flight) {@link AgentHandle.cancel} is a no-op.
97
97
  */
98
98
  cancel?: FunctionReference<"mutation">;
99
+ /**
100
+ * Called when the live thread subscription reports an error (a session
101
+ * expiry, an RLS denial). Without it such an error is dropped and `thread` /
102
+ * `status` freeze at their last value.
103
+ */
104
+ onError?: SubscriptionErrorCallback;
99
105
  /**
100
106
  * The app mutation that starts (or continues) a run — a thin wrapper over
101
107
  * `ctx.agents[name].run(...)`. Called with `{ threadKey, input }` merged with
@@ -259,6 +265,12 @@ interface AgentChatOptions {
259
265
  cancel?: FunctionReference<"mutation">;
260
266
  /** History depth forwarded to `agents:agentMessages`. */
261
267
  limit?: number;
268
+ /**
269
+ * Called when the live history or thread subscription reports an error (a
270
+ * session expiry, an RLS denial). Without it such an error is dropped and
271
+ * `messages` / `status` freeze at their last value.
272
+ */
273
+ onError?: SubscriptionErrorCallback;
262
274
  /**
263
275
  * The app mutation that starts (or continues) a run — a thin wrapper over
264
276
  * `ctx.agents[name].run(...)`. Called with `{ threadKey, input }` merged with
@@ -618,14 +630,18 @@ declare function flags<T extends Record<string, FlagValue>>(client: LunoraClient
618
630
  * `usePreloadedQuery`.
619
631
  *
620
632
  * Pass `client` explicitly, or omit it to resolve the ambient client published
621
- * by `setLunoraClient`.
633
+ * by `setLunoraClient`. Pass `onError` to surface a subscription-scoped error the
634
+ * server pushes (a session expiry, an RLS denial); without it such an error is
635
+ * dropped and the store keeps rendering the SSR snapshot as if it were live.
622
636
  *
623
637
  * Note on SSR: `readable`'s start callback only runs when the store is actually
624
638
  * subscribed (the browser), so on the server the store simply holds the seeded
625
639
  * value and opens no socket. The token's `value` is the single source of truth
626
640
  * for the first paint either way.
627
641
  */
628
- declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, client?: LunoraClient) => Readable<T>;
642
+ declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, client?: LunoraClient, options?: {
643
+ onError?: SubscriptionErrorCallback;
644
+ }) => Readable<T>;
629
645
  /**
630
646
  * The reactive handle returned by {@link mutation} — the Svelte counterpart to
631
647
  * React's `useMutation`, re-expressed as stores you read with `$`. The surface
@@ -713,9 +729,18 @@ type PageItemOf<F extends FunctionReference> = ReturnOf<F> extends {
713
729
  interface PaginatedQueryOptions {
714
730
  /** Page size for the first page (and the default for `loadMore`). */
715
731
  initialNumItems: number;
732
+ /** Called when a page subscription reports an error (also surfaced on the `error` store). */
733
+ onError?: SubscriptionErrorCallback;
716
734
  shardKey?: string;
717
735
  }
718
736
  interface PaginatedQueryHandle<T> {
737
+ /**
738
+ * The last page subscription error, or `undefined`. A tail page that fails
739
+ * before its first frame is dropped so `status` returns to `"CanLoadMore"`
740
+ * and `loadMore` can retry it; cleared by the next successful frame,
741
+ * `loadMore`, or an args emission.
742
+ */
743
+ error: Readable<SubscriptionError | undefined>;
719
744
  /** `true` while the first page or a `loadMore` page is in flight. */
720
745
  isLoading: Readable<boolean>;
721
746
  /** Request the next page. A no-op unless `status === "CanLoadMore"`. */
@@ -727,9 +752,13 @@ interface PaginatedQueryHandle<T> {
727
752
  interface InfiniteQueryOptions {
728
753
  /** Page size for the first page (and the default for `fetchNextPage`). */
729
754
  initialNumItems: number;
755
+ /** Called when a page subscription reports an error (also surfaced on the `error` store). */
756
+ onError?: SubscriptionErrorCallback;
730
757
  shardKey?: string;
731
758
  }
732
759
  interface InfiniteQueryHandle<T> {
760
+ /** The last page subscription error, or `undefined` — see `PaginatedQueryHandle.error`. */
761
+ error: Readable<SubscriptionError | undefined>;
733
762
  /** Request the next page. A no-op unless `status === "CanLoadMore"`. */
734
763
  fetchNextPage: (numberItems?: number) => void;
735
764
  /** `true` when the loaded tail reports it can load another page. */
@@ -868,9 +897,9 @@ type QueryStore<F extends FunctionReference> = Readable<ReturnOf<F> | undefined>
868
897
  * before this runs).
869
898
  *
870
899
  * `args` may also be a `Readable` store (wrap runes state with `toStore` or
871
- * `derived`): each emission tears down the previous subscription and opens a
872
- * fresh one against the new args — the Svelte counterpart of Vue's
873
- * `MaybeRefOrGetter` args. An emission of `"skip"` tears down without
900
+ * `derived`): each emission tears down the previous subscription, resets the
901
+ * value to `undefined`, and opens a fresh one against the new args — the Svelte
902
+ * counterpart of Vue's `MaybeRefOrGetter` args. An emission of `"skip"` tears down without
874
903
  * re-opening and resets the value to `undefined`.
875
904
  */
876
905
  declare function query<F extends FunctionReference>(function_: F, args: ReactiveArgs<F>, options?: QueryStoreOptions): QueryStore<F>;
@@ -915,6 +944,13 @@ declare const rateLimit: (config: RateLimitConfig, options?: RateLimitOptions) =
915
944
  /** The lifecycle of a stream the store is observing. */
916
945
  type StreamStatus = "complete" | "error" | "idle" | "streaming";
917
946
  interface StreamStoreOptions {
947
+ /**
948
+ * Opt into resume-on-reconnect for a stream the server declared `durable`.
949
+ * The chunks already received are kept and the socket re-attaches to the same
950
+ * run, so a dropped connection mid-generation continues instead of surfacing
951
+ * `STREAM_DISCONNECTED`. Has no effect on an ephemeral stream.
952
+ */
953
+ durable?: boolean;
918
954
  /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
919
955
  maxBuffer?: number;
920
956
  shardKey?: string;
@@ -973,8 +1009,8 @@ interface SubscriptionHandle<T> {
973
1009
  * argument to bypass the ambient context (useful in tests).
974
1010
  *
975
1011
  * `args` may also be a `Readable` store: each emission tears down the previous
976
- * subscription and opens a fresh one; a `"skip"` emission tears down without
977
- * re-opening and resets `data` to `undefined`.
1012
+ * subscription, resets `data` to `undefined`, and opens a fresh one; a `"skip"`
1013
+ * emission tears down without re-opening.
978
1014
  */
979
1015
  declare function subscription<F extends FunctionReference>(function_: F, args: ReactiveArgs<F>, options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
980
1016
  declare function subscription<F extends FunctionReference>(client: LunoraClient, function_: F, args: ReactiveArgs<F>, options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { FunctionReference, ArgsOf, ActionCallOptions, ReturnOf, LunoraClient, User, ConnectionStatus, Preloaded, MutationCallOptions, MutatorHandle, SubscriptionErrorCallback } from '@lunora/client';
1
+ import { FunctionReference, ArgsOf, ActionCallOptions, ReturnOf, LunoraClient, SubscriptionErrorCallback, User, ConnectionStatus, Preloaded, MutationCallOptions, MutatorHandle, SubscriptionError } from '@lunora/client';
2
2
  export type { ArgsOf, ConnectionStatus, FunctionReference, LunoraClient, MutationCallOptions, MutatorHandle, MutatorTransaction, Preloaded, ReturnOf } from '@lunora/client';
3
3
  import { Readable } from 'svelte/store';
4
4
  import { PaginationStatus } from '@lunora/client/pagination';
@@ -96,6 +96,12 @@ interface AgentOptions {
96
96
  * When omitted (or no run is in flight) {@link AgentHandle.cancel} is a no-op.
97
97
  */
98
98
  cancel?: FunctionReference<"mutation">;
99
+ /**
100
+ * Called when the live thread subscription reports an error (a session
101
+ * expiry, an RLS denial). Without it such an error is dropped and `thread` /
102
+ * `status` freeze at their last value.
103
+ */
104
+ onError?: SubscriptionErrorCallback;
99
105
  /**
100
106
  * The app mutation that starts (or continues) a run — a thin wrapper over
101
107
  * `ctx.agents[name].run(...)`. Called with `{ threadKey, input }` merged with
@@ -259,6 +265,12 @@ interface AgentChatOptions {
259
265
  cancel?: FunctionReference<"mutation">;
260
266
  /** History depth forwarded to `agents:agentMessages`. */
261
267
  limit?: number;
268
+ /**
269
+ * Called when the live history or thread subscription reports an error (a
270
+ * session expiry, an RLS denial). Without it such an error is dropped and
271
+ * `messages` / `status` freeze at their last value.
272
+ */
273
+ onError?: SubscriptionErrorCallback;
262
274
  /**
263
275
  * The app mutation that starts (or continues) a run — a thin wrapper over
264
276
  * `ctx.agents[name].run(...)`. Called with `{ threadKey, input }` merged with
@@ -618,14 +630,18 @@ declare function flags<T extends Record<string, FlagValue>>(client: LunoraClient
618
630
  * `usePreloadedQuery`.
619
631
  *
620
632
  * Pass `client` explicitly, or omit it to resolve the ambient client published
621
- * by `setLunoraClient`.
633
+ * by `setLunoraClient`. Pass `onError` to surface a subscription-scoped error the
634
+ * server pushes (a session expiry, an RLS denial); without it such an error is
635
+ * dropped and the store keeps rendering the SSR snapshot as if it were live.
622
636
  *
623
637
  * Note on SSR: `readable`'s start callback only runs when the store is actually
624
638
  * subscribed (the browser), so on the server the store simply holds the seeded
625
639
  * value and opens no socket. The token's `value` is the single source of truth
626
640
  * for the first paint either way.
627
641
  */
628
- declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, client?: LunoraClient) => Readable<T>;
642
+ declare const hydratePreloaded: <T>(preloaded: Preloaded<T>, client?: LunoraClient, options?: {
643
+ onError?: SubscriptionErrorCallback;
644
+ }) => Readable<T>;
629
645
  /**
630
646
  * The reactive handle returned by {@link mutation} — the Svelte counterpart to
631
647
  * React's `useMutation`, re-expressed as stores you read with `$`. The surface
@@ -713,9 +729,18 @@ type PageItemOf<F extends FunctionReference> = ReturnOf<F> extends {
713
729
  interface PaginatedQueryOptions {
714
730
  /** Page size for the first page (and the default for `loadMore`). */
715
731
  initialNumItems: number;
732
+ /** Called when a page subscription reports an error (also surfaced on the `error` store). */
733
+ onError?: SubscriptionErrorCallback;
716
734
  shardKey?: string;
717
735
  }
718
736
  interface PaginatedQueryHandle<T> {
737
+ /**
738
+ * The last page subscription error, or `undefined`. A tail page that fails
739
+ * before its first frame is dropped so `status` returns to `"CanLoadMore"`
740
+ * and `loadMore` can retry it; cleared by the next successful frame,
741
+ * `loadMore`, or an args emission.
742
+ */
743
+ error: Readable<SubscriptionError | undefined>;
719
744
  /** `true` while the first page or a `loadMore` page is in flight. */
720
745
  isLoading: Readable<boolean>;
721
746
  /** Request the next page. A no-op unless `status === "CanLoadMore"`. */
@@ -727,9 +752,13 @@ interface PaginatedQueryHandle<T> {
727
752
  interface InfiniteQueryOptions {
728
753
  /** Page size for the first page (and the default for `fetchNextPage`). */
729
754
  initialNumItems: number;
755
+ /** Called when a page subscription reports an error (also surfaced on the `error` store). */
756
+ onError?: SubscriptionErrorCallback;
730
757
  shardKey?: string;
731
758
  }
732
759
  interface InfiniteQueryHandle<T> {
760
+ /** The last page subscription error, or `undefined` — see `PaginatedQueryHandle.error`. */
761
+ error: Readable<SubscriptionError | undefined>;
733
762
  /** Request the next page. A no-op unless `status === "CanLoadMore"`. */
734
763
  fetchNextPage: (numberItems?: number) => void;
735
764
  /** `true` when the loaded tail reports it can load another page. */
@@ -868,9 +897,9 @@ type QueryStore<F extends FunctionReference> = Readable<ReturnOf<F> | undefined>
868
897
  * before this runs).
869
898
  *
870
899
  * `args` may also be a `Readable` store (wrap runes state with `toStore` or
871
- * `derived`): each emission tears down the previous subscription and opens a
872
- * fresh one against the new args — the Svelte counterpart of Vue's
873
- * `MaybeRefOrGetter` args. An emission of `"skip"` tears down without
900
+ * `derived`): each emission tears down the previous subscription, resets the
901
+ * value to `undefined`, and opens a fresh one against the new args — the Svelte
902
+ * counterpart of Vue's `MaybeRefOrGetter` args. An emission of `"skip"` tears down without
874
903
  * re-opening and resets the value to `undefined`.
875
904
  */
876
905
  declare function query<F extends FunctionReference>(function_: F, args: ReactiveArgs<F>, options?: QueryStoreOptions): QueryStore<F>;
@@ -915,6 +944,13 @@ declare const rateLimit: (config: RateLimitConfig, options?: RateLimitOptions) =
915
944
  /** The lifecycle of a stream the store is observing. */
916
945
  type StreamStatus = "complete" | "error" | "idle" | "streaming";
917
946
  interface StreamStoreOptions {
947
+ /**
948
+ * Opt into resume-on-reconnect for a stream the server declared `durable`.
949
+ * The chunks already received are kept and the socket re-attaches to the same
950
+ * run, so a dropped connection mid-generation continues instead of surfacing
951
+ * `STREAM_DISCONNECTED`. Has no effect on an ephemeral stream.
952
+ */
953
+ durable?: boolean;
918
954
  /** Forwarded to `client.stream()` — caps the in-flight chunk buffer. */
919
955
  maxBuffer?: number;
920
956
  shardKey?: string;
@@ -973,8 +1009,8 @@ interface SubscriptionHandle<T> {
973
1009
  * argument to bypass the ambient context (useful in tests).
974
1010
  *
975
1011
  * `args` may also be a `Readable` store: each emission tears down the previous
976
- * subscription and opens a fresh one; a `"skip"` emission tears down without
977
- * re-opening and resets `data` to `undefined`.
1012
+ * subscription, resets `data` to `undefined`, and opens a fresh one; a `"skip"`
1013
+ * emission tears down without re-opening.
978
1014
  */
979
1015
  declare function subscription<F extends FunctionReference>(function_: F, args: ReactiveArgs<F>, options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
980
1016
  declare function subscription<F extends FunctionReference>(client: LunoraClient, function_: F, args: ReactiveArgs<F>, options?: SubscriptionStoreOptions): SubscriptionHandle<ReturnOf<F>>;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{action as t}from"./packem_shared/action-SjeZUGhX.mjs";import{agent as a}from"./packem_shared/agent-CFzp-ncV.mjs";import{agentChat as f}from"./packem_shared/agentChat-BhMVjqq4.mjs";import{agentState as n}from"./packem_shared/agentState-at2Rg_Q9.mjs";import{agentToolEvents as i}from"./packem_shared/agentToolEvents-BrybzNXi.mjs";import{auth as g,authGate as s}from"./packem_shared/auth-Bew4W5n1.mjs";import{connectionStatus as l}from"./packem_shared/connectionStatus-D9A79Eqw.mjs";import{getLunoraClient as h,setLunoraClient as y}from"./packem_shared/getLunoraClient-DU7BmZy1.mjs";import{flag as L,flags as v}from"./packem_shared/flag-C6RFEBM_.mjs";import{hydratePreloaded as S}from"./packem_shared/hydratePreloaded-CW7Ak8zY.mjs";import{mutation as q}from"./packem_shared/mutation-DLBr5Op1.mjs";import{mutator as E}from"./packem_shared/mutator-DECDuo94.mjs";import{infiniteQuery as P,paginatedQuery as T}from"./packem_shared/infiniteQuery-CFBT6Hbs.mjs";import{presence as k}from"./packem_shared/presence-I_W9Zbhg.mjs";import{query as z}from"./packem_shared/query-aWSTFtNz.mjs";import{rateLimit as D}from"./packem_shared/rateLimit-Cli38qWO.mjs";import{stream as H}from"./packem_shared/stream-eY1eAuVw.mjs";import{subscription as J}from"./packem_shared/subscription-3foboeMU.mjs";import{voiceAgent as M}from"./packem_shared/voiceAgent-odCezdLl.mjs";export{t as action,a as agent,f as agentChat,n as agentState,i as agentToolEvents,g as auth,s as authGate,l as connectionStatus,L as flag,v as flags,h as getLunoraClient,S as hydratePreloaded,P as infiniteQuery,q as mutation,E as mutator,T as paginatedQuery,k as presence,z as query,D as rateLimit,y as setLunoraClient,H as stream,J as subscription,M as voiceAgent};
1
+ import{action as t}from"./packem_shared/action-SjeZUGhX.mjs";import{agent as a}from"./packem_shared/agent-WMVWf1Ks.mjs";import{agentChat as f}from"./packem_shared/agentChat-CJ048ZZl.mjs";import{agentState as n}from"./packem_shared/agentState-CAqcW2tF.mjs";import{agentToolEvents as i}from"./packem_shared/agentToolEvents-Dyu5BFZn.mjs";import{auth as g,authGate as s}from"./packem_shared/auth-Bew4W5n1.mjs";import{connectionStatus as l}from"./packem_shared/connectionStatus-D9A79Eqw.mjs";import{getLunoraClient as h,setLunoraClient as y}from"./packem_shared/getLunoraClient-DU7BmZy1.mjs";import{flag as L,flags as v}from"./packem_shared/flag-Csh9LBiO.mjs";import{hydratePreloaded as S}from"./packem_shared/hydratePreloaded-Douu4xsv.mjs";import{mutation as q}from"./packem_shared/mutation-DLBr5Op1.mjs";import{mutator as E}from"./packem_shared/mutator-DECDuo94.mjs";import{infiniteQuery as P,paginatedQuery as T}from"./packem_shared/infiniteQuery-CwF_9I0J.mjs";import{presence as k}from"./packem_shared/presence-BcBuOI0s.mjs";import{query as z}from"./packem_shared/query-BMl8EN8S.mjs";import{rateLimit as D}from"./packem_shared/rateLimit-Cli38qWO.mjs";import{stream as H}from"./packem_shared/stream-DGLI262b.mjs";import{subscription as J}from"./packem_shared/subscription-B1x2xDOl.mjs";import{voiceAgent as M}from"./packem_shared/voiceAgent-DsY2vCkg.mjs";export{t as action,a as agent,f as agentChat,n as agentState,i as agentToolEvents,g as auth,s as authGate,l as connectionStatus,L as flag,v as flags,h as getLunoraClient,S as hydratePreloaded,P as infiniteQuery,q as mutation,E as mutator,T as paginatedQuery,k as presence,z as query,D as rateLimit,y as setLunoraClient,H as stream,J as subscription,M as voiceAgent};
@@ -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 k,maxSeq as C}from"@lunora/client";import{writable as g}from"svelte/store";import{i as f}from"./is-browser-BEdfLJHK.mjs";import{isClient as J,NO_MUTATION_REF as O}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as P}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as h}from"./mutation-DLBr5Op1.mjs";import{stream as Q}from"./stream-DGLI262b.mjs";const V={__lunoraRef:""},W=(n,d)=>{const{api:a,cancel:u,limit:l,onError:v,send:E,sendArgs:I,stream:y,threadKey:r}=d,M=h(n,E),_=h(n,u??O),q=h(n,a.agents.agentResolveApproval);let m,o=[],i=[],x=[],S=0;const b=g([]),w=g(),A=g(""),p=()=>{const t=k(i,o);if(t.length===0){b.set(o);return}const s=C(o);b.set([...o,...t.map((e,c)=>({content:e.content,optimistic:!0,role:"user",seq:s+1+c}))])},T=()=>{const t=o.filter(e=>e.role==="assistant").length,s=x.filter(e=>e.kind!=="progress"&&e.threadKey===r&&e.turn>=t).map(e=>e.text).join("");A.set(s)},j=y===void 0?"skip":{key:r},N=f()?Q(n,y??V,j).chunks.subscribe(t=>{x=t,T()}):()=>{},D=l===void 0?{key:r}:{key:r,limit:l},F=f()?n.subscribe(a.agents.agentMessages,D,t=>{o=t,p(),T()},{onError:v}):()=>{},H=f()?n.subscribe(a.agents.agentThread,{key:r},t=>{m=t,w.set(m?.status)},{onError:v}):()=>{},K=async(t,s)=>{const e=S;S+=1;const c=C(o);i=[...k(i,o),{content:t,id:e,maxDurableSeqAtSend:c}],p();try{await M.mutate({input:t,threadKey:r,...I,...s})}catch(z){throw i=i.filter(G=>G.id!==e),p(),z}},R=async(t,s,e)=>{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:s,...e===void 0?{}:{note:e}})},B=async(t,s)=>R("approve",t,s),L=async(t,s)=>R("reject",t,s),U=async()=>{const t=m?.instanceId;u===void 0||t===void 0||await _.mutate({instanceId:t,threadKey:r})},$=()=>{F(),H(),N()};return{approve:B,cancel:U,messages:{subscribe:b.subscribe},reject:L,send:K,status:{subscribe:w.subscribe},streamingText:{subscribe:A.subscribe},teardown:$}};function rt(n,d){const a=J(n),u=a?n:P();return W(u,a?d:n)}export{rt as agentChat};
@@ -1 +1 @@
1
- import{derived as c}from"svelte/store";import{isClient as p}from"./agent-CFzp-ncV.mjs";import{getLunoraClient as f}from"./getLunoraClient-DU7BmZy1.mjs";import{subscription as d}from"./subscription-3foboeMU.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};
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-B1x2xDOl.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};
@@ -1 +1 @@
1
- import{derived as y}from"svelte/store";import{isClient as m}from"./agent-CFzp-ncV.mjs";import{getLunoraClient as I}from"./getLunoraClient-DU7BmZy1.mjs";import{stream as N}from"./stream-eY1eAuVw.mjs";import{subscription as h}from"./subscription-3foboeMU.mjs";const k={__lunoraRef:""},q=t=>{if(t.role==="assistant"&&t.toolCalls)return t.toolCalls.map(l=>({input:l.input,seq:t.seq,toolCallId:l.id,toolName:l.name,type:"call"}));if(t.role==="tool")return t.status==="awaiting_approval"?[{seq:t.seq,type:"awaiting-approval",...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}]:[{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 K(t,l){const n=m(t),a=n?t:I(),u=n?l:t,{api:p,limit:e,stream:i,threadKey:r}=u,s=e===void 0?{key:r}:{key:r,limit:e},{data:c}=h(a,p.agents.agentMessages,s),v=N(a,i??k,i===void 0?"skip":{key:r});return{events:y([c,v.chunks],([f,C])=>{const d=(f??[]).flatMap(o=>q(o)??[]);for(const o of C)o.kind==="progress"&&o.threadKey===r&&d.push({data:o.data,toolCallId:o.toolCallId,type:"progress"});return d})}}export{K as agentToolEvents};
1
+ import{derived as y}from"svelte/store";import{isClient as m}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as I}from"./getLunoraClient-DU7BmZy1.mjs";import{stream as N}from"./stream-DGLI262b.mjs";import{subscription as h}from"./subscription-B1x2xDOl.mjs";const k={__lunoraRef:""},q=t=>{if(t.role==="assistant"&&t.toolCalls)return t.toolCalls.map(l=>({input:l.input,seq:t.seq,toolCallId:l.id,toolName:l.name,type:"call"}));if(t.role==="tool")return t.status==="awaiting_approval"?[{seq:t.seq,type:"awaiting-approval",...t.toolCallId===void 0?{}:{toolCallId:t.toolCallId},...t.toolName===void 0?{}:{toolName:t.toolName}}]:[{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 K(t,l){const n=m(t),a=n?t:I(),u=n?l:t,{api:p,limit:e,stream:i,threadKey:r}=u,s=e===void 0?{key:r}:{key:r,limit:e},{data:c}=h(a,p.agents.agentMessages,s),v=N(a,i??k,i===void 0?"skip":{key:r});return{events:y([c,v.chunks],([f,C])=>{const d=(f??[]).flatMap(o=>q(o)??[]);for(const o of C)o.kind==="progress"&&o.threadKey===r&&d.push({data:o.data,toolCallId:o.toolCallId,type:"progress"});return d})}}export{K as agentToolEvents};
@@ -1 +1 @@
1
- import{readable as l}from"svelte/store";import{i as m}from"./is-browser-BEdfLJHK.mjs";import{isClient as i}from"./agent-CFzp-ncV.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};
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{readable as d}from"svelte/store";import{getLunoraClient as f}from"./getLunoraClient-DU7BmZy1.mjs";const h=(r,o,e={})=>{const n=o??f(),{args:t,functionPath:a,shardKey:s,value:c}=r,i={__lunoraRef:a};return d(c,l=>n.subscribe(i,t,u=>{l(u)},{onError:e.onError,shardKey:s}))};export{h as hydratePreloaded};
@@ -0,0 +1 @@
1
+ import{initialPages as J,derivePaginationStatus as W,applyLoadMore as Y,rebalance as Z}from"@lunora/client/pagination";import{derived as x,writable as B,readable as v,get as L}from"svelte/store";import{getLunoraClient as z}from"./getLunoraClient-DU7BmZy1.mjs";import{i as G}from"./is-function-reference-abFdrAae.mjs";import{i as ee,s as te}from"./subscribe-reactive-args-DYKqoWhw.mjs";const re=/["\\\u0000-\u001F\uD800-\uDFFF]/,q=e=>re.test(e)?JSON.stringify(e):`"${e}"`,D=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(typeof e=="number"){if(Number.isNaN(e))return"nan";if(e===1/0)return"inf";if(e===-1/0)return"-inf";if(Object.is(e,-0))return"-0"}if(typeof e=="string")return q(e);if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e)){let s="[";for(let n=0;n<e.length;n++)n>0&&(s+=","),s+=D(e[n]);return s+"]"}const r=Object.getPrototypeOf(e);if(r!==null&&r!==Object.prototype){const s=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${s} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const a=e,f=Object.keys(a).sort();let o="{",t=!0;for(const s of f){const n=a[s];n!==void 0&&(t?t=!1:o+=",",o+=q(s),o+=":",o+=D(n))}return o+"}"},T=e=>{let r="";for(let f=0;f<e.length;f+=32768)r+=String.fromCharCode(...e.subarray(f,f+32768));return btoa(r)},d="$lunora.wire$",Q=64,ne="__proto__",se=e=>{if(e===null||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype},E=(e,r=0)=>{if(r>Q)throw new RangeError(`wire-codec: value nesting exceeds the ${Q}-level limit`);if(e===void 0)return[d,"undefined"];if(e===null)return null;const a=typeof e;if(a==="bigint")return[d,"bigint",e.toString()];if(a==="number"){const t=e;return Number.isNaN(t)?[d,"nan"]:t===1/0?[d,"inf"]:t===-1/0?[d,"-inf"]:t}if(a!=="object")return e;if(e instanceof Date)return[d,"date",E(e.getTime(),r+1)];if(e instanceof Error){const t=e,s={};for(const g of Object.keys(t))t[g]!==void 0&&(s[g]=E(t[g],r+1));const n=[d,"error",t.name,t.message,s];return t.cause!==void 0&&n.push(E(t.cause,r+1)),n}if(e instanceof URL)return[d,"url",e.href];if(e instanceof Map)return[d,"map",[...e.entries()].map(([t,s])=>[E(t,r+1),E(s,r+1)])];if(e instanceof Set)return[d,"set",[...e].map(t=>E(t,r+1))];if(e instanceof ArrayBuffer)return[d,"bytes",T(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,s=t.constructor.name,n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return s==="Uint8Array"?[d,"bytes",T(n)]:[d,"bytes",T(n),s]}if(Array.isArray(e)){const t=e.map(s=>E(s,r+1));return t.length>0&&t[0]===d?[d,"arr",t]:t}if(!se(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 f=e,o={};for(const t of Object.keys(f)){const s=f[t];if(s===void 0)continue;const n=E(s,r+1);t===ne?Object.defineProperty(o,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):o[t]=n}return o},oe=e=>D(E(e)),_=(e,r)=>({...r,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),K=(e,r)=>`${e}::${oe(r)}`,H=(e,r,a,f)=>{const{initialNumItems:o,onError:t,shardKey:s}=f,n=B(J(o)),g=B(),R=B([]),u=new Map,p=new Map,P=new Set;let c=ee(a)?"skip":a;const A=()=>{if(c==="skip"){R.set([]);return}const l=c,h=L(n).map(k=>{const i=K(r.__lunoraRef,_(k,l));return u.get(i)});R.set(h)},j=(l,h)=>{if(c==="skip")return;const k=c,i=m=>K(r.__lunoraRef,_(m,k));for(const m of h){const y=i(m);if(u.has(y))continue;const M=l.find(w=>w.lower===m.lower);if(M){const w=u.get(i(M));w&&u.set(y,w)}}},C=()=>{if(c==="skip"){for(const i of p.values())i();p.clear(),R.set([]);return}const l=c,h=L(n),k=new Set;for(const i of h)k.add(K(r.__lunoraRef,_(i,l)));for(const[i,m]of p)k.has(i)||(m(),p.delete(i),P.delete(i),u.delete(i));for(const i of h){const m=_(i,l),y=K(r.__lunoraRef,m);if(p.has(y))continue;P.add(y);const M=e.subscribe(r,m,w=>{if(u.set(y,w),P.delete(y),g.set(void 0),A(),P.size===0){const S=L(n),N=Z(S,L(R));N&&(j(S,N),n.set(N),b(),A())}},{onError:w=>{P.delete(y),g.set(w);const S=L(n),N=S.at(-1);S.length>1&&N&&!u.has(y)&&K(r.__lunoraRef,_(N,l))===y&&(n.set(S.slice(0,-1)),b(),A()),t?.(w)},shardKey:s});p.set(y,M)}};let I=!1,O=!1;const b=()=>{if(I){O=!0;return}I=!0;try{do O=!1,C();while(O)}finally{I=!1}},$=()=>{for(const l of p.values())l();p.clear(),u.clear(),P.clear()},F=v([],l=>{const h=R.subscribe(l),k=te(a,i=>(c=i,b(),A(),()=>{$(),n.set(J(o)),g.set(void 0)}));return()=>{k(),h(),R.set([])}}),V=x(F,l=>W(c==="skip",l).status),X=l=>{if(c==="skip")return;const h=L(R),{nextCursor:k,status:i}=W(!1,h);if(i!=="CanLoadMore")return;const m=L(n),y=Y(m,k,l);if(!y)return;const M=m.at(-1),w=y.at(-2);if(M&&w){const S=K(r.__lunoraRef,_(M,c)),N=K(r.__lunoraRef,_(w,c));if(S!==N){const U=u.get(S);U&&(u.set(N,U),u.delete(S))}}g.set(void 0),n.set(y),b(),A()};return{error:{subscribe:g.subscribe},loadMore:X,pageResults:F,status:V}};function le(e,r,a,f){const o=!G(e),t=o?e:z(),s=o?r:e,n=o?a:r,g=o?f:a,{error:R,loadMore:u,pageResults:p,status:P}=H(t,s,n,g),c=x(p,j=>j.flatMap(C=>C?.page??[])),A=x(P,j=>j==="LoadingFirstPage"||j==="LoadingMore");return{error:R,isLoading:A,loadMore:u,results:c,status:P}}function ye(e,r,a,f){const o=!G(e),t=o?e:z(),s=o?r:e,n=o?a:r,g=o?f:a,{initialNumItems:R}=g,{error:u,loadMore:p,pageResults:P,status:c}=H(t,s,n,g),A=x(P,b=>b.flatMap($=>$?[$.page]:[])),j=x(c,b=>b==="LoadingFirstPage"),C=x(c,b=>b==="CanLoadMore"),I=x(c,b=>b==="LoadingMore");return{error:u,fetchNextPage:b=>{p(b??R)},hasNextPage:C,isFetchingNextPage:I,isLoading:j,pages:A,status:c}}export{ye as infiniteQuery,le as paginatedQuery};
@@ -0,0 +1 @@
1
+ import{onDestroy as U}from"svelte";import{readable as C}from"svelte/store";import{i as v}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as D}from"./getLunoraClient-DU7BmZy1.mjs";const I=()=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const t=crypto.getRandomValues(new Uint8Array(16));return Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")}}throw new Error("randomSessionId: no Web Crypto available — a session id needs crypto.randomUUID or crypto.getRandomValues")},w=1e4,E=(t,e,n)=>{const{heartbeat:o,intervalMs:a=w,listPresent:u,shardKey:i}=n,c=n.sessionId??I();let d=n.data;const s=()=>{const r={roomId:e,sessionId:c,...d===void 0?{}:{data:d}};t.mutation(o,r,{shardKey:i}).catch(()=>{})},b=r=>{d=r,s()},l=()=>{typeof document<"u"&&document.visibilityState==="visible"&&s()};let f,y;v()&&(s(),f=setInterval(s,a),typeof document<"u"&&document.addEventListener("visibilitychange",l),y=t.acquireConnectionContext({roomId:e,sessionId:c},{shardKey:i}));const g=C(void 0,r=>{if(v())return t.subscribe(u,{roomId:e},h=>{r(h)},{shardKey:i})});let p=!1;const m=()=>{p||(p=!0,f!==void 0&&clearInterval(f),typeof document<"u"&&document.removeEventListener("visibilitychange",l),y?.())};try{U(m)}catch{}return{present:g,sessionId:c,setData:b,teardown:m}};function A(t,e,n){const o=typeof t!="string",a=o?t:D();return E(a,o?e:t,o?n:e)}export{A as presence};
@@ -0,0 +1 @@
1
+ import{createQuerySubscription as d}from"@lunora/client/query";import{readable as u}from"svelte/store";import{getLunoraClient as b}from"./getLunoraClient-DU7BmZy1.mjs";import{i as v}from"./is-function-reference-abFdrAae.mjs";import{s as y}from"./subscribe-reactive-args-DYKqoWhw.mjs";function K(r,t,i,s){const o=!v(r),a=o?r:b(),c=o?t:r,p=o?i:t,n=(o?s:i)??{};return u(void 0,e=>y(p,f=>(e(void 0),d(a,c,f,{onData:m=>{e(m)},onError:n.onError,onReset:()=>{e(void 0)}},{shardKey:n.shardKey}))))}export{K as query};
@@ -0,0 +1 @@
1
+ import{writable as p,readable as g}from"svelte/store";import{getLunoraClient as R}from"./getLunoraClient-DU7BmZy1.mjs";import{i as B}from"./is-function-reference-abFdrAae.mjs";function j(c,u,l,h){const r=!B(c),v=r?c:R(),w=r?u:c,f=r?l:u,E=(r?h:l)??{},{durable:k,maxBuffer:x,shardKey:y}=E,e=p("idle"),n=p();let s;const b=()=>{s?.()},C=g([],m=>{if(m([]),n.set(void 0),f==="skip")return e.set("idle"),()=>{};e.set("streaming");let o=!0,a=[];const d=v.stream(w,f,{durable:k,maxBuffer:x,shardKey:y}),i=()=>{d.cancel()};return s=i,(async()=>{try{for await(const t of d){if(!o)return;a=[...a,t],m(a)}o&&e.set("complete")}catch(t){if(!o)return;n.set(t instanceof Error?t:new Error(String(t))),e.set("error")}})().catch(()=>{}),()=>{o=!1,i(),s===i&&(s=void 0)}}),S=()=>{b()};return{cancel:b,chunks:C,error:{subscribe:n.subscribe},status:{subscribe:e.subscribe},teardown:S}}export{j as stream};
@@ -0,0 +1 @@
1
+ import{createQuerySubscription as l}from"@lunora/client/query";import{LunoraError as R}from"@lunora/errors";import{writable as w,readable as h}from"svelte/store";import{getLunoraClient as x}from"./getLunoraClient-DU7BmZy1.mjs";import{i as y}from"./is-function-reference-abFdrAae.mjs";import{s as C}from"./subscribe-reactive-args-DYKqoWhw.mjs";function k(t,n,i,c){const r=!y(t),m=r?t:x(),d=r?n:t,p=r?i:n,f=(r?c:i)??{},{shardKey:u,onError:v}=f,e=w();return{data:h(void 0,s=>{const b=C(p,g=>(s(void 0),e.set(void 0),l(m,d,g,{onData:o=>{s(o),e.set(void 0)},onError:o=>{const a=o.code===void 0?new Error(o.message):new R(o.code,o.message);e.set(a),v?.(a)},onReset:()=>{s(void 0)}},{shardKey:u})));return()=>{b(),e.set(void 0)}}),error:{subscribe:e.subscribe}}}export{k as subscription};
@@ -1 +1 @@
1
- import{writable as A,get as I}from"svelte/store";import{isClient as P}from"./agent-CFzp-ncV.mjs";import{getLunoraClient as W}from"./getLunoraClient-DU7BmZy1.mjs";const H=16e3,V=e=>{if(e.length===0)return 0;let o=0;for(const t of e)o+=t*t;return Math.sqrt(o/e.length)},q=(e,o)=>{const t=o/H,i=t>1?Math.floor(e.length/t):e.length,l=new ArrayBuffer(i*2),c=new DataView(l);for(let d=0;d<i;d+=1){const g=e[Math.floor(d*t)]??0,b=Math.max(-1,Math.min(1,g));c.setInt16(d*2,b<0?b*32768:b*32767,!0)}return new Uint8Array(l)},B=async e=>{const o=globalThis,t=o.navigator?.mediaDevices?.getUserMedia.bind(o.navigator.mediaDevices),i=o.AudioContext??o.webkitAudioContext;if(!t||!i)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const l=await t({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),c=new i,d=c.createMediaStreamSource(l),g=c.createScriptProcessor(4096,1,1);let b=!1,S=!1,h=0,r=0;return g.onaudioprocess=a=>{const p=a.inputBuffer.getChannelData(0),f=b?0:V(p);if(e.onLevel(f),b)return;if(e.onAudio(q(p,c.sampleRate)),e.isSpeaking()){r=f>=e.interruptThreshold?r+1:0,r>=e.interruptChunks&&(r=0,e.onInterrupt());return}r=0;const w=p.length/c.sampleRate*1e3;if(f>=e.silenceThreshold){S=!0,h=0;return}S&&(h+=w,h>=e.silenceDurationMs&&(S=!1,h=0,e.onSilence()))},d.connect(g),g.connect(c.destination),{setMuted:a=>{b=a},stop:()=>{g.disconnect(),d.disconnect();for(const a of l.getTracks())a.stop();c.close()}}},$=()=>{const e=globalThis,o=e.AudioContext??e.webkitAudioContext;if(!o)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const t=new o,i=new Set;let l=0,c=Promise.resolve(),d=0;const g=async(h,r)=>{if(r!==d)return;let a;try{a=await t.decodeAudioData(h.buffer)}catch{return}if(r!==d)return;const p=t.createBufferSource();p.buffer=a,p.connect(t.destination);const f=Math.max(t.currentTime,l);p.start(f),l=f+a.duration,i.add(p),p.onended=()=>{i.delete(p)}},b=h=>{const r=Uint8Array.from(h),a=d;c=c.then(()=>g(r,a))},S=()=>{d+=1;for(const h of i)try{h.stop()}catch{}i.clear(),l=t.currentTime};return{enqueue:b,interrupt:S,stop:()=>{S(),t.close()}}},_=1,J=.01,K=1200,O=.15,G=3,j=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,z=e=>{const o=e.__lunoraRef,t=o.startsWith("agents:")?o.slice(7):o;return t.endsWith("Voice")?t.slice(0,-5):t},Q=(e,o,t)=>{const i=j(e),l=i.endsWith("/")?i.slice(0,-1):i,c=new URLSearchParams({threadKey:t});return`${l}/_lunora/voice/${encodeURIComponent(o)}?${c.toString()}`},X=(e,o)=>{const{createMicrophone:t=B,createSpeaker:i=$,createSocket:l,interruptChunks:c=G,interruptThreshold:d=O,silenceDurationMs:g=K,silenceThreshold:b=J,threadKey:S,voice:h}=o,r=A("idle"),a=A(!1),p=A(""),f=A(""),w=A(0),T=A(!1),y=A();let u,C=!1;const E=s=>{const n=u?.socket;return n?.readyState===_?(n.send(JSON.stringify(s)),!0):!1},M=()=>{const s=u;if(u=void 0,s){s.microphone?.stop(),s.speaker?.stop();try{s.socket.close()}catch{}}C=!1,a.set(!1),r.set("idle"),w.set(0)},U=M,L=s=>{const n=u;switch(s.type){case"assistant_delta":{n&&(n.speaking=!0),r.set("speaking"),f.update(k=>k+s.text);break}case"assistant_done":{n&&(n.speaking=!1),f.set(s.text),r.set("listening");break}case"error":{n&&(n.speaking=!1),y.set(new Error(s.message)),r.set("listening");break}case"interrupted":{n&&(n.speaking=!1,n.suppressAudio=!1),n?.speaker?.interrupt(),r.set("listening");break}case"ready":{n&&(n.audioFormat=s.audioFormat,n.suppressAudio=!1),a.set(!0),r.set("listening");break}case"user_transcript":{n&&(n.suppressAudio=!1),p.set(s.text),f.set(""),r.set("thinking");break}}},R=s=>{const n=u;!n||n.suppressAudio||(n.speaker??=i({audioFormat:n.audioFormat}),n.speaking=!0,r.set("speaking"),n.speaker.enqueue(s))},D=async()=>{if(!(u||C)){C=!0,y.set(void 0),p.set(""),f.set("");try{const s=Q(e.url,z(h),S),k=(l??(m=>new globalThis.WebSocket(m)))(s);k.binaryType="arraybuffer";const v={audioFormat:"mp3",microphone:void 0,socket:k,speaker:void 0,speaking:!1,suppressAudio:!1};u=v,k.onmessage=m=>{if(typeof m.data=="string"){try{L(JSON.parse(m.data))}catch{}return}R(new Uint8Array(m.data))},k.onerror=()=>{y.set(new Error("voiceAgent: voice socket error"))},k.onclose=()=>{u===v&&M()};const x=await t({interruptChunks:c,interruptThreshold:d,isSpeaking:()=>u?.speaking??!1,onAudio:m=>{k.readyState===_&&k.send(m)},onInterrupt:()=>{E({type:"interrupt"}),u?.speaker?.interrupt(),u&&(u.speaking=!1,u.suppressAudio=!0),r.set("listening")},onLevel:m=>{w.set(m)},onSilence:()=>{E({type:"commit"}),r.set("thinking")},silenceDurationMs:g,silenceThreshold:b});u===v?(v.microphone=x,T.set(!1),r.set("listening")):x.stop()}catch(s){y.set(s instanceof Error?s:new Error(String(s))),M()}finally{C=!1}}},F=()=>{const s=!I(T);return u?.microphone?.setMuted(s),T.set(s),s},N=s=>{E({text:s,type:"text"})&&r.set("thinking")};return{audioLevel:{subscribe:w.subscribe},connected:{subscribe:a.subscribe},endCall:U,error:{subscribe:y.subscribe},interimTranscript:{subscribe:f.subscribe},isMuted:{subscribe:T.subscribe},sendText:N,startCall:D,status:{subscribe:r.subscribe},toggleMute:F,transcript:{subscribe:p.subscribe}}};function te(e,o){const t=P(e),i=t?e:W();return X(i,t?o:e)}export{te as voiceAgent};
1
+ import{writable as A,get as I}from"svelte/store";import{isClient as P}from"./agent-WMVWf1Ks.mjs";import{getLunoraClient as W}from"./getLunoraClient-DU7BmZy1.mjs";const H=16e3,V=e=>{if(e.length===0)return 0;let o=0;for(const t of e)o+=t*t;return Math.sqrt(o/e.length)},q=(e,o)=>{const t=o/H,i=t>1?Math.floor(e.length/t):e.length,l=new ArrayBuffer(i*2),c=new DataView(l);for(let d=0;d<i;d+=1){const g=e[Math.floor(d*t)]??0,b=Math.max(-1,Math.min(1,g));c.setInt16(d*2,b<0?b*32768:b*32767,!0)}return new Uint8Array(l)},B=async e=>{const o=globalThis,t=o.navigator?.mediaDevices?.getUserMedia.bind(o.navigator.mediaDevices),i=o.AudioContext??o.webkitAudioContext;if(!t||!i)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const l=await t({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),c=new i,d=c.createMediaStreamSource(l),g=c.createScriptProcessor(4096,1,1);let b=!1,S=!1,h=0,r=0;return g.onaudioprocess=a=>{const p=a.inputBuffer.getChannelData(0),f=b?0:V(p);if(e.onLevel(f),b)return;if(e.onAudio(q(p,c.sampleRate)),e.isSpeaking()){r=f>=e.interruptThreshold?r+1:0,r>=e.interruptChunks&&(r=0,e.onInterrupt());return}r=0;const w=p.length/c.sampleRate*1e3;if(f>=e.silenceThreshold){S=!0,h=0;return}S&&(h+=w,h>=e.silenceDurationMs&&(S=!1,h=0,e.onSilence()))},d.connect(g),g.connect(c.destination),{setMuted:a=>{b=a},stop:()=>{g.disconnect(),d.disconnect();for(const a of l.getTracks())a.stop();c.close()}}},$=()=>{const e=globalThis,o=e.AudioContext??e.webkitAudioContext;if(!o)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const t=new o,i=new Set;let l=0,c=Promise.resolve(),d=0;const g=async(h,r)=>{if(r!==d)return;let a;try{a=await t.decodeAudioData(h.buffer)}catch{return}if(r!==d)return;const p=t.createBufferSource();p.buffer=a,p.connect(t.destination);const f=Math.max(t.currentTime,l);p.start(f),l=f+a.duration,i.add(p),p.onended=()=>{i.delete(p)}},b=h=>{const r=Uint8Array.from(h),a=d;c=c.then(()=>g(r,a))},S=()=>{d+=1;for(const h of i)try{h.stop()}catch{}i.clear(),l=t.currentTime};return{enqueue:b,interrupt:S,stop:()=>{S(),t.close()}}},_=1,J=.01,K=1200,O=.15,G=3,j=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,z=e=>{const o=e.__lunoraRef,t=o.startsWith("agents:")?o.slice(7):o;return t.endsWith("Voice")?t.slice(0,-5):t},Q=(e,o,t)=>{const i=j(e),l=i.endsWith("/")?i.slice(0,-1):i,c=new URLSearchParams({threadKey:t});return`${l}/_lunora/voice/${encodeURIComponent(o)}?${c.toString()}`},X=(e,o)=>{const{createMicrophone:t=B,createSpeaker:i=$,createSocket:l,interruptChunks:c=G,interruptThreshold:d=O,silenceDurationMs:g=K,silenceThreshold:b=J,threadKey:S,voice:h}=o,r=A("idle"),a=A(!1),p=A(""),f=A(""),w=A(0),T=A(!1),y=A();let u,C=!1;const E=s=>{const n=u?.socket;return n?.readyState===_?(n.send(JSON.stringify(s)),!0):!1},M=()=>{const s=u;if(u=void 0,s){s.microphone?.stop(),s.speaker?.stop();try{s.socket.close()}catch{}}C=!1,a.set(!1),r.set("idle"),w.set(0)},U=M,L=s=>{const n=u;switch(s.type){case"assistant_delta":{n&&(n.speaking=!0),r.set("speaking"),f.update(k=>k+s.text);break}case"assistant_done":{n&&(n.speaking=!1),f.set(s.text),r.set("listening");break}case"error":{n&&(n.speaking=!1),y.set(new Error(s.message)),r.set("listening");break}case"interrupted":{n&&(n.speaking=!1,n.suppressAudio=!1),n?.speaker?.interrupt(),r.set("listening");break}case"ready":{n&&(n.audioFormat=s.audioFormat,n.suppressAudio=!1),a.set(!0),r.set("listening");break}case"user_transcript":{n&&(n.suppressAudio=!1),p.set(s.text),f.set(""),r.set("thinking");break}}},R=s=>{const n=u;!n||n.suppressAudio||(n.speaker??=i({audioFormat:n.audioFormat}),n.speaking=!0,r.set("speaking"),n.speaker.enqueue(s))},D=async()=>{if(!(u||C)){C=!0,y.set(void 0),p.set(""),f.set("");try{const s=Q(e.url,z(h),S),k=(l??(m=>new globalThis.WebSocket(m)))(s);k.binaryType="arraybuffer";const v={audioFormat:"mp3",microphone:void 0,socket:k,speaker:void 0,speaking:!1,suppressAudio:!1};u=v,k.onmessage=m=>{if(typeof m.data=="string"){try{L(JSON.parse(m.data))}catch{}return}R(new Uint8Array(m.data))},k.onerror=()=>{y.set(new Error("voiceAgent: voice socket error"))},k.onclose=()=>{u===v&&M()};const x=await t({interruptChunks:c,interruptThreshold:d,isSpeaking:()=>u?.speaking??!1,onAudio:m=>{k.readyState===_&&k.send(m)},onInterrupt:()=>{E({type:"interrupt"}),u?.speaker?.interrupt(),u&&(u.speaking=!1,u.suppressAudio=!0),r.set("listening")},onLevel:m=>{w.set(m)},onSilence:()=>{E({type:"commit"}),r.set("thinking")},silenceDurationMs:g,silenceThreshold:b});u===v?(v.microphone=x,T.set(!1),r.set("listening")):x.stop()}catch(s){y.set(s instanceof Error?s:new Error(String(s))),M()}finally{C=!1}}},F=()=>{const s=!I(T);return u?.microphone?.setMuted(s),T.set(s),s},N=s=>{E({text:s,type:"text"})&&r.set("thinking")};return{audioLevel:{subscribe:w.subscribe},connected:{subscribe:a.subscribe},endCall:U,error:{subscribe:y.subscribe},interimTranscript:{subscribe:f.subscribe},isMuted:{subscribe:T.subscribe},sendText:N,startCall:D,status:{subscribe:r.subscribe},toggleMute:F,transcript:{subscribe:p.subscribe}}};function te(e,o){const t=P(e),i=t?e:W();return X(i,t?o:e)}export{te as voiceAgent};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/svelte",
3
- "version": "1.0.0-alpha.105",
3
+ "version": "1.0.0-alpha.106",
4
4
  "description": "Svelte adapter for Lunora — live stores, optimistic mutations, and reactive loaders",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -54,9 +54,9 @@
54
54
  "access": "public"
55
55
  },
56
56
  "dependencies": {
57
- "@lunora/client": "1.0.0-alpha.71",
58
- "@lunora/errors": "1.0.0-alpha.29",
59
- "@lunora/ratelimit": "1.0.0-alpha.35",
57
+ "@lunora/client": "1.0.0-alpha.72",
58
+ "@lunora/errors": "1.0.0-alpha.30",
59
+ "@lunora/ratelimit": "1.0.0-alpha.36",
60
60
  "@visulima/storage-client": "1.0.2"
61
61
  },
62
62
  "peerDependencies": {
@@ -1 +0,0 @@
1
- import{writable as d}from"svelte/store";import{i as R}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as T}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as f}from"./mutation-DLBr5Op1.mjs";const _={__lunoraRef:""},A=t=>typeof t=="object"&&t!==null&&typeof t.subscribe=="function",C=(t,r)=>{const{api:e,cancel:s,run:a,runArgs:m,threadKey:c}=r,i=f(t,a),p=f(t,s??_);let o;const u=d(),b=d(),l=R()?t.subscribe(e.agents.agentThread,{key:c},n=>{o=n,u.set(o),b.set(o?.status)}):()=>{},g=async(n,w)=>{await i.mutate({input:n,threadKey:c,...m,...w})},h=async()=>{const n=o?.instanceId;s===void 0||n===void 0||await p.mutate({instanceId:n,threadKey:c})},y=()=>{l()};return{cancel:h,pending:i.pending,run:g,status:{subscribe:b.subscribe},teardown:y,thread:{subscribe:u.subscribe}}};function N(t,r){const e=A(t),s=e?t:T();return C(s,e?r:t)}export{_ as NO_MUTATION_REF,N as agent,A as isClient};
@@ -1 +0,0 @@
1
- import{reconcileOptimistic as R,maxSeq as k}from"@lunora/client";import{writable as g}from"svelte/store";import{i as f}from"./is-browser-BEdfLJHK.mjs";import{isClient as G,NO_MUTATION_REF as J}from"./agent-CFzp-ncV.mjs";import{getLunoraClient as O}from"./getLunoraClient-DU7BmZy1.mjs";import{mutation as h}from"./mutation-DLBr5Op1.mjs";import{stream as P}from"./stream-eY1eAuVw.mjs";const Q={__lunoraRef:""},V=(n,d)=>{const{api:a,cancel:u,limit:l,send:C,sendArgs:I,stream:v,threadKey:r}=d,E=h(n,C),M=h(n,u??J),_=h(n,a.agents.agentResolveApproval);let m,o=[],i=[],y=[],x=0;const b=g([]),S=g(),w=g(""),p=()=>{const t=R(i,o);if(t.length===0){b.set(o);return}const s=k(o);b.set([...o,...t.map((e,c)=>({content:e.content,optimistic:!0,role:"user",seq:s+1+c}))])},A=()=>{const t=o.filter(e=>e.role==="assistant").length,s=y.filter(e=>e.kind!=="progress"&&e.threadKey===r&&e.turn>=t).map(e=>e.text).join("");w.set(s)},q=v===void 0?"skip":{key:r},j=f()?P(n,v??Q,q).chunks.subscribe(t=>{y=t,A()}):()=>{},N=l===void 0?{key:r}:{key:r,limit:l},D=f()?n.subscribe(a.agents.agentMessages,N,t=>{o=t,p(),A()}):()=>{},F=f()?n.subscribe(a.agents.agentThread,{key:r},t=>{m=t,S.set(m?.status)}):()=>{},H=async(t,s)=>{const e=x;x+=1;const c=k(o);i=[...R(i,o),{content:t,id:e,maxDurableSeqAtSend:c}],p();try{await E.mutate({input:t,threadKey:r,...I,...s})}catch($){throw i=i.filter(z=>z.id!==e),p(),$}},T=async(t,s,e)=>{const c=m?.instanceId;if(c===void 0)throw new Error(`agentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await _.mutate({decision:t,instanceId:c,threadKey:r,toolCallId:s,...e===void 0?{}:{note:e}})},K=async(t,s)=>T("approve",t,s),B=async(t,s)=>T("reject",t,s),L=async()=>{const t=m?.instanceId;u===void 0||t===void 0||await M.mutate({instanceId:t,threadKey:r})},U=()=>{D(),F(),j()};return{approve:K,cancel:L,messages:{subscribe:b.subscribe},reject:B,send:H,status:{subscribe:S.subscribe},streamingText:{subscribe:w.subscribe},teardown:U}};function nt(n,d){const a=G(n),u=a?n:O();return V(u,a?d:n)}export{nt as agentChat};
@@ -1 +0,0 @@
1
- import{readable as u}from"svelte/store";import{getLunoraClient as d}from"./getLunoraClient-DU7BmZy1.mjs";const b=(e,r)=>{const o=r??d(),{args:t,functionPath:n,shardKey:a,value:s}=e,c={__lunoraRef:n};return u(s,i=>o.subscribe(c,t,l=>{i(l)},{shardKey:a}))};export{b as hydratePreloaded};
@@ -1 +0,0 @@
1
- import{initialPages as D,derivePaginationStatus as F,applyLoadMore as H,rebalance as V}from"@lunora/client/pagination";import{derived as E,writable as U,readable as X,get as L}from"svelte/store";import{getLunoraClient as q}from"./getLunoraClient-DU7BmZy1.mjs";import{i as Q}from"./is-function-reference-abFdrAae.mjs";import{i as Y,s as Z}from"./subscribe-reactive-args-DYKqoWhw.mjs";const v=/["\\\u0000-\u001F\uD800-\uDFFF]/,J=e=>v.test(e)?JSON.stringify(e):`"${e}"`,B=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(typeof e=="number"){if(Number.isNaN(e))return"nan";if(e===1/0)return"inf";if(e===-1/0)return"-inf";if(Object.is(e,-0))return"-0"}if(typeof e=="string")return J(e);if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e)){let r="[";for(let s=0;s<e.length;s++)s>0&&(r+=","),r+=B(e[s]);return r+"]"}const n=Object.getPrototypeOf(e);if(n!==null&&n!==Object.prototype){const r=e.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${r} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const a=e,u=Object.keys(a).sort();let o="{",t=!0;for(const r of u){const s=a[r];s!==void 0&&(t?t=!1:o+=",",o+=J(r),o+=":",o+=B(s))}return o+"}"},$=e=>{let n="";for(let u=0;u<e.length;u+=32768)n+=String.fromCharCode(...e.subarray(u,u+32768));return btoa(n)},y="$lunora.wire$",W=64,ee="__proto__",te=e=>{if(e===null||typeof e!="object")return!1;const n=Object.getPrototypeOf(e);return n===null||n===Object.prototype},h=(e,n=0)=>{if(n>W)throw new RangeError(`wire-codec: value nesting exceeds the ${W}-level limit`);if(e===void 0)return[y,"undefined"];if(e===null)return null;const a=typeof e;if(a==="bigint")return[y,"bigint",e.toString()];if(a==="number"){const t=e;return Number.isNaN(t)?[y,"nan"]:t===1/0?[y,"inf"]:t===-1/0?[y,"-inf"]:t}if(a!=="object")return e;if(e instanceof Date)return[y,"date",h(e.getTime(),n+1)];if(e instanceof Error){const t=e,r={};for(const i of Object.keys(t))t[i]!==void 0&&(r[i]=h(t[i],n+1));const s=[y,"error",t.name,t.message,r];return t.cause!==void 0&&s.push(h(t.cause,n+1)),s}if(e instanceof URL)return[y,"url",e.href];if(e instanceof Map)return[y,"map",[...e.entries()].map(([t,r])=>[h(t,n+1),h(r,n+1)])];if(e instanceof Set)return[y,"set",[...e].map(t=>h(t,n+1))];if(e instanceof ArrayBuffer)return[y,"bytes",$(new Uint8Array(e)),"ArrayBuffer"];if(ArrayBuffer.isView(e)){const t=e,r=t.constructor.name,s=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return r==="Uint8Array"?[y,"bytes",$(s)]:[y,"bytes",$(s),r]}if(Array.isArray(e)){const t=e.map(r=>h(r,n+1));return t.length>0&&t[0]===y?[y,"arr",t]:t}if(!te(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 u=e,o={};for(const t of Object.keys(u)){const r=u[t];if(r===void 0)continue;const s=h(r,n+1);t===ee?Object.defineProperty(o,t,{configurable:!0,enumerable:!0,value:s,writable:!0}):o[t]=s}return o},ne=e=>B(h(e)),_=(e,n)=>({...n,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}}),K=(e,n)=>`${e}::${ne(n)}`,z=(e,n,a,u)=>{const{initialNumItems:o,shardKey:t}=u,r=U(D(o)),s=U([]),i=new Map,d=new Map,P=new Set;let f=Y(a)?"skip":a;const b=()=>{if(f==="skip"){s.set([]);return}const l=f,w=L(r).map(R=>{const c=K(n.__lunoraRef,_(R,l));return i.get(c)});s.set(w)},I=(l,w)=>{if(f==="skip")return;const R=f,c=g=>K(n.__lunoraRef,_(g,R));for(const g of w){const p=c(g);if(i.has(p))continue;const N=l.find(k=>k.lower===g.lower);if(N){const k=i.get(c(N));k&&i.set(p,k)}}},S=()=>{if(f==="skip"){for(const c of d.values())c();d.clear(),s.set([]);return}const l=f,w=L(r),R=new Set;for(const c of w)R.add(K(n.__lunoraRef,_(c,l)));for(const[c,g]of d)R.has(c)||(g(),d.delete(c),P.delete(c),i.delete(c));for(const c of w){const g=_(c,l),p=K(n.__lunoraRef,g);if(d.has(p))continue;P.add(p);const N=e.subscribe(n,g,k=>{if(i.set(p,k),P.delete(p),b(),P.size===0){const M=L(r),j=V(M,L(s));j&&(I(M,j),r.set(j),O(),b())}},{shardKey:t});d.set(p,N)}};let A=!1,x=!1;const O=()=>{if(A){x=!0;return}A=!0;try{do x=!1,S();while(x)}finally{A=!1}},m=()=>{for(const l of d.values())l();d.clear(),i.clear(),P.clear()},C=X([],l=>{const w=s.subscribe(l),R=Z(a,c=>(f=c,O(),b(),()=>{m(),r.set(D(o))}));return()=>{R(),w(),s.set([])}}),G=E(C,l=>F(f==="skip",l).status);return{loadMore:l=>{if(f==="skip")return;const w=L(s),{nextCursor:R,status:c}=F(!1,w);if(c!=="CanLoadMore")return;const g=L(r),p=H(g,R,l);if(!p)return;const N=g.at(-1),k=p.at(-2);if(N&&k){const M=K(n.__lunoraRef,_(N,f)),j=K(n.__lunoraRef,_(k,f));if(M!==j){const T=i.get(M);T&&(i.set(j,T),i.delete(M))}}r.set(p),O(),b()},pageResults:C,status:G}};function fe(e,n,a,u){const o=!Q(e),t=o?e:q(),r=o?n:e,s=o?a:n,i=o?u:a,{loadMore:d,pageResults:P,status:f}=z(t,r,s,i),b=E(P,S=>S.flatMap(A=>A?.page??[]));return{isLoading:E(f,S=>S==="LoadingFirstPage"||S==="LoadingMore"),loadMore:d,results:b,status:f}}function ue(e,n,a,u){const o=!Q(e),t=o?e:q(),r=o?n:e,s=o?a:n,i=o?u:a,{initialNumItems:d}=i,{loadMore:P,pageResults:f,status:b}=z(t,r,s,i),I=E(f,m=>m.flatMap(C=>C?[C.page]:[])),S=E(b,m=>m==="LoadingFirstPage"),A=E(b,m=>m==="CanLoadMore"),x=E(b,m=>m==="LoadingMore");return{fetchNextPage:m=>{P(m??d)},hasNextPage:A,isFetchingNextPage:x,isLoading:S,pages:I,status:b}}export{ue as infiniteQuery,fe as paginatedQuery};
@@ -1 +0,0 @@
1
- import{onDestroy as D}from"svelte";import{readable as C}from"svelte/store";import{i as v}from"./is-browser-BEdfLJHK.mjs";import{getLunoraClient as S}from"./getLunoraClient-DU7BmZy1.mjs";const U=()=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const t=crypto.getRandomValues(new Uint8Array(16));return Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")}}return Date.now().toString(36)},w=1e4,E=(t,e,n)=>{const{heartbeat:o,intervalMs:a=w,listPresent:u,shardKey:i}=n,c=n.sessionId??U();let d=n.data;const s=()=>{const r={roomId:e,sessionId:c,...d===void 0?{}:{data:d}};t.mutation(o,r,{shardKey:i}).catch(()=>{})},b=r=>{d=r,s()},l=()=>{typeof document<"u"&&document.visibilityState==="visible"&&s()};let f,y;v()&&(s(),f=setInterval(s,a),typeof document<"u"&&document.addEventListener("visibilitychange",l),y=t.acquireConnectionContext({roomId:e,sessionId:c},{shardKey:i}));const g=C(void 0,r=>{if(v())return t.subscribe(u,{roomId:e},h=>{r(h)},{shardKey:i})});let p=!1;const m=()=>{p||(p=!0,f!==void 0&&clearInterval(f),typeof document<"u"&&document.removeEventListener("visibilitychange",l),y?.())};try{D(m)}catch{}return{present:g,sessionId:c,setData:b,teardown:m}};function V(t,e,n){const o=typeof t!="string",a=o?t:S();return E(a,o?e:t,o?n:e)}export{V as presence};
@@ -1 +0,0 @@
1
- import{createQuerySubscription as d}from"@lunora/client/query";import{readable as u}from"svelte/store";import{getLunoraClient as b}from"./getLunoraClient-DU7BmZy1.mjs";import{i as y}from"./is-function-reference-abFdrAae.mjs";import{s as R}from"./subscribe-reactive-args-DYKqoWhw.mjs";function K(r,e,t,s){const o=!y(r),a=o?r:b(),c=o?e:r,p=o?t:e,i=(o?s:t)??{};return u(void 0,n=>R(p,f=>d(a,c,f,{onData:m=>{n(m)},onError:i.onError,onReset:()=>{n(void 0)}},{shardKey:i.shardKey})))}export{K as query};
@@ -1 +0,0 @@
1
- import{writable as p,readable as S}from"svelte/store";import{getLunoraClient as g}from"./getLunoraClient-DU7BmZy1.mjs";import{i as R}from"./is-function-reference-abFdrAae.mjs";function L(c,u,f,h){const r=!R(c),v=r?c:g(),w=r?u:c,l=r?f:u,E=(r?h:f)??{},{maxBuffer:k,shardKey:x}=E,e=p("idle"),n=p();let s;const b=()=>{s?.()},y=S([],m=>{if(m([]),n.set(void 0),l==="skip")return e.set("idle"),()=>{};e.set("streaming");let o=!0,i=[];const d=v.stream(w,l,{maxBuffer:k,shardKey:x}),a=()=>{d.cancel()};return s=a,(async()=>{try{for await(const t of d){if(!o)return;i=[...i,t],m(i)}o&&e.set("complete")}catch(t){if(!o)return;n.set(t instanceof Error?t:new Error(String(t))),e.set("error")}})().catch(()=>{}),()=>{o=!1,a(),s===a&&(s=void 0)}}),C=()=>{b()};return{cancel:b,chunks:y,error:{subscribe:n.subscribe},status:{subscribe:e.subscribe},teardown:C}}export{L as stream};
@@ -1 +0,0 @@
1
- import{createQuerySubscription as E}from"@lunora/client/query";import{writable as R,readable as g}from"svelte/store";import{getLunoraClient as h}from"./getLunoraClient-DU7BmZy1.mjs";import{i as w}from"./is-function-reference-abFdrAae.mjs";import{s as x}from"./subscribe-reactive-args-DYKqoWhw.mjs";function Q(e,s,n,a){const r=!w(e),p=r?e:h(),m=r?s:e,b=r?n:s,u=(r?a:n)??{},{shardKey:d,onError:f}=u,o=R();return{data:g(void 0,i=>{const v=x(b,l=>(o.set(void 0),E(p,m,l,{onData:t=>{i(t),o.set(void 0)},onError:t=>{const c=new Error(t.message);o.set(c),f?.(c)},onReset:()=>{i(void 0)}},{shardKey:d})));return()=>{v(),o.set(void 0)}}),error:{subscribe:o.subscribe}}}export{Q as subscription};