@lunora/react 1.0.0-alpha.142 → 1.0.0-alpha.144

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.
Files changed (52) hide show
  1. package/dist/index.d.mts +18 -3
  2. package/dist/index.d.ts +18 -3
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_shared/{AuthLoading-ueuPtzle.mjs → AuthLoading-C4peHFqr.mjs} +1 -1
  5. package/dist/packem_shared/LunoraProvider-ycCDFZO7.mjs +1 -0
  6. package/dist/packem_shared/hydratePreloaded-DkalGL_d.mjs +2 -0
  7. package/dist/packem_shared/lunora-provider-Ci1bMLFJ.mjs +2 -0
  8. package/dist/packem_shared/{lunoraQueryOptions-BVgQsR9d.mjs → lunoraQueryOptions-ChMQ9ryB.mjs} +1 -1
  9. package/dist/packem_shared/query-key-B9a-X5-b.mjs +1 -0
  10. package/dist/packem_shared/use-paginated-core-B4VdKLHG.mjs +2 -0
  11. package/dist/packem_shared/useAction-BYfenvCz.mjs +2 -0
  12. package/dist/packem_shared/{useAgent-DtQfMu4S.mjs → useAgent-CcXW5rpk.mjs} +1 -1
  13. package/dist/packem_shared/{useAgentChat-g4ZNMq1B.mjs → useAgentChat-Dfc-9Aej.mjs} +1 -1
  14. package/dist/packem_shared/{useAgentState-BuMYPWb2.mjs → useAgentState-DEqDDLjZ.mjs} +1 -1
  15. package/dist/packem_shared/{useAgentToolEvents-B1ItKmZi.mjs → useAgentToolEvents-Bd9s9VxW.mjs} +1 -1
  16. package/dist/packem_shared/useAuth-B0lB-41L.mjs +2 -0
  17. package/dist/packem_shared/useAuthSessions-DRJa5zcI.mjs +2 -0
  18. package/dist/packem_shared/{useAuthState-A5yrsHUw.mjs → useAuthState-1Dt1VZIp.mjs} +1 -1
  19. package/dist/packem_shared/useClientQuery-C8Oicfpy.mjs +2 -0
  20. package/dist/packem_shared/useConnectionStatus-D2qx1r4Y.mjs +2 -0
  21. package/dist/packem_shared/useFlag-BIwOxn8g.mjs +2 -0
  22. package/dist/packem_shared/useHttpStream-Bd3OlUdw.mjs +2 -0
  23. package/dist/packem_shared/{useInfiniteQuery-BnekI8ek.mjs → useInfiniteQuery-IV6t_BkX.mjs} +1 -1
  24. package/dist/packem_shared/useMutation-BcMP_t-U.mjs +2 -0
  25. package/dist/packem_shared/{usePaginatedQuery-DhjOm3E5.mjs → usePaginatedQuery-o4MfqAwR.mjs} +1 -1
  26. package/dist/packem_shared/usePresence-C6JrSHmL.mjs +2 -0
  27. package/dist/packem_shared/useQuery-BW1a6UaK.mjs +2 -0
  28. package/dist/packem_shared/useStream-sVU3yeXf.mjs +2 -0
  29. package/dist/packem_shared/useSubscription-DqmEF70G.mjs +2 -0
  30. package/dist/packem_shared/useVoiceAgent-LbNGGRqF.mjs +2 -0
  31. package/dist/server.mjs +1 -1
  32. package/package.json +3 -3
  33. package/dist/packem_shared/LunoraProvider-DC06S-p1.mjs +0 -2
  34. package/dist/packem_shared/cache-6yT0tWav.mjs +0 -1
  35. package/dist/packem_shared/hydratePreloaded-CB9ns38y.mjs +0 -2
  36. package/dist/packem_shared/query-key-By_ZIdza.mjs +0 -1
  37. package/dist/packem_shared/stable-key-B_BlboiY.mjs +0 -1
  38. package/dist/packem_shared/use-paginated-core-DHtDp4dj.mjs +0 -2
  39. package/dist/packem_shared/useAction-CUSJu4yq.mjs +0 -2
  40. package/dist/packem_shared/useAuth-BuH3kbVK.mjs +0 -2
  41. package/dist/packem_shared/useAuthSessions-gBDeNFnd.mjs +0 -2
  42. package/dist/packem_shared/useClientQuery-DFs7trEf.mjs +0 -2
  43. package/dist/packem_shared/useConnectionStatus-XYsYGiT6.mjs +0 -2
  44. package/dist/packem_shared/useFlag-BDM923ke.mjs +0 -2
  45. package/dist/packem_shared/useHttpStream-DWtB9sAr.mjs +0 -2
  46. package/dist/packem_shared/useMutation-BnKec7bE.mjs +0 -2
  47. package/dist/packem_shared/usePresence-BVjZyltT.mjs +0 -2
  48. package/dist/packem_shared/useQuery-Dl68EkYb.mjs +0 -2
  49. package/dist/packem_shared/useStream-Cor62Cu-.mjs +0 -2
  50. package/dist/packem_shared/useSubscription-egFPCaGE.mjs +0 -2
  51. package/dist/packem_shared/useVoiceAgent-DHdUlo0G.mjs +0 -2
  52. package/dist/packem_shared/wire-key-p_JEwJ1j.mjs +0 -1
package/dist/index.d.mts CHANGED
@@ -203,9 +203,11 @@ interface ActionHook<F extends FunctionReference> {
203
203
  * stick, and the action would silently fire minutes later on reconnect. `retry`
204
204
  * is pinned to `0` — not inherited from an app-supplied QueryClient — because
205
205
  * `client.action` sends no idempotency key, so a retry after a 502 on an action
206
- * that already ran server-side would run it a second time. A mutation may pause
207
- * and retry safely; it carries a `mutationId` and an offline queue. An action
208
- * carries neither.
206
+ * that already ran server-side would run it a second time. `useMutation` pins
207
+ * both the same way, for a different reason: `client.mutation` queues an
208
+ * offline write itself, and a paused call would never reach that queue (it
209
+ * waits for the network itself only when the client cannot queue). An action
210
+ * has no queue at all, so offline it fails fast.
209
211
  *
210
212
  * **What it deliberately does not carry.** There is no `optimistic` /
211
213
  * `optimisticUpdate` and no `withOptimisticUpdate`, which `useMutation` has. An
@@ -998,6 +1000,12 @@ interface MutationHook<F extends FunctionReference> {
998
1000
  * call options pass straight through to `client.mutation`, which applies and
999
1001
  * rolls them back against the Lunora subscription cache (Convex parity) — not
1000
1002
  * through TanStack's `onMutate`.
1003
+ *
1004
+ * Offline, a write the client can queue reaches `client.mutation` at once,
1005
+ * which queues it (the offline queue or a durable outbox) and paints the
1006
+ * optimistic update. A write it cannot queue (before the shard's first connect,
1007
+ * or with no WebSocket) waits until the browser is online again, then sends.
1008
+ * TanStack never retries; the queue owns replays.
1001
1009
  */
1002
1010
  declare const useMutation: <F extends FunctionReference>(function_: F) => MutationHook<F>;
1003
1011
  interface MutatorHook<TArgs> {
@@ -1043,6 +1051,13 @@ declare const useMutator: <TArgs = Record<string, unknown>>(handle: MutatorHandl
1043
1051
  * Pass `onError` to surface a subscription-scoped error the server pushes (a
1044
1052
  * session expiry, an RLS denial). Without it such an error is dropped and the
1045
1053
  * hook keeps rendering the SSR snapshot as if it were live.
1054
+ *
1055
+ * The preloaded value was read for whoever was signed in when the page loaded.
1056
+ * After a sign-out or user switch retires an identity, every `usePreloadedQuery`
1057
+ * on the client (mounted then or later) stops using it and returns `undefined`
1058
+ * until the live value arrives. A token preloaded after the switch (a client-side
1059
+ * navigation that preloads again) is ignored too and costs a loading flash: the
1060
+ * hook cannot tell which identity a token was read under.
1046
1061
  */
1047
1062
  declare const usePreloadedQuery: <T>(preloaded: Preloaded<T>, options?: {
1048
1063
  onError?: SubscriptionErrorCallback;
package/dist/index.d.ts CHANGED
@@ -203,9 +203,11 @@ interface ActionHook<F extends FunctionReference> {
203
203
  * stick, and the action would silently fire minutes later on reconnect. `retry`
204
204
  * is pinned to `0` — not inherited from an app-supplied QueryClient — because
205
205
  * `client.action` sends no idempotency key, so a retry after a 502 on an action
206
- * that already ran server-side would run it a second time. A mutation may pause
207
- * and retry safely; it carries a `mutationId` and an offline queue. An action
208
- * carries neither.
206
+ * that already ran server-side would run it a second time. `useMutation` pins
207
+ * both the same way, for a different reason: `client.mutation` queues an
208
+ * offline write itself, and a paused call would never reach that queue (it
209
+ * waits for the network itself only when the client cannot queue). An action
210
+ * has no queue at all, so offline it fails fast.
209
211
  *
210
212
  * **What it deliberately does not carry.** There is no `optimistic` /
211
213
  * `optimisticUpdate` and no `withOptimisticUpdate`, which `useMutation` has. An
@@ -998,6 +1000,12 @@ interface MutationHook<F extends FunctionReference> {
998
1000
  * call options pass straight through to `client.mutation`, which applies and
999
1001
  * rolls them back against the Lunora subscription cache (Convex parity) — not
1000
1002
  * through TanStack's `onMutate`.
1003
+ *
1004
+ * Offline, a write the client can queue reaches `client.mutation` at once,
1005
+ * which queues it (the offline queue or a durable outbox) and paints the
1006
+ * optimistic update. A write it cannot queue (before the shard's first connect,
1007
+ * or with no WebSocket) waits until the browser is online again, then sends.
1008
+ * TanStack never retries; the queue owns replays.
1001
1009
  */
1002
1010
  declare const useMutation: <F extends FunctionReference>(function_: F) => MutationHook<F>;
1003
1011
  interface MutatorHook<TArgs> {
@@ -1043,6 +1051,13 @@ declare const useMutator: <TArgs = Record<string, unknown>>(handle: MutatorHandl
1043
1051
  * Pass `onError` to surface a subscription-scoped error the server pushes (a
1044
1052
  * session expiry, an RLS denial). Without it such an error is dropped and the
1045
1053
  * hook keeps rendering the SSR snapshot as if it were live.
1054
+ *
1055
+ * The preloaded value was read for whoever was signed in when the page loaded.
1056
+ * After a sign-out or user switch retires an identity, every `usePreloadedQuery`
1057
+ * on the client (mounted then or later) stops using it and returns `undefined`
1058
+ * until the live value arrives. A token preloaded after the switch (a client-side
1059
+ * navigation that preloads again) is ignored too and costs a loading flash: the
1060
+ * hook cannot tell which identity a token was read under.
1046
1061
  */
1047
1062
  declare const usePreloadedQuery: <T>(preloaded: Preloaded<T>, options?: {
1048
1063
  onError?: SubscriptionErrorCallback;
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{AuthLoading as o,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-ueuPtzle.mjs";import{useAuthState as a}from"./packem_shared/useAuthState-A5yrsHUw.mjs";import{LunoraProvider as n,useLunora as f}from"./packem_shared/LunoraProvider-DC06S-p1.mjs";import{lunoraQueryOptions as m}from"./packem_shared/lunoraQueryOptions-BVgQsR9d.mjs";import{useAction as x}from"./packem_shared/useAction-CUSJu4yq.mjs";import{useAuthSessions as g,useAuthUsers as A,useImpersonate as h,useOrganizations as U,useSignUpInvitations as c}from"./packem_shared/useAuthSessions-gBDeNFnd.mjs";import{useAgent as C}from"./packem_shared/useAgent-DtQfMu4S.mjs";import{useAgentChat as S}from"./packem_shared/useAgentChat-g4ZNMq1B.mjs";import{useAgentState as P}from"./packem_shared/useAgentState-BuMYPWb2.mjs";import{useAgentToolEvents as R}from"./packem_shared/useAgentToolEvents-B1ItKmZi.mjs";import{default as I}from"./packem_shared/useAuth-BuH3kbVK.mjs";import{default as v}from"./packem_shared/useClientQuery-DFs7trEf.mjs";import{default as z}from"./packem_shared/useConnectionStatus-XYsYGiT6.mjs";import{useFlag as T,useFlags as k}from"./packem_shared/useFlag-BDM923ke.mjs";import{useHttpStream as V}from"./packem_shared/useHttpStream-DWtB9sAr.mjs";import{default as q}from"./packem_shared/useInfiniteQuery-BnekI8ek.mjs";import{useMutation as B}from"./packem_shared/useMutation-BnKec7bE.mjs";import{useMutator as G}from"./packem_shared/useMutator-BtUd-xEA.mjs";import{usePaginatedQuery as K}from"./packem_shared/usePaginatedQuery-DhjOm3E5.mjs";import{hydratePreloaded as W,default as X}from"./packem_shared/hydratePreloaded-CB9ns38y.mjs";import{usePresence as Z}from"./packem_shared/usePresence-BVjZyltT.mjs";import{default as $}from"./packem_shared/useQuery-Dl68EkYb.mjs";import{useRateLimit as re}from"./packem_shared/useRateLimit-Cckxi8m9.mjs";import{useStream as te}from"./packem_shared/useStream-Cor62Cu-.mjs";import{default as se}from"./packem_shared/useSubscription-egFPCaGE.mjs";import{useVoiceAgent as pe}from"./packem_shared/useVoiceAgent-DHdUlo0G.mjs";import{createClientQuery as fe,getErrorCode as ie,getRetryAfterMs as me,isConflictError as de,isForbiddenError as xe,isRateLimitedError as le,isUnauthorizedError as ge}from"@lunora/client";import{RestrictionError as he,UploadControl as Ue,UploadError as ce}from"@visulima/storage-client";import{useChunkedRestUpload as Ce,useFileInput as Ee,useMultipartUpload as Se,usePasteUpload as Qe,useTusUpload as Pe,useUpload as Le}from"@visulima/storage-client/react";export{o as AuthLoading,t as Authenticated,n as LunoraProvider,he as RestrictionError,u as Unauthenticated,Ue as UploadControl,ce as UploadError,fe as createClientQuery,ie as getErrorCode,me as getRetryAfterMs,W as hydratePreloaded,de as isConflictError,xe as isForbiddenError,le as isRateLimitedError,ge as isUnauthorizedError,m as lunoraQueryOptions,x as useAction,C as useAgent,S as useAgentChat,P as useAgentState,R as useAgentToolEvents,I as useAuth,g as useAuthSessions,a as useAuthState,A as useAuthUsers,Ce as useChunkedRestUpload,v as useClientQuery,z as useConnectionStatus,Ee as useFileInput,T as useFlag,k as useFlags,V as useHttpStream,h as useImpersonate,q as useInfiniteQuery,f as useLunora,Se as useMultipartUpload,B as useMutation,G as useMutator,U as useOrganizations,K as usePaginatedQuery,Qe as usePasteUpload,X as usePreloadedQuery,Z as usePresence,$ as useQuery,re as useRateLimit,c as useSignUpInvitations,te as useStream,se as useSubscription,Pe as useTusUpload,Le as useUpload,pe as useVoiceAgent};
2
+ import{AuthLoading as o,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-C4peHFqr.mjs";import{useAuthState as a}from"./packem_shared/useAuthState-1Dt1VZIp.mjs";import{L as n,u as f}from"./packem_shared/lunora-provider-Ci1bMLFJ.mjs";import{lunoraQueryOptions as m}from"./packem_shared/lunoraQueryOptions-ChMQ9ryB.mjs";import{useAction as x}from"./packem_shared/useAction-BYfenvCz.mjs";import{useAuthSessions as g,useAuthUsers as A,useImpersonate as h,useOrganizations as U,useSignUpInvitations as c}from"./packem_shared/useAuthSessions-DRJa5zcI.mjs";import{useAgent as C}from"./packem_shared/useAgent-CcXW5rpk.mjs";import{useAgentChat as S}from"./packem_shared/useAgentChat-Dfc-9Aej.mjs";import{useAgentState as L}from"./packem_shared/useAgentState-DEqDDLjZ.mjs";import{useAgentToolEvents as R}from"./packem_shared/useAgentToolEvents-Bd9s9VxW.mjs";import{default as I}from"./packem_shared/useAuth-B0lB-41L.mjs";import{default as v}from"./packem_shared/useClientQuery-C8Oicfpy.mjs";import{default as z}from"./packem_shared/useConnectionStatus-D2qx1r4Y.mjs";import{useFlag as T,useFlags as k}from"./packem_shared/useFlag-BIwOxn8g.mjs";import{useHttpStream as V}from"./packem_shared/useHttpStream-Bd3OlUdw.mjs";import{default as q}from"./packem_shared/useInfiniteQuery-IV6t_BkX.mjs";import{useMutation as B}from"./packem_shared/useMutation-BcMP_t-U.mjs";import{useMutator as G}from"./packem_shared/useMutator-BtUd-xEA.mjs";import{usePaginatedQuery as K}from"./packem_shared/usePaginatedQuery-o4MfqAwR.mjs";import{hydratePreloaded as W,default as X}from"./packem_shared/hydratePreloaded-DkalGL_d.mjs";import{usePresence as Z}from"./packem_shared/usePresence-C6JrSHmL.mjs";import{default as $}from"./packem_shared/useQuery-BW1a6UaK.mjs";import{useRateLimit as re}from"./packem_shared/useRateLimit-Cckxi8m9.mjs";import{useStream as te}from"./packem_shared/useStream-sVU3yeXf.mjs";import{default as se}from"./packem_shared/useSubscription-DqmEF70G.mjs";import{useVoiceAgent as pe}from"./packem_shared/useVoiceAgent-LbNGGRqF.mjs";import{createClientQuery as fe,getErrorCode as ie,getRetryAfterMs as me,isConflictError as de,isForbiddenError as xe,isRateLimitedError as le,isUnauthorizedError as ge}from"@lunora/client";import{RestrictionError as he,UploadControl as Ue,UploadError as ce}from"@visulima/storage-client";import{useChunkedRestUpload as Ce,useFileInput as Ee,useMultipartUpload as Se,usePasteUpload as Qe,useTusUpload as Le,useUpload as Pe}from"@visulima/storage-client/react";export{o as AuthLoading,t as Authenticated,n as LunoraProvider,he as RestrictionError,u as Unauthenticated,Ue as UploadControl,ce as UploadError,fe as createClientQuery,ie as getErrorCode,me as getRetryAfterMs,W as hydratePreloaded,de as isConflictError,xe as isForbiddenError,le as isRateLimitedError,ge as isUnauthorizedError,m as lunoraQueryOptions,x as useAction,C as useAgent,S as useAgentChat,L as useAgentState,R as useAgentToolEvents,I as useAuth,g as useAuthSessions,a as useAuthState,A as useAuthUsers,Ce as useChunkedRestUpload,v as useClientQuery,z as useConnectionStatus,Ee as useFileInput,T as useFlag,k as useFlags,V as useHttpStream,h as useImpersonate,q as useInfiniteQuery,f as useLunora,Se as useMultipartUpload,B as useMutation,G as useMutator,U as useOrganizations,K as usePaginatedQuery,Qe as usePasteUpload,X as usePreloadedQuery,Z as usePresence,$ as useQuery,re as useRateLimit,c as useSignUpInvitations,te as useStream,se as useSubscription,Le as useTusUpload,Pe as useUpload,pe as useVoiceAgent};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{useAuthState as o}from"./useAuthState-A5yrsHUw.mjs";const s=t=>{const{children:n}=t,{isAuthenticated:i}=o();return i?n:void 0},d=t=>{const{children:n}=t,{isAuthenticated:i,isLoading:e}=o();return!e&&!i?n:void 0},r=t=>{const{children:n}=t,{isLoading:i}=o();return i?n:void 0};export{r as AuthLoading,s as Authenticated,d as Unauthenticated};
2
+ import{useAuthState as o}from"./useAuthState-1Dt1VZIp.mjs";const s=t=>{const{children:n}=t,{isAuthenticated:i}=o();return i?n:void 0},d=t=>{const{children:n}=t,{isAuthenticated:i,isLoading:e}=o();return!e&&!i?n:void 0},r=t=>{const{children:n}=t,{isLoading:i}=o();return i?n:void 0};export{r as AuthLoading,s as Authenticated,d as Unauthenticated};
@@ -0,0 +1 @@
1
+ import{L as a,u}from"./lunora-provider-Ci1bMLFJ.mjs";export{a as LunoraProvider,u as useLunora};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as R}from"react/compiler-runtime";import{useQueryClient as S,useQuery as q}from"@tanstack/react-query";import{useRef as K,useEffect as _,useSyncExternalStore as P}from"react";import{u as N,g as T}from"./lunora-provider-Ci1bMLFJ.mjs";import{l as x,a as C}from"./query-key-B9a-X5-b.mjs";const F=function(o,r){const e=R(9);let n;e[0]!==r?(n=r===void 0?{}:r,e[0]=r,e[1]=n):n=e[1];const s=n,t=N(),i=S(),p=K(s.onError);let c;e[2]!==s.onError?(c=()=>{p.current=s.onError},e[2]=s.onError,e[3]=c):c=e[3],_(c);let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=Q=>{p.current?.(Q)},e[4]=u):u=e[4];const h=u,l=T(t),g=P(l.subscribeIdentityEpoch,l.identityEpoch,O),{args:f,functionPath:v,shardKey:y}=o,b=g===0?o.value:void 0,m={__lunoraRef:v},E=x(m,f,y),{data:I}=q({initialData:b,queryFn:()=>t.query(m,f,{shardKey:y}),queryKey:E,staleTime:Number.POSITIVE_INFINITY}),d=C(E);let a;return e[5]!==t||e[6]!==i||e[7]!==d?(a=[t,i,d,h],e[5]=t,e[6]=i,e[7]=d,e[8]=a):a=e[8],_(()=>l.attach(i,E,m,f,y,{onError:h}),a),I===void 0?b:I},$=function(o,r={}){return F(o,r)};function O(){return 0}export{F as default,$ as hydratePreloaded};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as k}from"react/compiler-runtime";import{LunoraError as I}from"@lunora/errors";import{QueryClientContext as S,QueryClientProvider as w,QueryClient as v}from"@tanstack/react-query";import{use as m,useState as L,useEffect as Q,createContext as E}from"react";import{k as y}from"./query-key-B9a-X5-b.mjs";import{jsx as p}from"react/jsx-runtime";const C=r=>{r!==void 0&&(r.cancel({silent:!0}),r.setState({...r.state,data:void 0,dataUpdatedAt:0,error:null,fetchStatus:"idle",status:"pending"}))};class x{constructor(e){this.client=e}client;entries=new Map;pushes=new Map;samples=new Map;epoch=0;identityWatched=new Set;listening=!1;keyOf(e){return y(e)}hasConsumers(e){return this.entries.has(y(e))}openSnapshotSample(e){const t=y(e);return this.samples.set(t,(this.samples.get(t)??0)+1),{key:t,pushes:this.pushes.get(t)??0}}closeSnapshotSample(e){const t=(this.samples.get(e.key)??1)-1,s=(this.pushes.get(e.key)??0)===e.pushes;return t>0?(this.samples.set(e.key,t),s):(this.samples.delete(e.key),this.entries.has(e.key)||this.pushes.delete(e.key),s)}clearOnIdentityChange(e){this.listenForIdentityChange(),this.identityWatched.add(e)}identityEpoch=()=>this.epoch;subscribeIdentityEpoch=e=>(this.listenForIdentityChange(),this.client.onIdentityChange(e));listenForIdentityChange(){this.listening||(this.listening=!0,this.client.onIdentityChange(()=>{this.epoch+=1;for(const e of this.identityWatched){const t=e.getQueryCache();for(const s of t.findAll({queryKey:["lunora"]}))C(s),s.getObserversCount()===0&&!this.hasConsumers(s.queryKey)&&t.remove(s)}}))}attach(e,t,s,h,c,d={}){const a=y(t);let n=this.entries.get(a);if(!n){n={errorCallbacks:new Set,refCount:0,unsubscribe:void 0},this.entries.set(a,n);const i=n;try{n.unsubscribe=this.client.subscribe(s,h,o=>{if(this.pushes.set(a,(this.pushes.get(a)??0)+1),o===void 0){C(e.getQueryCache().find({exact:!0,queryKey:t}));return}e.setQueryData(t,o)},{onError:o=>{for(const f of i.errorCallbacks)f(o)},shardKey:c})}catch(o){throw this.entries.delete(a),o}}n.refCount+=1;const{onError:u}=d;u&&n.errorCallbacks.add(u);let l=!1;return()=>{if(l)return;l=!0;const i=this.entries.get(a);i&&(i.refCount-=1,u&&i.errorCallbacks.delete(u),i.refCount<=0&&(i.unsubscribe?.(),this.entries.delete(a)))}}}const g=new WeakMap,O=r=>{let e=g.get(r);return e||(e=new x(r),g.set(r,e)),e},b=E(null),N=()=>new v({defaultOptions:{mutations:{retry:0},queries:{gcTime:5*6e4,retry:0,staleTime:Number.POSITIVE_INFINITY}}}),R=r=>{const e=k(13),{children:t,client:s,queryClient:h}=r,c=m(S);let d;e[0]!==c||e[1]!==h?(d=()=>h??c??N(),e[0]=c,e[1]=h,e[2]=d):d=e[2];const[a]=L(d),n=h??c??a;let u,l;e[3]!==s||e[4]!==n?(u=()=>{O(s).clearOnIdentityChange(n)},l=[s,n],e[3]=s,e[4]=n,e[5]=u,e[6]=l):(u=e[5],l=e[6]),Q(u,l);let i;e[7]!==t||e[8]!==s?(i=p(b,{value:s,children:t}),e[7]=t,e[8]=s,e[9]=i):i=e[9];const o=i;if(c===n)return o;let f;return e[10]!==o||e[11]!==n?(f=p(w,{client:n,children:o}),e[10]=o,e[11]=n,e[12]=f):f=e[12],f},D=()=>{const r=m(b);if(!r)throw new I("INTERNAL","useLunora must be used inside <LunoraProvider />");return r};export{R as L,O as g,D as u};
@@ -1 +1 @@
1
- import{l as u}from"./query-key-By_ZIdza.mjs";const t=(a,r,s,e={})=>{const y=s??{};return{queryFn:()=>a.query(r,y,{shardKey:e.shardKey}),queryKey:u(r,y,e.shardKey),staleTime:Number.POSITIVE_INFINITY}};export{t as lunoraQueryOptions};
1
+ import{l as u}from"./query-key-B9a-X5-b.mjs";const t=(a,r,s,e={})=>{const y=s??{};return{queryFn:()=>a.query(r,y,{shardKey:e.shardKey}),queryKey:u(r,y,e.shardKey),staleTime:Number.POSITIVE_INFINITY}};export{t as lunoraQueryOptions};
@@ -0,0 +1 @@
1
+ const l=/["\\\u0000-\u001F\uD800-\uDFFF]/,d=r=>l.test(r)?JSON.stringify(r):`"${r}"`,b=r=>{if(r===void 0)return"null";if(typeof r=="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 r=="number"){if(Number.isNaN(r))return"nan";if(r===1/0)return"inf";if(r===-1/0)return"-inf";if(Object.is(r,-0))return"-0"}if(typeof r=="string")return d(r);if(r===null||typeof r!="object")return JSON.stringify(r);if(Array.isArray(r)){let e="[";for(let i=0;i<r.length;i++)i>0&&(e+=","),e+=b(r[i]);return e+"]"}const n=Object.getPrototypeOf(r);if(n!==null&&n!==Object.prototype){const e=r.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${e} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const s=r,c=Object.keys(s).sort();let f="{",t=!0;for(const e of c){const i=s[e];i!==void 0&&(t?t=!1:f+=",",f+=d(e),f+=":",f+=b(i))}return f+"}"},u=r=>{let n="";for(let c=0;c<r.length;c+=32768)n+=String.fromCharCode(...r.subarray(c,c+32768));return btoa(n)},o="$lunora.wire$";const g="__proto__",m=r=>{if(r===null||typeof r!="object")return!1;const n=Object.getPrototypeOf(r);return n===null||n===Object.prototype},a=(r,n=0)=>{if(n>64)throw new RangeError("wire-codec: value nesting exceeds the 64-level limit");if(r===void 0)return[o,"undefined"];if(r===null)return null;const s=typeof r;if(s==="bigint")return[o,"bigint",r.toString()];if(s==="number"){const t=r;return Number.isNaN(t)?[o,"nan"]:t===1/0?[o,"inf"]:t===-1/0?[o,"-inf"]:t}if(s!=="object")return r;if(r instanceof Date)return[o,"date",a(r.getTime(),n+1)];if(r instanceof Error){const t=r,e={};for(const y of Object.keys(t)){if(t[y]===void 0)continue;const p=a(t[y],n+1);y===g?Object.defineProperty(e,y,{configurable:!0,enumerable:!0,value:p,writable:!0}):e[y]=p}const i=[o,"error",String(t.name),String(t.message),e];return t.cause!==void 0&&i.push(a(t.cause,n+1)),i}if(r instanceof URL)return[o,"url",r.href];if(r instanceof Map)return[o,"map",[...r.entries()].map(([t,e])=>[a(t,n+1),a(e,n+1)])];if(r instanceof Set)return[o,"set",[...r].map(t=>a(t,n+1))];if(r instanceof ArrayBuffer)return[o,"bytes",u(new Uint8Array(r)),"ArrayBuffer"];if(ArrayBuffer.isView(r)){const t=r,e=t.constructor.name,i=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);return e==="Uint8Array"?[o,"bytes",u(i)]:[o,"bytes",u(i),e]}if(Array.isArray(r)){const t=r.map(e=>a(e,n+1));return t.length>0&&t[0]===o?[o,"arr",t]:t}if(!m(r)){const t=r.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 c=r,f={};for(const t of Object.keys(c)){const e=c[t];if(e===void 0)continue;const i=a(e,n+1);t===g?Object.defineProperty(f,t,{configurable:!0,enumerable:!0,value:i,writable:!0}):f[t]=i}return f},w=r=>b(a(r)),O=r=>w(r),A=(r,n,s)=>["lunora",r.__lunoraRef,n,s??null],S=r=>O(r);export{S as a,b,O as k,A as l,w as s};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{initialPages as O,rebalance as Y,derivePaginationStatus as T,applyLoadMore as _}from"@lunora/client/pagination";import{useQueryClient as B,CancelledError as G}from"@tanstack/react-query";import{useRef as p,useReducer as J,useState as z,useEffect as d,useCallback as U}from"react";import{u as W,g as X}from"./lunora-provider-Ci1bMLFJ.mjs";import{a as u,l as S}from"./query-key-B9a-X5-b.mjs";const Z=function(i){const l=p(void 0);return l.current??=i(),l},oe=function(i,l,R){const y=W(),o=B(),{initialNumItems:Q,shardKey:g}=R,f=l==="skip",k=f?{}:l,[,$]=J(e=>e+1,0),[P,K]=z(()=>O(Q)),[j,C]=z(void 0),A=p(R.onError);d(()=>{A.current=R.onError});const E=`${u(S(i,k,g))}::${String(Q)}`,x=p(E);x.current!==E&&(x.current=E,K(O(Q)),C(void 0));const b=P.map(e=>{const r={...k,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}},t=S(i,r,g);return{args:r,key:t}}),D=b.map(({key:e})=>u(e)).join("|"),v=p({baseArgs:k,entries:[],fn:i,shardKey:g});d(()=>{v.current={baseArgs:k,entries:b,fn:i,shardKey:g}});const F=(e,r,t)=>{C(t),K(a=>{const s=v.current,n=a.at(-1);if(a.length<=1||!n||o.getQueryData(r)!==void 0)return a;const m={...s.baseArgs,paginationOpts:{cursor:n.lower,endCursor:n.upper,numItems:n.numItems}};return u(S(s.fn,m,s.shardKey))===e?a.slice(0,-1):a}),A.current?.(t)},q=Z(()=>new Map),L=p(y);d(()=>{const e=q.current;if(L.current!==y){for(const s of e.values())s();e.clear(),L.current=y}if(f){for(const s of e.values())s();e.clear();return}const r=v.current,t=X(y),a=new Set(r.entries.map(({key:s})=>u(s)));for(const[s,n]of e)a.has(s)||(n(),e.delete(s));for(const s of r.entries){const n=u(s.key);if(e.has(n))continue;const m=()=>{o.fetchQuery({gcTime:Number.POSITIVE_INFINITY,queryFn:async()=>{const c=t.openSnapshotSample(s.key),N=await y.query(r.fn,s.args,{shardKey:r.shardKey});return t.closeSnapshotSample(c)?N:o.getQueryData(s.key)??N},queryKey:s.key,staleTime:0}).catch(c=>{if(c instanceof G){t.hasConsumers(s.key)&&m();return}F(n,s.key,c instanceof Error?{code:c.code,message:c.message}:{message:String(c)})})};m();const h=t.attach(o,s.key,r.fn,s.args,r.shardKey,{onError:M=>{F(n,s.key,M)}}),I=s.key;e.set(n,()=>{h(),t.hasConsumers(I)||o.removeQueries({exact:!0,queryKey:I})})}},[y,o,D,f]),d(()=>()=>{for(const e of q.current.values())e();q.current.clear()},[]),d(()=>o.getQueryCache().subscribe(t=>{if(t.type!=="updated")return;const a=u(t.query.queryKey);b.some(({key:s})=>u(s)===a)&&(C(void 0),$())}),[o,D]);const w=f?[]:b.map(({key:e})=>o.getQueryData(e));d(()=>{if(f)return;const e=Y(P,w);e&&K(e)});const{status:H}=T(f,w),V=U(e=>{C(void 0),K(r=>{const t=v.current,a=r.map(h=>{const I={...t.baseArgs,paginationOpts:{cursor:h.lower,endCursor:h.upper,numItems:h.numItems}};return o.getQueryData(S(t.fn,I,t.shardKey))}),{nextCursor:s,status:n}=T(!1,a);return _(r,n==="CanLoadMore"?s:void 0,e)??r})},[o]);return{error:j,loadMore:V,pageResults:w,status:H}};export{oe as u};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as R}from"react/compiler-runtime";import{createCallRunner as k}from"@lunora/client";import{useMutation as x}from"@tanstack/react-query";import{useState as n}from"react";import{u as C}from"./lunora-provider-Ci1bMLFJ.mjs";const S=a=>{const t=R(12),i=C(),[c,g]=n(void 0),[l,m]=n(void 0),[u,M]=n(!1);let o;t[0]!==i||t[1]!==a?(o={mutationFn:async e=>{const{args:y,options:A}=e;return i.action(a,y,A)},networkMode:"always",retry:0},t[0]=i,t[1]=a,t[2]=o):o=t[2];const{mutateAsync:d,reset:p}=x(o);let s;t[3]!==d||t[4]!==p?(s=()=>({call:k(async(e,y)=>d({args:e,options:y}),{setError:m,setPending:M,setResult:e=>{g(()=>e),m(void 0)}}),reset:()=>{g(void 0),m(void 0),p()}}),t[3]=d,t[4]=p,t[5]=s):s=t[5];const[w]=n(s),{call:f,reset:v}=w;let r;return t[6]!==f||t[7]!==c||t[8]!==l||t[9]!==u||t[10]!==v?(r={call:f,data:c,error:l,pending:u,reset:v},t[6]=f,t[7]=c,t[8]=l,t[9]=u,t[10]=v,t[11]=r):r=t[11],r};export{S as useAction};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as N}from"react/compiler-runtime";import{useMutation as R}from"./useMutation-BnKec7bE.mjs";import O from"./useSubscription-egFPCaGE.mjs";const b={__lunoraRef:""},F=_=>{const t=N(20),{api:A,cancel:a,onError:d,run:I,runArgs:f,threadKey:e}=_,s=R(I),T=R(a??b);let c;t[0]!==e?(c={key:e},t[0]=e,t[1]=c):c=t[1];let r;t[2]!==d?(r={onError:d},t[2]=d,t[3]=r):r=t[3];const{data:v,error:p}=O(A.agents.agentThread,c,r),n=v,g=n?.status,o=n?.instanceId,{mutate:m}=s,{mutate:M}=T;let i;t[4]!==f||t[5]!==m||t[6]!==e?(i=async(w,E)=>{await m({input:w,threadKey:e,...f,...E})},t[4]=f,t[5]=m,t[6]=e,t[7]=i):i=t[7];const h=i;let u;t[8]!==M||t[9]!==a||t[10]!==o||t[11]!==e?(u=async()=>{a===void 0||o===void 0||await M({instanceId:o,threadKey:e})},t[8]=M,t[9]=a,t[10]=o,t[11]=e,t[12]=u):u=t[12];const y=u;let l;return t[13]!==y||t[14]!==p||t[15]!==h||t[16]!==s.pending||t[17]!==g||t[18]!==n?(l={cancel:y,error:p,pending:s.pending,run:h,status:g,thread:n},t[13]=y,t[14]=p,t[15]=h,t[16]=s.pending,t[17]=g,t[18]=n,t[19]=l):l=t[19],l};export{F as useAgent};
2
+ import{c as N}from"react/compiler-runtime";import{useMutation as R}from"./useMutation-BcMP_t-U.mjs";import O from"./useSubscription-DqmEF70G.mjs";const b={__lunoraRef:""},F=_=>{const t=N(20),{api:A,cancel:a,onError:d,run:I,runArgs:f,threadKey:e}=_,s=R(I),T=R(a??b);let c;t[0]!==e?(c={key:e},t[0]=e,t[1]=c):c=t[1];let r;t[2]!==d?(r={onError:d},t[2]=d,t[3]=r):r=t[3];const{data:v,error:p}=O(A.agents.agentThread,c,r),n=v,g=n?.status,o=n?.instanceId,{mutate:m}=s,{mutate:M}=T;let i;t[4]!==f||t[5]!==m||t[6]!==e?(i=async(w,E)=>{await m({input:w,threadKey:e,...f,...E})},t[4]=f,t[5]=m,t[6]=e,t[7]=i):i=t[7];const h=i;let u;t[8]!==M||t[9]!==a||t[10]!==o||t[11]!==e?(u=async()=>{a===void 0||o===void 0||await M({instanceId:o,threadKey:e})},t[8]=M,t[9]=a,t[10]=o,t[11]=e,t[12]=u):u=t[12];const y=u;let l;return t[13]!==y||t[14]!==p||t[15]!==h||t[16]!==s.pending||t[17]!==g||t[18]!==n?(l={cancel:y,error:p,pending:s.pending,run:h,status:g,thread:n},t[13]=y,t[14]=p,t[15]=h,t[16]=s.pending,t[17]=g,t[18]=n,t[19]=l):l=t[19],l};export{F as useAgent};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{reconcileOptimistic as M,maxSeq as R}from"@lunora/client";import{useState as Q,useRef as S}from"react";import{useMutation as u}from"./useMutation-BnKec7bE.mjs";import{useStream as V}from"./useStream-Cor62Cu-.mjs";import A from"./useSubscription-egFPCaGE.mjs";const W={__lunoraRef:""},X={__lunoraRef:""},Z=[],it=E=>{const{api:a,cancel:m,limit:d,onError:l,send:_,sendArgs:k,stream:p,threadKey:e}=E,x=d===void 0?{key:e}:{key:e,limit:d},{data:w,error:O}=A(a.agents.agentMessages,x,{onError:l}),{data:T,error:b}=A(a.agents.agentThread,{key:e},{onError:l}),I=p===void 0?"skip":{key:e},{chunks:j}=V(p??X,I),q=u(_),C=u(m??W),D=u(a.agents.agentResolveApproval),[K,c]=Q([]),f=S(0),h=S(e);h.current!==e&&(h.current=e,c([]));const g=T,N=g?.status,o=g?.instanceId,s=w??Z,v=M(K,s),F=R(s),G=v.length===0?s:[...s,...v.map((t,n)=>({content:t.content,optimistic:!0,role:"user",seq:F+1+n}))],P=s.filter(t=>t.role==="assistant").length,U=j.filter(t=>t.kind!=="progress"&&t.threadKey===e&&t.turn>=P).map(t=>t.text).join(""),{mutate:Y}=q,{mutate:$}=C,{mutate:z}=D,B=async(t,n)=>{const r=f.current;f.current+=1;const H=R(s);c(i=>[...M(i,s),{content:t,id:r,maxDurableSeqAtSend:H}]);try{await Y({input:t,threadKey:e,...k,...n})}catch(i){throw c(J=>J.filter(L=>L.id!==r)),i}},y=async(t,n,r)=>{if(o===void 0)throw new Error(`useAgentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await z({decision:t,instanceId:o,threadKey:e,toolCallId:n,...r===void 0?{}:{note:r}})};return{approve:(t,n)=>y("approve",t,n),cancel:async()=>{m===void 0||o===void 0||await $({instanceId:o,threadKey:e})},error:O??b,messages:G,reject:(t,n)=>y("reject",t,n),send:B,status:N,streamingText:U}};export{it as useAgentChat};
2
+ import{reconcileOptimistic as M,maxSeq as R}from"@lunora/client";import{useState as Q,useRef as S}from"react";import{useMutation as u}from"./useMutation-BcMP_t-U.mjs";import{useStream as V}from"./useStream-sVU3yeXf.mjs";import A from"./useSubscription-DqmEF70G.mjs";const W={__lunoraRef:""},X={__lunoraRef:""},Z=[],it=E=>{const{api:a,cancel:m,limit:d,onError:l,send:_,sendArgs:k,stream:p,threadKey:e}=E,x=d===void 0?{key:e}:{key:e,limit:d},{data:w,error:O}=A(a.agents.agentMessages,x,{onError:l}),{data:T,error:b}=A(a.agents.agentThread,{key:e},{onError:l}),I=p===void 0?"skip":{key:e},{chunks:j}=V(p??X,I),q=u(_),C=u(m??W),D=u(a.agents.agentResolveApproval),[K,c]=Q([]),f=S(0),h=S(e);h.current!==e&&(h.current=e,c([]));const g=T,N=g?.status,o=g?.instanceId,s=w??Z,v=M(K,s),F=R(s),G=v.length===0?s:[...s,...v.map((t,n)=>({content:t.content,optimistic:!0,role:"user",seq:F+1+n}))],P=s.filter(t=>t.role==="assistant").length,U=j.filter(t=>t.kind!=="progress"&&t.threadKey===e&&t.turn>=P).map(t=>t.text).join(""),{mutate:Y}=q,{mutate:$}=C,{mutate:z}=D,B=async(t,n)=>{const r=f.current;f.current+=1;const H=R(s);c(i=>[...M(i,s),{content:t,id:r,maxDurableSeqAtSend:H}]);try{await Y({input:t,threadKey:e,...k,...n})}catch(i){throw c(J=>J.filter(L=>L.id!==r)),i}},y=async(t,n,r)=>{if(o===void 0)throw new Error(`useAgentChat: cannot ${t} — no in-flight run (thread has no instanceId)`);await z({decision:t,instanceId:o,threadKey:e,toolCallId:n,...r===void 0?{}:{note:r}})};return{approve:(t,n)=>y("approve",t,n),cancel:async()=>{m===void 0||o===void 0||await $({instanceId:o,threadKey:e})},error:O??b,messages:G,reject:(t,n)=>y("reject",t,n),send:B,status:N,streamingText:U}};export{it as useAgentChat};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as o}from"react/compiler-runtime";import d from"./useSubscription-egFPCaGE.mjs";const l=t=>{const e=o(5);let r;e[0]!==t.threadKey?(r={key:t.threadKey},e[0]=t.threadKey,e[1]=r):r=e[1];const{data:n,error:s}=d(t.api.agents.agentState,r),c=n;let a;return e[2]!==s||e[3]!==c?(a={error:s,state:c},e[2]=s,e[3]=c,e[4]=a):a=e[4],a};export{l as useAgentState};
2
+ import{c as o}from"react/compiler-runtime";import d from"./useSubscription-DqmEF70G.mjs";const l=t=>{const e=o(5);let r;e[0]!==t.threadKey?(r={key:t.threadKey},e[0]=t.threadKey,e[1]=r):r=e[1];const{data:n,error:s}=d(t.api.agents.agentState,r),c=n;let a;return e[2]!==s||e[3]!==c?(a={error:s,state:c},e[2]=s,e[3]=c,e[4]=a):a=e[4],a};export{l as useAgentState};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as y}from"react/compiler-runtime";import{useStream as I}from"./useStream-Cor62Cu-.mjs";import N from"./useSubscription-egFPCaGE.mjs";const E={__lunoraRef:""},_=[],k=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}}]},A=o=>{const t=y(12),{api:c,limit:r,stream:n,threadKey:l}=o;let a;t[0]!==r||t[1]!==l?(a=r===void 0?{key:l}:{key:l,limit:r},t[0]=r,t[1]=l,t[2]=a):a=t[2];const f=a,{data:v}=N(c.agents.agentMessages,f);let i;t[3]!==n||t[4]!==l?(i=n===void 0?"skip":{key:l},t[3]=n,t[4]=l,t[5]=i):i=t[5];const C=i,{chunks:p}=I(n??E,C),s=v??_;let e;if(t[6]!==p||t[7]!==s||t[8]!==l){e=s.flatMap(q);for(const d of p)d.kind==="progress"&&d.threadKey===l&&e.push({data:d.data,toolCallId:d.toolCallId,type:"progress"});t[6]=p,t[7]=s,t[8]=l,t[9]=e}else e=t[9];let u;return t[10]!==e?(u={events:e},t[10]=e,t[11]=u):u=t[11],u};function q(o){return k(o)??[]}export{A as useAgentToolEvents};
2
+ import{c as y}from"react/compiler-runtime";import{useStream as I}from"./useStream-sVU3yeXf.mjs";import N from"./useSubscription-DqmEF70G.mjs";const E={__lunoraRef:""},_=[],k=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}}]},A=o=>{const t=y(12),{api:c,limit:r,stream:n,threadKey:l}=o;let a;t[0]!==r||t[1]!==l?(a=r===void 0?{key:l}:{key:l,limit:r},t[0]=r,t[1]=l,t[2]=a):a=t[2];const f=a,{data:v}=N(c.agents.agentMessages,f);let i;t[3]!==n||t[4]!==l?(i=n===void 0?"skip":{key:l},t[3]=n,t[4]=l,t[5]=i):i=t[5];const C=i,{chunks:p}=I(n??E,C),s=v??_;let e;if(t[6]!==p||t[7]!==s||t[8]!==l){e=s.flatMap(q);for(const d of p)d.kind==="progress"&&d.threadKey===l&&e.push({data:d.data,toolCallId:d.toolCallId,type:"progress"});t[6]=p,t[7]=s,t[8]=l,t[9]=e}else e=t[9];let u;return t[10]!==e?(u={events:e},t[10]=e,t[11]=u):u=t[11],u};function q(o){return k(o)??[]}export{A as useAgentToolEvents};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as h}from"react/compiler-runtime";import{getIdentityStore as k}from"@lunora/client/auth";import{useSyncExternalStore as p}from"react";import{u as A}from"./lunora-provider-Ci1bMLFJ.mjs";const _=()=>{const t=h(13),e=A();let o;t[0]!==e?(o=k(e),t[0]=e,t[1]=o):o=t[1];const n=o;let s,r,u;t[2]!==e?(s=g=>e.onAuthTokenChange(g),r=()=>e.getAuthToken(),u=()=>e.getAuthToken(),t[2]=e,t[3]=s,t[4]=r,t[5]=u):(s=t[3],r=t[4],u=t[5]);const i=p(s,r,u),f=p(n.subscribe,n.getUser,T),m=p(n.subscribe,n.getStatus,b);let l;t[6]!==e?(l=g=>{e.setAuthToken(g)},t[6]=e,t[7]=l):l=t[7];const a=l;let c;return t[8]!==a||t[9]!==m||t[10]!==i||t[11]!==f?(c={setToken:a,status:m,token:i,user:f},t[8]=a,t[9]=m,t[10]=i,t[11]=f,t[12]=c):c=t[12],c};function T(){return null}function b(){return"loading"}export{_ as default};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as A}from"react/compiler-runtime";import{useMutation as y,useQuery as z,keepPreviousData as I}from"@tanstack/react-query";import{useState as _,useSyncExternalStore as b}from"react";import{u as S}from"./lunora-provider-Ci1bMLFJ.mjs";const U="lunora-react-admin-auth",D=50;function v(t,e,o,u={}){const{enabled:r=!0,pageSize:c=D}=u,[i,s]=_(c),l=b(g=>t.onAuthTokenChange(g),()=>t.currentIdentity(),()=>t.currentIdentity()),n=[U,l??"anon",...e,i],a=z({enabled:r,placeholderData:I,queryFn:()=>o(i),queryKey:n,staleTime:0}),d=a.data?.rows,f=a.data?.total,m=f!==void 0&&d!==void 0&&d.length<f,p=()=>{m&&s(g=>g+c)},h=()=>{a.refetch().catch(()=>{})};return{data:d,error:a.error??void 0,hasMore:m,loadMore:p,loading:a.isLoading,refetch:h,total:f}}const $=t=>{const e=A(20);let o;e[0]!==t?(o=t===void 0?{}:t,e[0]=t,e[1]=o):o=e[1];const u=o,r=S(),{enabled:c,filterField:i,filterValue:s,pageSize:l,search:n,searchField:a,sortBy:d,sortDirection:f}=u;let m;e[2]!==i||e[3]!==s||e[4]!==n||e[5]!==a||e[6]!==d||e[7]!==f?(m=["users",{filterField:i,filterValue:s,search:n,searchField:a,sortBy:d,sortDirection:f}],e[2]=i,e[3]=s,e[4]=n,e[5]=a,e[6]=d,e[7]=f,e[8]=m):m=e[8];let p;e[9]!==r||e[10]!==i||e[11]!==s||e[12]!==n||e[13]!==a||e[14]!==d||e[15]!==f?(p=g=>r.listAuthUsers({filterField:i,filterValue:s,limit:g,search:n,searchField:a,sortBy:d,sortDirection:f}),e[9]=r,e[10]=i,e[11]=s,e[12]=n,e[13]=a,e[14]=d,e[15]=f,e[16]=p):p=e[16];let h;return e[17]!==c||e[18]!==l?(h={enabled:c,pageSize:l},e[17]=c,e[18]=l,e[19]=h):h=e[19],v(r,m,p,h)},M=t=>{const e=A(8);let o;e[0]!==t?(o=t===void 0?{}:t,e[0]=t,e[1]=o):o=e[1];const u=o,r=S(),{enabled:c,pageSize:i}=u;let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=["organizations"],e[2]=s):s=e[2];let l;e[3]!==r?(l=a=>r.listAuthOrganizations({limit:a}),e[3]=r,e[4]=l):l=e[4];let n;return e[5]!==c||e[6]!==i?(n={enabled:c,pageSize:i},e[5]=c,e[6]=i,e[7]=n):n=e[7],v(r,s,l,n)},T=t=>{const e=A(8);let o;e[0]!==t?(o=t===void 0?{}:t,e[0]=t,e[1]=o):o=e[1];const u=o,r=S(),{enabled:c,pageSize:i}=u;let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=["sign-up-invitations"],e[2]=s):s=e[2];let l;e[3]!==r?(l=a=>r.listAuthSignUpInvitations({limit:a}),e[3]=r,e[4]=l):l=e[4];let n;return e[5]!==c||e[6]!==i?(n={enabled:c,pageSize:i},e[5]=c,e[6]=i,e[7]=n):n=e[7],v(r,s,l,n)},q=t=>{const e=A(10);let o;e[0]!==t?(o=t===void 0?{}:t,e[0]=t,e[1]=o):o=e[1];const u=o,r=S(),{enabled:c,pageSize:i,userId:s}=u;let l;e[2]!==s?(l=["sessions",{userId:s}],e[2]=s,e[3]=l):l=e[3];let n;e[4]!==r||e[5]!==s?(n=d=>r.listAuthSessions({limit:d,userId:s}),e[4]=r,e[5]=s,e[6]=n):n=e[6];let a;return e[7]!==c||e[8]!==i?(a={enabled:c,pageSize:i},e[7]=c,e[8]=i,e[9]=a):a=e[9],v(r,l,n,a)},k=()=>{const t=A(10),e=S();let o;t[0]!==e?(o={mutationFn:a=>e.impersonateAuthUser({userId:a})},t[0]=e,t[1]=o):o=t[1];const u=y(o),{mutateAsync:r,reset:c}=u;let i;t[2]!==r?(i=a=>r(a),t[2]=r,t[3]=i):i=t[3];const s=i,l=u.error??void 0;let n;return t[4]!==s||t[5]!==u.data||t[6]!==u.isPending||t[7]!==c||t[8]!==l?(n={data:u.data,error:l,impersonate:s,pending:u.isPending,reset:c},t[4]=s,t[5]=u.data,t[6]=u.isPending,t[7]=c,t[8]=l,t[9]=n):n=t[9],n};export{q as useAuthSessions,$ as useAuthUsers,k as useImpersonate,M as useOrganizations,T as useSignUpInvitations};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as u}from"react/compiler-runtime";import{isAuthenticatedStatus as r,isLoadingStatus as a}from"@lunora/client/auth";import n from"./useAuth-BuH3kbVK.mjs";const m=()=>{const t=u(7),{status:e}=n();let s;t[0]!==e?(s=r(e),t[0]=e,t[1]=s):s=t[1];let i;t[2]!==e?(i=a(e),t[2]=e,t[3]=i):i=t[3];let o;return t[4]!==s||t[5]!==i?(o={isAuthenticated:s,isLoading:i},t[4]=s,t[5]=i,t[6]=o):o=t[6],o};export{m as useAuthState};
2
+ import{c as u}from"react/compiler-runtime";import{isAuthenticatedStatus as r,isLoadingStatus as a}from"@lunora/client/auth";import n from"./useAuth-B0lB-41L.mjs";const m=()=>{const t=u(7),{status:e}=n();let s;t[0]!==e?(s=r(e),t[0]=e,t[1]=s):s=t[1];let i;t[2]!==e?(i=a(e),t[2]=e,t[3]=i):i=t[3];let o;return t[4]!==s||t[5]!==i?(o={isAuthenticated:s,isLoading:i},t[4]=s,t[5]=i,t[6]=o):o=t[6],o};export{m as useAuthState};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{useCallback as u,useSyncExternalStore as l}from"react";import{u as c}from"./lunora-provider-Ci1bMLFJ.mjs";const y=e=>{const t=c(),n=u(s=>t.subscribeClientQuery(e,()=>{s()}),[t,e.key]),r=l(n,()=>t.getClientQuery(e),()=>t.getClientQuery(e)),o=u(s=>{t.setClientQuery(e,s)},[t,e]);return[r,o]};export{y as default};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as r}from"react/compiler-runtime";import{useSyncExternalStore as u}from"react";import{u as a}from"./lunora-provider-Ci1bMLFJ.mjs";const S=()=>{const t=r(4),n=a();let o,e,s;return t[0]!==n?(o=c=>n.onConnectionStatus(()=>{c()}),e=()=>n.connectionStatus(),s=()=>n.connectionStatus(),t[0]=n,t[1]=o,t[2]=e,t[3]=s):(o=t[1],e=t[2],s=t[3]),u(o,e,s)};export{S as default};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{useState as _,useRef as i,useEffect as b}from"react";import{u as d}from"./lunora-provider-Ci1bMLFJ.mjs";import{b as K}from"./query-key-B9a-X5-b.mjs";const g="__lunora_flags__:eval",m=t=>{const e=typeof t;return e==="boolean"||e==="number"||e==="string"?e:"object"},v={__lunoraRef:g},F=(t,e,n)=>{try{return t.subscribe(v,{default:e.default,key:e.key,type:m(e.default)},s=>{n(s)},{onError:()=>{n(e.default)}})}catch{return()=>{}}},S=(t,e)=>{const n=d(),[s,r]=_(e),o=m(e),u=`${t}::${o}`,f=i(u);f.current!==u&&(f.current=u,r(e));const l=i(e);return b(()=>{l.current=e}),b(()=>{let a=!1;const c=l.current;r(c);const p=F(n,{default:c,key:t},y=>{a||r(y)});return()=>{a=!0,p()}},[n,t,o]),s},h=t=>{const e=d(),[n,s]=_(t),r=K(t),o=i(r);o.current!==r&&(o.current=r,s(t));const u=i(t);return b(()=>{u.current=t}),b(()=>{let f=!1;const l=u.current;s(l);const a=[];for(const[c,p]of Object.entries(l))a.push(F(e,{default:p,key:c},y=>{f||s(R=>({...R,[c]:y}))}));return()=>{f=!0;for(const c of a)c()}},[e,r]),n};export{S as useFlag,h as useFlags};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as S}from"react/compiler-runtime";import{useReducer as _,useRef as v,useEffect as R}from"react";import{u as b}from"./lunora-provider-Ci1bMLFJ.mjs";import{s as z,c as E}from"./stream-state-abygFxmy.mjs";import{s as H}from"./query-key-B9a-X5-b.mjs";const w=(t,c,n)=>{const e=S(24);let m;e[0]!==n?(m=n===void 0?{}:n,e[0]=n,e[1]=m):m=e[1];const o=m,f=b();let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a={chunks:[],error:void 0,status:"idle"},e[2]=a):a=e[2];const[s,i]=_(z,a),r=c==="skip";let u;e[3]!==c||e[4]!==r?(u=r?"skip":H(c),e[3]=c,e[4]=r,e[5]=u):u=e[5];const k=u,x=v(void 0);let l;e[6]!==c||e[7]!==f||e[8]!==o.maxBuffer||e[9]!==t||e[10]!==r?(l=()=>{if(r)return i({type:"reset"}),K;i({type:"reset"}),i({type:"start"});const{cancel:B,cleanup:y}=E(f.httpStream(t,c,{maxBuffer:o.maxBuffer}),i);return x.current=B,()=>{y(),x.current=void 0}},e[6]=c,e[7]=f,e[8]=o.maxBuffer,e[9]=t,e[10]=r,e[11]=l):l=e[11];let p;e[12]!==f||e[13]!==o.maxBuffer||e[14]!==t.method||e[15]!==t.path||e[16]!==k||e[17]!==r?(p=[f,t.method,t.path,k,r,o.maxBuffer],e[12]=f,e[13]=o.maxBuffer,e[14]=t.method,e[15]=t.path,e[16]=k,e[17]=r,e[18]=p):p=e[18],R(l,p);let h;e[19]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{x.current?.()},e[19]=h):h=e[19];let d;return e[20]!==s.chunks||e[21]!==s.error||e[22]!==s.status?(d={cancel:h,chunks:s.chunks,error:s.error,status:s.status},e[20]=s.chunks,e[21]=s.error,e[22]=s.status,e[23]=d):d=e[23],d};function K(){}export{w as useHttpStream};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as M}from"react/compiler-runtime";import{useRef as R,useEffect as y}from"react";import{u as C}from"./use-paginated-core-DHtDp4dj.mjs";const v=(x,c,N)=>{const e=M(16),{initialNumItems:s}=N,{error:u,loadMore:o,pageResults:m,status:a}=C(x,c==="skip"?"skip":c,N),P=c==="skip";let t;if(e[0]!==m){t=[];for(const f of m)f&&t.push(f.page);e[0]=m,e[1]=t}else t=e[1];let i;e[2]!==s||e[3]!==o?(i={defaultNumItems:s,loadMore:o},e[2]=s,e[3]=o,e[4]=i):i=e[4];const h=R(i);let n;e[5]!==s||e[6]!==o?(n=()=>{h.current={defaultNumItems:s,loadMore:o}},e[5]=s,e[6]=o,e[7]=n):n=e[7],y(n);let r;e[8]===Symbol.for("react.memo_cache_sentinel")?(r=f=>{const{defaultNumItems:k,loadMore:L}=h.current;L(f??k)},e[8]=r):r=e[8];const I=r,d=a==="CanLoadMore",p=!P&&a==="LoadingMore",g=!P&&a==="LoadingFirstPage";let l;return e[9]!==u||e[10]!==t||e[11]!==a||e[12]!==d||e[13]!==p||e[14]!==g?(l={error:u,fetchNextPage:I,hasNextPage:d,isFetchingNextPage:p,isLoading:g,pages:t,status:a},e[9]=u,e[10]=t,e[11]=a,e[12]=d,e[13]=p,e[14]=g,e[15]=l):l=e[15],l};export{v as default};
2
+ import{c as M}from"react/compiler-runtime";import{useRef as R,useEffect as y}from"react";import{u as C}from"./use-paginated-core-B4VdKLHG.mjs";const v=(x,c,N)=>{const e=M(16),{initialNumItems:s}=N,{error:u,loadMore:o,pageResults:m,status:a}=C(x,c==="skip"?"skip":c,N),P=c==="skip";let t;if(e[0]!==m){t=[];for(const f of m)f&&t.push(f.page);e[0]=m,e[1]=t}else t=e[1];let i;e[2]!==s||e[3]!==o?(i={defaultNumItems:s,loadMore:o},e[2]=s,e[3]=o,e[4]=i):i=e[4];const h=R(i);let n;e[5]!==s||e[6]!==o?(n=()=>{h.current={defaultNumItems:s,loadMore:o}},e[5]=s,e[6]=o,e[7]=n):n=e[7],y(n);let r;e[8]===Symbol.for("react.memo_cache_sentinel")?(r=f=>{const{defaultNumItems:k,loadMore:L}=h.current;L(f??k)},e[8]=r):r=e[8];const I=r,d=a==="CanLoadMore",p=!P&&a==="LoadingMore",g=!P&&a==="LoadingFirstPage";let l;return e[9]!==u||e[10]!==t||e[11]!==a||e[12]!==d||e[13]!==p||e[14]!==g?(l={error:u,fetchNextPage:I,hasNextPage:d,isFetchingNextPage:p,isLoading:g,pages:t,status:a},e[9]=u,e[10]=t,e[11]=a,e[12]=d,e[13]=p,e[14]=g,e[15]=l):l=e[15],l};export{v as default};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{useMutation as y,onlineManager as p}from"@tanstack/react-query";import{useRef as O,useState as h,useCallback as l}from"react";import{u as k}from"./lunora-provider-Ci1bMLFJ.mjs";const C=async()=>new Promise(r=>{if(p.isOnline()){r();return}const s=p.subscribe(t=>{t&&(s(),r())})}),U=r=>{const s=k(),t=O(0),[u,d]=h(!1),M=y({mutationFn:async({args:n,options:e})=>(s.canQueueOffline(e?.shardKey)||await C(),s.mutation(r,n,e)),networkMode:"always",retry:0,onMutate:()=>{t.current+=1,d(!0)},onSettled:()=>{t.current-=1,d(t.current>0)}}),{data:a,error:i,isError:c,mutateAsync:o,reset:m}=M,b=l((n,e)=>o({args:n,options:e}),[o]),f=l(n=>({data:a,error:i,isError:c,mutate:(g,w)=>o({args:g,options:{optimisticUpdate:n,...w}}),pending:u,reset:m,withOptimisticUpdate:f}),[o,a,i,c,u,m]);return{data:a,error:i,isError:c,mutate:b,pending:u,reset:m,withOptimisticUpdate:f}};export{U as useMutation};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c}from"react/compiler-runtime";import{u as f}from"./use-paginated-core-DHtDp4dj.mjs";const L=(d,i,l)=>{const e=c(8),{error:r,loadMore:p,pageResults:n,status:t}=f(d,i==="skip"?"skip":i,l);let s;if(e[0]!==n){s=[];for(const u of n)u&&s.push(...u.page);e[0]=n,e[1]=s}else s=e[1];const a=!(i==="skip")&&(t==="LoadingFirstPage"||t==="LoadingMore");let o;return e[2]!==r||e[3]!==p||e[4]!==s||e[5]!==t||e[6]!==a?(o={error:r,isLoading:a,loadMore:p,results:s,status:t},e[2]=r,e[3]=p,e[4]=s,e[5]=t,e[6]=a,e[7]=o):o=e[7],o};export{L as usePaginatedQuery};
2
+ import{c}from"react/compiler-runtime";import{u as f}from"./use-paginated-core-B4VdKLHG.mjs";const L=(d,i,l)=>{const e=c(8),{error:r,loadMore:p,pageResults:n,status:t}=f(d,i==="skip"?"skip":i,l);let s;if(e[0]!==n){s=[];for(const u of n)u&&s.push(...u.page);e[0]=n,e[1]=s}else s=e[1];const a=!(i==="skip")&&(t==="LoadingFirstPage"||t==="LoadingMore");let o;return e[2]!==r||e[3]!==p||e[4]!==s||e[5]!==t||e[6]!==a?(o={error:r,isLoading:a,loadMore:p,results:s,status:t},e[2]=r,e[3]=p,e[4]=s,e[5]=t,e[6]=a,e[7]=o):o=e[7],o};export{L as usePaginatedQuery};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{useMemo as V,useState as I,useRef as f,useEffect as d,useCallback as h}from"react";import{u as A}from"./lunora-provider-Ci1bMLFJ.mjs";const C=()=>{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,n=>n.toString(16).padStart(2,"0")).join("")}}throw new Error("randomSessionId: no Web Crypto available — a session id needs crypto.randomUUID or crypto.getRandomValues")},_=1e4,M=(t,n)=>{const r=A(),{heartbeat:l,intervalMs:y=_,listPresent:m,shardKey:s}=n,c=V(()=>n.sessionId??C(),[n.sessionId]),[E,R]=I(void 0),[g,b]=I(void 0),v=f(n.onError);d(()=>{v.current=n.onError});const u=f(n.data),p=f({client:r,heartbeat:l,roomId:t,sessionId:c,shardKey:s});d(()=>{p.current={client:r,heartbeat:l,roomId:t,sessionId:c,shardKey:s}});const o=h(()=>{const{client:e,heartbeat:a,roomId:i,sessionId:U,shardKey:D}=p.current,L={roomId:i,sessionId:U,...u.current===void 0?{}:{data:u.current}};e.mutation(a,L,{shardKey:D}).catch(()=>{})},[]),S=h(e=>{u.current=e,o()},[o]);return d(()=>{o();const e=setInterval(o,y),a=()=>{typeof document<"u"&&document.visibilityState==="visible"&&o()};return typeof document<"u"&&document.addEventListener("visibilitychange",a),()=>{clearInterval(e),typeof document<"u"&&document.removeEventListener("visibilitychange",a)}},[o,y]),d(()=>r.acquireConnectionContext({roomId:t,sessionId:c},{shardKey:s}),[r,t,c,s]),d(()=>{let e=!1;const a=r.subscribe(m,{roomId:t},i=>{e||(R(i),b(void 0))},{onError:i=>{e||b(i),v.current?.(i)},shardKey:s});return()=>{e=!0,a()}},[r,m.__lunoraRef,t,s]),{error:g,present:E,sessionId:c,setData:S}};export{M as usePresence};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{useQueryClient as E,useQuery as b}from"@tanstack/react-query";import{useRef as I,useEffect as c,useCallback as k,useState as q}from"react";import{u as K,g as f}from"./lunora-provider-Ci1bMLFJ.mjs";import{l as C,a as D}from"./query-key-B9a-X5-b.mjs";const F=(a,i,h={})=>{const e=K(),u=E(),{onError:l,shardKey:o}=h,d=I(l);c(()=>{d.current=l});const p=k(s=>{d.current?.(s)},[]),r=i==="skip",n=r?{}:i,t=C(a,n,o),[y,Q]=q(e.isReady);c(()=>{y||e.whenReady().then(()=>{Q(!0)})},[e,y]);const g=r?void 0:e.peekHydratedQuery(a.__lunoraRef,n,o),{data:R}=b({enabled:!r&&y,initialData:g,queryFn:async()=>{const s=f(e),S=s.openSnapshotSample(t),m=await e.query(a,n,{shardKey:o});return s.closeSnapshotSample(S)?m:u.getQueryData(t)??m},queryKey:t,staleTime:Number.POSITIVE_INFINITY});return c(()=>r?()=>{}:f(e).attach(u,t,a,n,o,{onError:p}),[e,u,D(t),r,p]),r?void 0:R};export{F as default};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as K}from"react/compiler-runtime";import{useReducer as B,useRef as R,useEffect as _}from"react";import{u as v}from"./lunora-provider-Ci1bMLFJ.mjs";import{s as S,c as z}from"./stream-state-abygFxmy.mjs";import{s as E}from"./query-key-B9a-X5-b.mjs";const A=(u,a,l)=>{const e=K(27);let c;e[0]!==l?(c=l===void 0?{}:l,e[0]=l,e[1]=c):c=e[1];const r=c,o=v();let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f={chunks:[],error:void 0,status:"idle"},e[2]=f):f=e[2];const[t,m]=B(S,f),s=a==="skip";let n;e[3]!==a||e[4]!==s?(n=s?"skip":E(a),e[3]=a,e[4]=s,e[5]=n):n=e[5];const y=n,b=R(void 0);let i;e[6]!==a||e[7]!==o||e[8]!==u||e[9]!==r.durable||e[10]!==r.maxBuffer||e[11]!==r.shardKey||e[12]!==s?(i=()=>{if(s)return m({type:"reset"}),L;m({type:"reset"}),m({type:"start"});const{cancel:k,cleanup:x}=z(o.stream(u,a,{durable:r.durable,maxBuffer:r.maxBuffer,shardKey:r.shardKey}),m);return b.current=k,()=>{x(),b.current=void 0}},e[6]=a,e[7]=o,e[8]=u,e[9]=r.durable,e[10]=r.maxBuffer,e[11]=r.shardKey,e[12]=s,e[13]=i):i=e[13];let d;e[14]!==o||e[15]!==u.__lunoraRef||e[16]!==r.durable||e[17]!==r.maxBuffer||e[18]!==r.shardKey||e[19]!==y||e[20]!==s?(d=[o,u.__lunoraRef,y,s,r.shardKey,r.maxBuffer,r.durable],e[14]=o,e[15]=u.__lunoraRef,e[16]=r.durable,e[17]=r.maxBuffer,e[18]=r.shardKey,e[19]=y,e[20]=s,e[21]=d):d=e[21],_(i,d);let p;e[22]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{b.current?.()},e[22]=p):p=e[22];let h;return e[23]!==t.chunks||e[24]!==t.error||e[25]!==t.status?(h={cancel:p,chunks:t.chunks,error:t.error,status:t.status},e[23]=t.chunks,e[24]=t.error,e[25]=t.status,e[26]=h):h=e[26],h};function L(){}export{A as useStream};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as x}from"react/compiler-runtime";import{createQuerySubscription as A}from"@lunora/client/query";import{LunoraError as D}from"@lunora/errors";import{useState as F,useRef as S,useEffect as v}from"react";import{u as M}from"./lunora-provider-Ci1bMLFJ.mjs";import{s as Q}from"./query-key-B9a-X5-b.mjs";const H=(o,r,a)=>{const e=x(24);let l;e[0]!==a?(l=a===void 0?{}:a,e[0]=a,e[1]=l):l=e[1];const t=l,n=M();let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={data:void 0,error:void 0},e[2]=c):c=e[2];const[k,E]=F(c),s=r==="skip";let d;e[3]!==r||e[4]!==s?(d=s?"skip":Q(r),e[3]=r,e[4]=s,e[5]=d):d=e[5];const b=d,K=S(t.onError);let u;e[6]!==t.onError?(u=()=>{K.current=t.onError},e[6]=t.onError,e[7]=u):u=e[7],v(u);let f;e[8]!==r||e[9]!==o?(f={args:r,fn:o},e[8]=r,e[9]=o,e[10]=f):f=e[10];const R=S(f);let m;e[11]!==r||e[12]!==o?(m=()=>{R.current={args:r,fn:o}},e[11]=r,e[12]=o,e[13]=m):m=e[13],v(m);let p;e[14]!==n||e[15]!==t.shardKey||e[16]!==s?(p=()=>{if(s)return E({data:void 0,error:void 0}),W;let h=!1;const{args:w,fn:z}=R.current,L=A(n,z,w,{onData:i=>{h||E({data:i,error:void 0})},onError:i=>{const q=i.code===void 0?new Error(i.message):new D(i.code,i.message);K.current?.(i),queueMicrotask(()=>{h||E({data:void 0,error:q})})}},{shardKey:t.shardKey});return()=>{h=!0,L()}},e[14]=n,e[15]=t.shardKey,e[16]=s,e[17]=p):p=e[17];let y;return e[18]!==n||e[19]!==o.__lunoraRef||e[20]!==t.shardKey||e[21]!==b||e[22]!==s?(y=[n,o.__lunoraRef,b,t.shardKey,s],e[18]=n,e[19]=o.__lunoraRef,e[20]=t.shardKey,e[21]=b,e[22]=s,e[23]=y):y=e[23],v(p,y),k};function W(){}export{H as default};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{useState as T,useRef as W,useCallback as y,useEffect as G}from"react";import{u as X}from"./lunora-provider-Ci1bMLFJ.mjs";const N="/_lunora/ws",j="/_lunora/voice/",z=4001,O=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,Q=e=>{const r=e.startsWith("agents:")?e.slice(7):e;return r.endsWith("Voice")?r.slice(0,-5):r},Y=(e,r)=>{if(r===void 0||r==="")return O(e);if(r.endsWith(N))return r.slice(0,-N.length);try{return new URL(r).origin}catch{return O(e)}},Z=e=>{const r=Y(e.httpUrl,e.wsUrl),o=r.endsWith("/")?r.slice(0,-1):r,i=new URLSearchParams({threadKey:e.threadKey});return`${o}${j}${encodeURIComponent(e.agent)}?${i.toString()}`},ee=(e,r)=>{if(r?.code===z)return new Error(`${e}: authentication token expired — refresh the credential and start a new call`)},te=(e,r,o)=>{const i=e.currentIdentity();return e.onAuthTokenChange(()=>{e.currentIdentity()!==i&&o(new Error(`${r}: the signed-in identity changed during the call — the session was ended; start a new call`))})},ne=16e3,re=e=>{if(e.length===0)return 0;let r=0;for(const o of e)r+=o*o;return Math.sqrt(r/e.length)},oe=(e,r)=>{const o=r/ne,i=o>1?Math.floor(e.length/o):e.length,d=new ArrayBuffer(i*2),l=new DataView(d);for(let u=0;u<i;u+=1){const g=e[Math.floor(u*o)]??0,p=Math.max(-1,Math.min(1,g));l.setInt16(u*2,p<0?p*32768:p*32767,!0)}return new Uint8Array(d)},se=async e=>{const r=globalThis,o=r.navigator?.mediaDevices?.getUserMedia.bind(r.navigator.mediaDevices),i=r.AudioContext??r.webkitAudioContext;if(!o||!i)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const d=await o({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),l=new i,u=l.createMediaStreamSource(d),g=l.createScriptProcessor(4096,1,1);let p=!1,w=!1,a=0,h=0;return g.onaudioprocess=s=>{const f=s.inputBuffer.getChannelData(0),m=p?0:re(f);if(e.onLevel(m),p)return;if(e.onAudio(oe(f,l.sampleRate)),e.isTurnActive()){h=m>=e.interruptThreshold?h+1:0,h>=e.interruptChunks&&(h=0,e.onInterrupt());return}h=0;const x=f.length/l.sampleRate*1e3;if(m>=e.silenceThreshold){w=!0,a=0;return}w&&(a+=x,a>=e.silenceDurationMs&&(w=!1,a=0,e.onSilence()))},u.connect(g),g.connect(l.destination),{setMuted:s=>{p=s},stop:()=>{g.disconnect(),u.disconnect();for(const s of d.getTracks())s.stop();l.close()}}},ce=()=>{const e=globalThis,r=e.AudioContext??e.webkitAudioContext;if(!r)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const o=new r,i=new Set;let d=0,l=Promise.resolve(),u=0;const g=async(a,h)=>{if(h!==u)return;let s;try{s=await o.decodeAudioData(a.buffer)}catch{return}if(h!==u)return;const f=o.createBufferSource();f.buffer=s,f.connect(o.destination);const m=Math.max(o.currentTime,d);f.start(m),d=m+s.duration,i.add(f),f.onended=()=>{i.delete(f)}},p=a=>{const h=Uint8Array.from(a),s=u;l=l.then(()=>g(h,s))},w=()=>{u+=1;for(const a of i)try{a.stop()}catch{}i.clear(),d=o.currentTime};return{enqueue:p,interrupt:w,stop:()=>{w(),o.close()}}},P=1,ie=.01,ae=1200,ue=.15,le=3,he=e=>{const{createMicrophone:r=se,createSpeaker:o=ce,createSocket:i,interruptChunks:d=le,interruptThreshold:l=ue,silenceDurationMs:u=ae,silenceThreshold:g=ie,threadKey:p,voice:w}=e,a=X(),[h,s]=T("idle"),[f,m]=T(!1),[x,M]=T(""),[H,b]=T(""),[$,R]=T(0),[I,U]=T(!1),[B,E]=T(void 0),c=W(void 0),_=W(!1),v=y(t=>{const n=c.current?.socket;return n?.readyState===P?(n.send(JSON.stringify(t)),!0):!1},[]),A=y(()=>{const t=c.current;if(c.current=void 0,t){t.unwatchIdentity?.(),t.microphone?.stop(),t.speaker?.stop(),t.socket.onmessage=null,t.socket.onerror=null,t.socket.onclose=null;try{t.socket.close()}catch{}}_.current=!1,m(!1),s("idle"),R(0)},[]),L=y(t=>{const n=c.current;switch(t.type){case"assistant_delta":{n&&(n.speaking=!0),s("speaking"),b(F=>F+t.text);break}case"assistant_done":{n&&(n.awaitingTurn=!1,n.speaking=!1),b(t.text),s("listening");break}case"error":{n&&(n.awaitingTurn=!1,n.speaking=!1),E(new Error(t.message)),s("listening");break}case"interrupted":{n&&(n.awaitingTurn=!1,n.speaking=!1,n.suppressAudio=!1),n?.speaker?.interrupt(),s("listening");break}case"ready":{n&&(n.audioFormat=t.audioFormat,n.suppressAudio=!1),m(!0),s("listening");break}case"user_transcript":{n&&(n.suppressAudio=!1),M(t.text),b(""),s("thinking");break}}},[]),D=y(t=>{const n=c.current;!n||n.suppressAudio||(n.speaker??=o({audioFormat:n.audioFormat}),n.speaking=!0,s("speaking"),n.speaker.enqueue(t))},[o]),q=y(async()=>{if(c.current||_.current)return;_.current=!0,E(void 0),M(""),b("");let t;try{const n=Z({agent:Q(w.__lunoraRef),httpUrl:a.url,threadKey:p,wsUrl:a.wsUrl}),S=(i??(k=>{const C=a.getWebSocketImpl();if(!C)throw new Error("useVoiceAgent: no WebSocket implementation available (pass createSocket explicitly)");return new C(k)}))(n);S.binaryType="arraybuffer",t={audioFormat:"mp3",microphone:void 0,socket:S,speaker:void 0,speaking:!1,awaitingTurn:!1,suppressAudio:!1,unwatchIdentity:void 0},c.current=t,t.unwatchIdentity=te(a,"useVoiceAgent",k=>{c.current===t&&(E(k),A())}),S.onmessage=k=>{if(typeof k.data=="string"){try{L(JSON.parse(k.data))}catch{}return}D(new Uint8Array(k.data))},S.onerror=()=>{E(new Error("useVoiceAgent: voice socket error"))},S.onclose=k=>{if(c.current!==t)return;const C=ee("useVoiceAgent",k);C&&E(C),A()};const V=await r({interruptChunks:d,interruptThreshold:l,isTurnActive:()=>(c.current?.speaking??!1)||(c.current?.awaitingTurn??!1),onAudio:k=>{S.readyState===P&&S.send(k)},onInterrupt:()=>{v({type:"interrupt"}),c.current?.speaker?.interrupt(),c.current&&(c.current.awaitingTurn=!1,c.current.speaking=!1,c.current.suppressAudio=!0),s("listening")},onLevel:R,onSilence:()=>{v({type:"commit"}),c.current&&(c.current.awaitingTurn=!0),s("thinking")},silenceDurationMs:u,silenceThreshold:g});c.current===t?(t.microphone=V,U(!1),t.speaking||s("listening")):V.stop()}catch(n){c.current===t&&(E(n instanceof Error?n:new Error(String(n))),A())}finally{_.current=!1}},[a,r,i,D,L,d,l,v,u,g,A,p,w]),K=y(()=>{const t=!I;return c.current?.microphone?.setMuted(t),U(t),t},[I]),J=y(t=>{v({text:t,type:"text"})&&(c.current&&(c.current.awaitingTurn=!0),s("thinking"))},[v]);return G(()=>A,[A]),{audioLevel:$,connected:f,endCall:A,error:B,interimTranscript:H,isMuted:I,sendText:J,startCall:q,status:h,toggleMute:K,transcript:x}};export{he as useVoiceAgent};
package/dist/server.mjs CHANGED
@@ -1 +1 @@
1
- import{createServerClient as o}from"@lunora/client/ssr";import{createServerClient as K,deserializePreloaded as f,getServerSession as Q,serializePreloaded as x}from"@lunora/client/ssr";import{l as d}from"./packem_shared/query-key-By_ZIdza.mjs";import{lunoraQueryOptions as S}from"./packem_shared/lunoraQueryOptions-BVgQsR9d.mjs";import{preloadQuery as v,preloadedQueryResult as N}from"@lunora/client";import{HydrationBoundary as T,dehydrate as g}from"@tanstack/react-query";const u=async(r,a,e,t,y={})=>{const s=t??{};await r.prefetchQuery({queryFn:()=>a.query(e,s,{shardKey:y.shardKey}),queryKey:d(e,s,y.shardKey),staleTime:Number.POSITIVE_INFINITY})},h=async(r,a,e,t={})=>o(r).query(a,e,{shardKey:t.shardKey}),i=async(r,a,e,t={})=>o(r).mutation(a,e,{shardKey:t.shardKey}),l=async(r,a,e,t={})=>o(r).action(a,e,{shardKey:t.shardKey});export{T as HydrationBoundary,K as createServerClient,g as dehydrate,f as deserializePreloaded,l as fetchAction,i as fetchMutation,h as fetchQuery,Q as getServerSession,S as lunoraQueryOptions,u as prefetchQuery,v as preloadQuery,N as preloadedQueryResult,x as serializePreloaded};
1
+ import{createServerClient as o}from"@lunora/client/ssr";import{createServerClient as K,deserializePreloaded as f,getServerSession as Q,serializePreloaded as x}from"@lunora/client/ssr";import{l as d}from"./packem_shared/query-key-B9a-X5-b.mjs";import{lunoraQueryOptions as S}from"./packem_shared/lunoraQueryOptions-ChMQ9ryB.mjs";import{preloadQuery as v,preloadedQueryResult as N}from"@lunora/client";import{HydrationBoundary as T,dehydrate as g}from"@tanstack/react-query";const u=async(r,a,e,t,y={})=>{const s=t??{};await r.prefetchQuery({queryFn:()=>a.query(e,s,{shardKey:y.shardKey}),queryKey:d(e,s,y.shardKey),staleTime:Number.POSITIVE_INFINITY})},h=async(r,a,e,t={})=>o(r).query(a,e,{shardKey:t.shardKey}),i=async(r,a,e,t={})=>o(r).mutation(a,e,{shardKey:t.shardKey}),l=async(r,a,e,t={})=>o(r).action(a,e,{shardKey:t.shardKey});export{T as HydrationBoundary,K as createServerClient,g as dehydrate,f as deserializePreloaded,l as fetchAction,i as fetchMutation,h as fetchQuery,Q as getServerSession,S as lunoraQueryOptions,u as prefetchQuery,v as preloadQuery,N as preloadedQueryResult,x as serializePreloaded};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/react",
3
- "version": "1.0.0-alpha.142",
3
+ "version": "1.0.0-alpha.144",
4
4
  "description": "React hooks for Lunora: useQuery, useMutation, useSubscription, and useAuth",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -57,9 +57,9 @@
57
57
  "access": "public"
58
58
  },
59
59
  "dependencies": {
60
- "@lunora/client": "1.0.0-alpha.136",
60
+ "@lunora/client": "1.0.0-alpha.137",
61
61
  "@lunora/errors": "1.0.0-alpha.41",
62
- "@lunora/ratelimit": "1.0.0-alpha.80",
62
+ "@lunora/ratelimit": "1.0.0-alpha.82",
63
63
  "@visulima/storage-client": "1.0.3"
64
64
  },
65
65
  "peerDependencies": {
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{c as p}from"react/compiler-runtime";import{LunoraError as y}from"@lunora/errors";import{QueryClientContext as L,QueryClientProvider as I,QueryClient as v}from"@tanstack/react-query";import{use as f,useState as x,createContext as N}from"react";import{jsx as m}from"react/jsx-runtime";const C=N(null),Q=()=>new v({defaultOptions:{mutations:{retry:0},queries:{gcTime:5*6e4,retry:0,staleTime:Number.POSITIVE_INFINITY}}}),b=r=>{const e=p(9),{children:c,client:a,queryClient:n}=r,t=f(L);let o;e[0]!==t||e[1]!==n?(o=()=>n??t??Q(),e[0]=t,e[1]=n,e[2]=o):o=e[2];const[d]=x(o),i=n??t??d;let u;e[3]!==c||e[4]!==a?(u=m(C,{value:a,children:c}),e[3]=c,e[4]=a,e[5]=u):u=e[5];const l=u;if(t===i)return l;let s;return e[6]!==l||e[7]!==i?(s=m(I,{client:i,children:l}),e[6]=l,e[7]=i,e[8]=s):s=e[8],s},q=()=>{const r=f(C);if(!r)throw new y("INTERNAL","useLunora must be used inside <LunoraProvider />");return r};export{b as LunoraProvider,q as useLunora};
@@ -1 +0,0 @@
1
- import{k as a}from"./query-key-By_ZIdza.mjs";class b{constructor(e){this.client=e}client;entries=new Map;pushes=new Map;samples=new Map;keyOf(e){return a(e)}hasConsumers(e){return this.entries.has(a(e))}openSnapshotSample(e){const t=a(e);return this.samples.set(t,(this.samples.get(t)??0)+1),{key:t,pushes:this.pushes.get(t)??0}}closeSnapshotSample(e){const t=(this.samples.get(e.key)??1)-1,h=(this.pushes.get(e.key)??0)===e.pushes;return t>0?(this.samples.set(e.key,t),h):(this.samples.delete(e.key),this.entries.has(e.key)||this.pushes.delete(e.key),h)}attach(e,t,h,p,f,k={}){const s=a(t);let r=this.entries.get(s);if(!r){r={errorCallbacks:new Set,refCount:0,unsubscribe:void 0},this.entries.set(s,r);const n=r;try{r.unsubscribe=this.client.subscribe(h,p,i=>{this.pushes.set(s,(this.pushes.get(s)??0)+1),e.setQueryData(t,i)},{onError:i=>{for(const y of n.errorCallbacks)y(i)},shardKey:f})}catch(i){throw this.entries.delete(s),i}}r.refCount+=1;const{onError:u}=k;u&&r.errorCallbacks.add(u);let c=!1;return()=>{if(c)return;c=!0;const n=this.entries.get(s);n&&(n.refCount-=1,u&&n.errorCallbacks.delete(u),n.refCount<=0&&(n.unsubscribe?.(),this.entries.delete(s)))}}}const l=new WeakMap,d=o=>{let e=l.get(o);return e||(e=new b(o),l.set(o,e)),e};export{d as g};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{c as _}from"react/compiler-runtime";import{useQueryClient as b,useQuery as q}from"@tanstack/react-query";import{useRef as K,useEffect as Q}from"react";import{g as P}from"./cache-6yT0tWav.mjs";import{useLunora as v}from"./LunoraProvider-DC06S-p1.mjs";import{l as N,s as S}from"./query-key-By_ZIdza.mjs";const T=function(a,e){const r=_(9);let o;r[0]!==e?(o=e===void 0?{}:e,r[0]=e,r[1]=o):o=r[1];const n=o,t=v(),s=b(),p=K(n.onError);let i;r[2]!==n.onError?(i=()=>{p.current=n.onError},r[2]=n.onError,r[3]=i):i=r[3],Q(i);let u;r[4]===Symbol.for("react.memo_cache_sentinel")?(u=I=>{p.current?.(I)},r[4]=u):u=r[4];const E=u,{args:l,functionPath:R,shardKey:f,value:g}=a,y={__lunoraRef:R},m=N(y,l,f),{data:h}=q({initialData:g,queryFn:()=>t.query(y,l,{shardKey:f}),queryKey:m,staleTime:Number.POSITIVE_INFINITY}),d=S(m);let c;return r[5]!==t||r[6]!==s||r[7]!==d?(c=[t,s,d,E],r[5]=t,r[6]=s,r[7]=d,r[8]=c):c=r[8],Q(()=>P(t).attach(s,m,y,l,f,{onError:E}),c),h===void 0?g:h},L=function(a,e={}){return T(a,e)};export{T as default,L as hydratePreloaded};
@@ -1 +0,0 @@
1
- import{s as r}from"./wire-key-p_JEwJ1j.mjs";const o=e=>r(e),n=(e,s,a)=>["lunora",e.__lunoraRef,s,a??null],t=e=>o(e);export{o as k,n as l,t as s};
@@ -1 +0,0 @@
1
- const a=/["\\\u0000-\u001F\uD800-\uDFFF]/,f=t=>a.test(t)?JSON.stringify(t):`"${t}"`,y=t=>{if(t===void 0)return"null";if(typeof t=="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 t=="number"){if(Number.isNaN(t))return"nan";if(t===1/0)return"inf";if(t===-1/0)return"-inf";if(Object.is(t,-0))return"-0"}if(typeof t=="string")return f(t);if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t)){let r="[";for(let n=0;n<t.length;n++)n>0&&(r+=","),r+=y(t[n]);return r+"]"}const i=Object.getPrototypeOf(t);if(i!==null&&i!==Object.prototype){const r=t.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 o=t,c=Object.keys(o).sort();let e="{",s=!0;for(const r of c){const n=o[r];n!==void 0&&(s?s=!1:e+=",",e+=f(r),e+=":",e+=y(n))}return e+"}"};export{y as s};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{initialPages as N,rebalance as H,derivePaginationStatus as O,applyLoadMore as V}from"@lunora/client/pagination";import{useQueryClient as Y}from"@tanstack/react-query";import{useRef as p,useReducer as B,useState as T,useEffect as d,useCallback as G}from"react";import{g as J}from"./cache-6yT0tWav.mjs";import{useLunora as U}from"./LunoraProvider-DC06S-p1.mjs";import{s as u,l as I}from"./query-key-By_ZIdza.mjs";const W=function(i){const m=p(void 0);return m.current??=i(),m},ne=function(i,m,S){const y=U(),o=Y(),{initialNumItems:R,shardKey:h}=S,f=m==="skip",g=f?{}:m,[,z]=B(e=>e+1,0),[A,k]=T(()=>N(R)),[_,K]=T(void 0),P=p(S.onError);d(()=>{P.current=S.onError});const Q=`${u(I(i,g,h))}::${String(R)}`,x=p(Q);x.current!==Q&&(x.current=Q,k(N(R)),K(void 0));const b=A.map(e=>{const t={...g,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}},r=I(i,t,h);return{args:t,key:r}}),D=b.map(({key:e})=>u(e)).join("|"),v=p({baseArgs:g,entries:[],fn:i,shardKey:h});d(()=>{v.current={baseArgs:g,entries:b,fn:i,shardKey:h}});const F=(e,t,r)=>{K(r),k(a=>{const s=v.current,n=a.at(-1);if(a.length<=1||!n||o.getQueryData(t)!==void 0)return a;const w={...s.baseArgs,paginationOpts:{cursor:n.lower,endCursor:n.upper,numItems:n.numItems}};return u(I(s.fn,w,s.shardKey))===e?a.slice(0,-1):a}),P.current?.(r)},q=W(()=>new Map),L=p(y);d(()=>{const e=q.current;if(L.current!==y){for(const s of e.values())s();e.clear(),L.current=y}if(f){for(const s of e.values())s();e.clear();return}const t=v.current,r=J(y),a=new Set(t.entries.map(({key:s})=>u(s)));for(const[s,n]of e)a.has(s)||(n(),e.delete(s));for(const s of t.entries){const n=u(s.key);if(e.has(n))continue;o.fetchQuery({gcTime:Number.POSITIVE_INFINITY,queryFn:async()=>{const c=r.openSnapshotSample(s.key),M=await y.query(t.fn,s.args,{shardKey:t.shardKey});return r.closeSnapshotSample(c)?M:o.getQueryData(s.key)??M},queryKey:s.key,staleTime:0}).catch(c=>{F(n,s.key,c instanceof Error?{code:c.code,message:c.message}:{message:String(c)})});const l=r.attach(o,s.key,t.fn,s.args,t.shardKey,{onError:c=>{F(n,s.key,c)}}),C=s.key;e.set(n,()=>{l(),r.hasConsumers(C)||o.removeQueries({exact:!0,queryKey:C})})}},[y,o,D,f]),d(()=>()=>{for(const e of q.current.values())e();q.current.clear()},[]),d(()=>o.getQueryCache().subscribe(r=>{if(r.type!=="updated")return;const a=u(r.query.queryKey);b.some(({key:s})=>u(s)===a)&&(K(void 0),z())}),[o,D]);const E=f?[]:b.map(({key:e})=>o.getQueryData(e));d(()=>{if(f)return;const e=H(A,E);e&&k(e)});const{status:$}=O(f,E),j=G(e=>{K(void 0),k(t=>{const r=v.current,a=t.map(l=>{const C={...r.baseArgs,paginationOpts:{cursor:l.lower,endCursor:l.upper,numItems:l.numItems}};return o.getQueryData(I(r.fn,C,r.shardKey))}),{nextCursor:s,status:n}=O(!1,a);return V(t,n==="CanLoadMore"?s:void 0,e)??t})},[o]);return{error:_,loadMore:j,pageResults:E,status:$}};export{ne as u};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{c as R}from"react/compiler-runtime";import{createCallRunner as k}from"@lunora/client";import{useMutation as x}from"@tanstack/react-query";import{useState as n}from"react";import{useLunora as C}from"./LunoraProvider-DC06S-p1.mjs";const S=a=>{const t=R(12),i=C(),[c,g]=n(void 0),[l,m]=n(void 0),[u,M]=n(!1);let o;t[0]!==i||t[1]!==a?(o={mutationFn:async e=>{const{args:y,options:A}=e;return i.action(a,y,A)},networkMode:"always",retry:0},t[0]=i,t[1]=a,t[2]=o):o=t[2];const{mutateAsync:d,reset:p}=x(o);let s;t[3]!==d||t[4]!==p?(s=()=>({call:k(async(e,y)=>d({args:e,options:y}),{setError:m,setPending:M,setResult:e=>{g(()=>e),m(void 0)}}),reset:()=>{g(void 0),m(void 0),p()}}),t[3]=d,t[4]=p,t[5]=s):s=t[5];const[w]=n(s),{call:f,reset:v}=w;let r;return t[6]!==f||t[7]!==c||t[8]!==l||t[9]!==u||t[10]!==v?(r={call:f,data:c,error:l,pending:u,reset:v},t[6]=f,t[7]=c,t[8]=l,t[9]=u,t[10]=v,t[11]=r):r=t[11],r};export{S as useAction};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{c as h}from"react/compiler-runtime";import{getIdentityStore as k}from"@lunora/client/auth";import{useSyncExternalStore as p}from"react";import{useLunora as A}from"./LunoraProvider-DC06S-p1.mjs";const _=()=>{const t=h(13),e=A();let o;t[0]!==e?(o=k(e),t[0]=e,t[1]=o):o=t[1];const n=o;let s,r,u;t[2]!==e?(s=g=>e.onAuthTokenChange(g),r=()=>e.getAuthToken(),u=()=>e.getAuthToken(),t[2]=e,t[3]=s,t[4]=r,t[5]=u):(s=t[3],r=t[4],u=t[5]);const i=p(s,r,u),f=p(n.subscribe,n.getUser,T),m=p(n.subscribe,n.getStatus,b);let l;t[6]!==e?(l=g=>{e.setAuthToken(g)},t[6]=e,t[7]=l):l=t[7];const a=l;let c;return t[8]!==a||t[9]!==m||t[10]!==i||t[11]!==f?(c={setToken:a,status:m,token:i,user:f},t[8]=a,t[9]=m,t[10]=i,t[11]=f,t[12]=c):c=t[12],c};function T(){return null}function b(){return"loading"}export{_ as default};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{c as A}from"react/compiler-runtime";import{useMutation as y,useQuery as z,keepPreviousData as I}from"@tanstack/react-query";import{useState as _,useSyncExternalStore as b}from"react";import{useLunora as S}from"./LunoraProvider-DC06S-p1.mjs";const U="lunora-react-admin-auth",D=50;function v(t,e,o,u={}){const{enabled:r=!0,pageSize:c=D}=u,[i,s]=_(c),a=b(g=>t.onAuthTokenChange(g),()=>t.currentIdentity(),()=>t.currentIdentity()),n=[U,a??"anon",...e,i],l=z({enabled:r,placeholderData:I,queryFn:()=>o(i),queryKey:n,staleTime:0}),d=l.data?.rows,f=l.data?.total,m=f!==void 0&&d!==void 0&&d.length<f,p=()=>{m&&s(g=>g+c)},h=()=>{l.refetch().catch(()=>{})};return{data:d,error:l.error??void 0,hasMore:m,loadMore:p,loading:l.isLoading,refetch:h,total:f}}const $=t=>{const e=A(20);let o;e[0]!==t?(o=t===void 0?{}:t,e[0]=t,e[1]=o):o=e[1];const u=o,r=S(),{enabled:c,filterField:i,filterValue:s,pageSize:a,search:n,searchField:l,sortBy:d,sortDirection:f}=u;let m;e[2]!==i||e[3]!==s||e[4]!==n||e[5]!==l||e[6]!==d||e[7]!==f?(m=["users",{filterField:i,filterValue:s,search:n,searchField:l,sortBy:d,sortDirection:f}],e[2]=i,e[3]=s,e[4]=n,e[5]=l,e[6]=d,e[7]=f,e[8]=m):m=e[8];let p;e[9]!==r||e[10]!==i||e[11]!==s||e[12]!==n||e[13]!==l||e[14]!==d||e[15]!==f?(p=g=>r.listAuthUsers({filterField:i,filterValue:s,limit:g,search:n,searchField:l,sortBy:d,sortDirection:f}),e[9]=r,e[10]=i,e[11]=s,e[12]=n,e[13]=l,e[14]=d,e[15]=f,e[16]=p):p=e[16];let h;return e[17]!==c||e[18]!==a?(h={enabled:c,pageSize:a},e[17]=c,e[18]=a,e[19]=h):h=e[19],v(r,m,p,h)},M=t=>{const e=A(8);let o;e[0]!==t?(o=t===void 0?{}:t,e[0]=t,e[1]=o):o=e[1];const u=o,r=S(),{enabled:c,pageSize:i}=u;let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=["organizations"],e[2]=s):s=e[2];let a;e[3]!==r?(a=l=>r.listAuthOrganizations({limit:l}),e[3]=r,e[4]=a):a=e[4];let n;return e[5]!==c||e[6]!==i?(n={enabled:c,pageSize:i},e[5]=c,e[6]=i,e[7]=n):n=e[7],v(r,s,a,n)},T=t=>{const e=A(8);let o;e[0]!==t?(o=t===void 0?{}:t,e[0]=t,e[1]=o):o=e[1];const u=o,r=S(),{enabled:c,pageSize:i}=u;let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=["sign-up-invitations"],e[2]=s):s=e[2];let a;e[3]!==r?(a=l=>r.listAuthSignUpInvitations({limit:l}),e[3]=r,e[4]=a):a=e[4];let n;return e[5]!==c||e[6]!==i?(n={enabled:c,pageSize:i},e[5]=c,e[6]=i,e[7]=n):n=e[7],v(r,s,a,n)},q=t=>{const e=A(10);let o;e[0]!==t?(o=t===void 0?{}:t,e[0]=t,e[1]=o):o=e[1];const u=o,r=S(),{enabled:c,pageSize:i,userId:s}=u;let a;e[2]!==s?(a=["sessions",{userId:s}],e[2]=s,e[3]=a):a=e[3];let n;e[4]!==r||e[5]!==s?(n=d=>r.listAuthSessions({limit:d,userId:s}),e[4]=r,e[5]=s,e[6]=n):n=e[6];let l;return e[7]!==c||e[8]!==i?(l={enabled:c,pageSize:i},e[7]=c,e[8]=i,e[9]=l):l=e[9],v(r,a,n,l)},k=()=>{const t=A(10),e=S();let o;t[0]!==e?(o={mutationFn:l=>e.impersonateAuthUser({userId:l})},t[0]=e,t[1]=o):o=t[1];const u=y(o),{mutateAsync:r,reset:c}=u;let i;t[2]!==r?(i=l=>r(l),t[2]=r,t[3]=i):i=t[3];const s=i,a=u.error??void 0;let n;return t[4]!==s||t[5]!==u.data||t[6]!==u.isPending||t[7]!==c||t[8]!==a?(n={data:u.data,error:a,impersonate:s,pending:u.isPending,reset:c},t[4]=s,t[5]=u.data,t[6]=u.isPending,t[7]=c,t[8]=a,t[9]=n):n=t[9],n};export{q as useAuthSessions,$ as useAuthUsers,k as useImpersonate,M as useOrganizations,T as useSignUpInvitations};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{useCallback as n,useSyncExternalStore as l}from"react";import{useLunora as c}from"./LunoraProvider-DC06S-p1.mjs";const y=e=>{const t=c(),u=n(s=>t.subscribeClientQuery(e,()=>{s()}),[t,e.key]),r=l(u,()=>t.getClientQuery(e),()=>t.getClientQuery(e)),o=n(s=>{t.setClientQuery(e,s)},[t,e]);return[r,o]};export{y as default};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{c as s}from"react/compiler-runtime";import{useSyncExternalStore as u}from"react";import{useLunora as i}from"./LunoraProvider-DC06S-p1.mjs";const S=()=>{const t=s(4),n=i();let o,e,c;return t[0]!==n?(o=r=>n.onConnectionStatus(()=>{r()}),e=()=>n.connectionStatus(),c=()=>n.connectionStatus(),t[0]=n,t[1]=o,t[2]=e,t[3]=c):(o=t[1],e=t[2],c=t[3]),u(o,e,c)};export{S as default};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{useState as _,useRef as i,useEffect as b}from"react";import{useLunora as d}from"./LunoraProvider-DC06S-p1.mjs";import{s as K}from"./stable-key-B_BlboiY.mjs";const g="__lunora_flags__:eval",m=t=>{const e=typeof t;return e==="boolean"||e==="number"||e==="string"?e:"object"},v={__lunoraRef:g},F=(t,e,n)=>{try{return t.subscribe(v,{default:e.default,key:e.key,type:m(e.default)},s=>{n(s)},{onError:()=>{n(e.default)}})}catch{return()=>{}}},S=(t,e)=>{const n=d(),[s,r]=_(e),o=m(e),u=`${t}::${o}`,f=i(u);f.current!==u&&(f.current=u,r(e));const l=i(e);return b(()=>{l.current=e}),b(()=>{let a=!1;const c=l.current;r(c);const p=F(n,{default:c,key:t},y=>{a||r(y)});return()=>{a=!0,p()}},[n,t,o]),s},h=t=>{const e=d(),[n,s]=_(t),r=K(t),o=i(r);o.current!==r&&(o.current=r,s(t));const u=i(t);return b(()=>{u.current=t}),b(()=>{let f=!1;const l=u.current;s(l);const a=[];for(const[c,p]of Object.entries(l))a.push(F(e,{default:p,key:c},y=>{f||s(R=>({...R,[c]:y}))}));return()=>{f=!0;for(const c of a)c()}},[e,r]),n};export{S as useFlag,h as useFlags};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{c as S}from"react/compiler-runtime";import{useReducer as _,useRef as v,useEffect as R}from"react";import{useLunora as b}from"./LunoraProvider-DC06S-p1.mjs";import{s as z,c as E}from"./stream-state-abygFxmy.mjs";import{s as H}from"./wire-key-p_JEwJ1j.mjs";const w=(t,c,n)=>{const e=S(24);let m;e[0]!==n?(m=n===void 0?{}:n,e[0]=n,e[1]=m):m=e[1];const o=m,f=b();let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a={chunks:[],error:void 0,status:"idle"},e[2]=a):a=e[2];const[s,i]=_(z,a),r=c==="skip";let l;e[3]!==c||e[4]!==r?(l=r?"skip":H(c),e[3]=c,e[4]=r,e[5]=l):l=e[5];const k=l,x=v(void 0);let u;e[6]!==c||e[7]!==f||e[8]!==o.maxBuffer||e[9]!==t||e[10]!==r?(u=()=>{if(r)return i({type:"reset"}),K;i({type:"reset"}),i({type:"start"});const{cancel:B,cleanup:y}=E(f.httpStream(t,c,{maxBuffer:o.maxBuffer}),i);return x.current=B,()=>{y(),x.current=void 0}},e[6]=c,e[7]=f,e[8]=o.maxBuffer,e[9]=t,e[10]=r,e[11]=u):u=e[11];let p;e[12]!==f||e[13]!==o.maxBuffer||e[14]!==t.method||e[15]!==t.path||e[16]!==k||e[17]!==r?(p=[f,t.method,t.path,k,r,o.maxBuffer],e[12]=f,e[13]=o.maxBuffer,e[14]=t.method,e[15]=t.path,e[16]=k,e[17]=r,e[18]=p):p=e[18],R(u,p);let h;e[19]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{x.current?.()},e[19]=h):h=e[19];let d;return e[20]!==s.chunks||e[21]!==s.error||e[22]!==s.status?(d={cancel:h,chunks:s.chunks,error:s.error,status:s.status},e[20]=s.chunks,e[21]=s.error,e[22]=s.status,e[23]=d):d=e[23],d};function K(){}export{w as useHttpStream};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{useMutation as C}from"@tanstack/react-query";import{useRef as R,useState as S,useCallback as p}from"react";import{useLunora as U}from"./LunoraProvider-DC06S-p1.mjs";const x=d=>{const f=U(),o=R(0),[u,c]=S(!1),M=C({mutationFn:({args:t,options:e})=>f.mutation(d,t,e),onMutate:()=>{o.current+=1,c(!0)},onSettled:()=>{o.current-=1,c(o.current>0)}}),{data:r,error:s,isError:a,mutateAsync:n,reset:i}=M,g=p((t,e)=>n({args:t,options:e}),[n]),m=p(t=>({data:r,error:s,isError:a,mutate:(l,b)=>n({args:l,options:{optimisticUpdate:t,...b}}),pending:u,reset:i,withOptimisticUpdate:m}),[n,r,s,a,u,i]);return{data:r,error:s,isError:a,mutate:g,pending:u,reset:i,withOptimisticUpdate:m}};export{x as useMutation};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{useMemo as V,useState as I,useRef as f,useEffect as d,useCallback as h}from"react";import{useLunora as A}from"./LunoraProvider-DC06S-p1.mjs";const C=()=>{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,n=>n.toString(16).padStart(2,"0")).join("")}}throw new Error("randomSessionId: no Web Crypto available — a session id needs crypto.randomUUID or crypto.getRandomValues")},_=1e4,M=(t,n)=>{const r=A(),{heartbeat:l,intervalMs:y=_,listPresent:m,shardKey:s}=n,c=V(()=>n.sessionId??C(),[n.sessionId]),[E,R]=I(void 0),[g,b]=I(void 0),v=f(n.onError);d(()=>{v.current=n.onError});const u=f(n.data),p=f({client:r,heartbeat:l,roomId:t,sessionId:c,shardKey:s});d(()=>{p.current={client:r,heartbeat:l,roomId:t,sessionId:c,shardKey:s}});const o=h(()=>{const{client:e,heartbeat:i,roomId:a,sessionId:U,shardKey:D}=p.current,L={roomId:a,sessionId:U,...u.current===void 0?{}:{data:u.current}};e.mutation(i,L,{shardKey:D}).catch(()=>{})},[]),S=h(e=>{u.current=e,o()},[o]);return d(()=>{o();const e=setInterval(o,y),i=()=>{typeof document<"u"&&document.visibilityState==="visible"&&o()};return typeof document<"u"&&document.addEventListener("visibilitychange",i),()=>{clearInterval(e),typeof document<"u"&&document.removeEventListener("visibilitychange",i)}},[o,y]),d(()=>r.acquireConnectionContext({roomId:t,sessionId:c},{shardKey:s}),[r,t,c,s]),d(()=>{let e=!1;const i=r.subscribe(m,{roomId:t},a=>{e||(R(a),b(void 0))},{onError:a=>{e||b(a),v.current?.(a)},shardKey:s});return()=>{e=!0,i()}},[r,m.__lunoraRef,t,s]),{error:g,present:E,sessionId:c,setData:S}};export{M as usePresence};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{useQueryClient as E,useQuery as b}from"@tanstack/react-query";import{useRef as I,useEffect as y,useCallback as k,useState as q}from"react";import{g as f}from"./cache-6yT0tWav.mjs";import{useLunora as K}from"./LunoraProvider-DC06S-p1.mjs";import{l as C,s as D}from"./query-key-By_ZIdza.mjs";const H=(a,c,h={})=>{const e=K(),u=E(),{onError:l,shardKey:o}=h,p=I(l);y(()=>{p.current=l});const d=k(s=>{p.current?.(s)},[]),r=c==="skip",n=r?{}:c,t=C(a,n,o),[i,Q]=q(e.isReady);y(()=>{i||e.whenReady().then(()=>{Q(!0)})},[e,i]);const g=r?void 0:e.peekHydratedQuery(a.__lunoraRef,n,o),{data:R}=b({enabled:!r&&i,initialData:g,queryFn:async()=>{const s=f(e),S=s.openSnapshotSample(t),m=await e.query(a,n,{shardKey:o});return s.closeSnapshotSample(S)?m:u.getQueryData(t)??m},queryKey:t,staleTime:Number.POSITIVE_INFINITY});return y(()=>r?()=>{}:f(e).attach(u,t,a,n,o,{onError:d}),[e,u,D(t),r,d]),r?void 0:R};export{H as default};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{c as K}from"react/compiler-runtime";import{useReducer as B,useRef as R,useEffect as _}from"react";import{useLunora as v}from"./LunoraProvider-DC06S-p1.mjs";import{s as S,c as z}from"./stream-state-abygFxmy.mjs";import{s as E}from"./wire-key-p_JEwJ1j.mjs";const A=(u,a,l)=>{const e=K(27);let c;e[0]!==l?(c=l===void 0?{}:l,e[0]=l,e[1]=c):c=e[1];const r=c,o=v();let f;e[2]===Symbol.for("react.memo_cache_sentinel")?(f={chunks:[],error:void 0,status:"idle"},e[2]=f):f=e[2];const[t,m]=B(S,f),s=a==="skip";let n;e[3]!==a||e[4]!==s?(n=s?"skip":E(a),e[3]=a,e[4]=s,e[5]=n):n=e[5];const y=n,b=R(void 0);let i;e[6]!==a||e[7]!==o||e[8]!==u||e[9]!==r.durable||e[10]!==r.maxBuffer||e[11]!==r.shardKey||e[12]!==s?(i=()=>{if(s)return m({type:"reset"}),L;m({type:"reset"}),m({type:"start"});const{cancel:k,cleanup:x}=z(o.stream(u,a,{durable:r.durable,maxBuffer:r.maxBuffer,shardKey:r.shardKey}),m);return b.current=k,()=>{x(),b.current=void 0}},e[6]=a,e[7]=o,e[8]=u,e[9]=r.durable,e[10]=r.maxBuffer,e[11]=r.shardKey,e[12]=s,e[13]=i):i=e[13];let d;e[14]!==o||e[15]!==u.__lunoraRef||e[16]!==r.durable||e[17]!==r.maxBuffer||e[18]!==r.shardKey||e[19]!==y||e[20]!==s?(d=[o,u.__lunoraRef,y,s,r.shardKey,r.maxBuffer,r.durable],e[14]=o,e[15]=u.__lunoraRef,e[16]=r.durable,e[17]=r.maxBuffer,e[18]=r.shardKey,e[19]=y,e[20]=s,e[21]=d):d=e[21],_(i,d);let p;e[22]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{b.current?.()},e[22]=p):p=e[22];let h;return e[23]!==t.chunks||e[24]!==t.error||e[25]!==t.status?(h={cancel:p,chunks:t.chunks,error:t.error,status:t.status},e[23]=t.chunks,e[24]=t.error,e[25]=t.status,e[26]=h):h=e[26],h};function L(){}export{A as useStream};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{c as x}from"react/compiler-runtime";import{createQuerySubscription as A}from"@lunora/client/query";import{LunoraError as D}from"@lunora/errors";import{useState as F,useRef as S,useEffect as v}from"react";import{useLunora as M}from"./LunoraProvider-DC06S-p1.mjs";import{s as Q}from"./wire-key-p_JEwJ1j.mjs";const H=(o,r,a)=>{const e=x(24);let l;e[0]!==a?(l=a===void 0?{}:a,e[0]=a,e[1]=l):l=e[1];const t=l,n=M();let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={data:void 0,error:void 0},e[2]=c):c=e[2];const[k,E]=F(c),s=r==="skip";let d;e[3]!==r||e[4]!==s?(d=s?"skip":Q(r),e[3]=r,e[4]=s,e[5]=d):d=e[5];const b=d,K=S(t.onError);let f;e[6]!==t.onError?(f=()=>{K.current=t.onError},e[6]=t.onError,e[7]=f):f=e[7],v(f);let u;e[8]!==r||e[9]!==o?(u={args:r,fn:o},e[8]=r,e[9]=o,e[10]=u):u=e[10];const R=S(u);let m;e[11]!==r||e[12]!==o?(m=()=>{R.current={args:r,fn:o}},e[11]=r,e[12]=o,e[13]=m):m=e[13],v(m);let p;e[14]!==n||e[15]!==t.shardKey||e[16]!==s?(p=()=>{if(s)return E({data:void 0,error:void 0}),W;let h=!1;const{args:w,fn:z}=R.current,L=A(n,z,w,{onData:i=>{h||E({data:i,error:void 0})},onError:i=>{const q=i.code===void 0?new Error(i.message):new D(i.code,i.message);K.current?.(i),queueMicrotask(()=>{h||E({data:void 0,error:q})})}},{shardKey:t.shardKey});return()=>{h=!0,L()}},e[14]=n,e[15]=t.shardKey,e[16]=s,e[17]=p):p=e[17];let y;return e[18]!==n||e[19]!==o.__lunoraRef||e[20]!==t.shardKey||e[21]!==b||e[22]!==s?(y=[n,o.__lunoraRef,b,t.shardKey,s],e[18]=n,e[19]=o.__lunoraRef,e[20]=t.shardKey,e[21]=b,e[22]=s,e[23]=y):y=e[23],v(p,y),k};function W(){}export{H as default};
@@ -1,2 +0,0 @@
1
- 'use client';
2
- import{useState as T,useRef as W,useCallback as y,useEffect as G}from"react";import{useLunora as X}from"./LunoraProvider-DC06S-p1.mjs";const N="/_lunora/ws",j="/_lunora/voice/",z=4001,O=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,Q=e=>{const r=e.startsWith("agents:")?e.slice(7):e;return r.endsWith("Voice")?r.slice(0,-5):r},Y=(e,r)=>{if(r===void 0||r==="")return O(e);if(r.endsWith(N))return r.slice(0,-N.length);try{return new URL(r).origin}catch{return O(e)}},Z=e=>{const r=Y(e.httpUrl,e.wsUrl),o=r.endsWith("/")?r.slice(0,-1):r,i=new URLSearchParams({threadKey:e.threadKey});return`${o}${j}${encodeURIComponent(e.agent)}?${i.toString()}`},ee=(e,r)=>{if(r?.code===z)return new Error(`${e}: authentication token expired — refresh the credential and start a new call`)},te=(e,r,o)=>{const i=e.currentIdentity();return e.onAuthTokenChange(()=>{e.currentIdentity()!==i&&o(new Error(`${r}: the signed-in identity changed during the call — the session was ended; start a new call`))})},ne=16e3,re=e=>{if(e.length===0)return 0;let r=0;for(const o of e)r+=o*o;return Math.sqrt(r/e.length)},oe=(e,r)=>{const o=r/ne,i=o>1?Math.floor(e.length/o):e.length,d=new ArrayBuffer(i*2),l=new DataView(d);for(let u=0;u<i;u+=1){const g=e[Math.floor(u*o)]??0,p=Math.max(-1,Math.min(1,g));l.setInt16(u*2,p<0?p*32768:p*32767,!0)}return new Uint8Array(d)},se=async e=>{const r=globalThis,o=r.navigator?.mediaDevices?.getUserMedia.bind(r.navigator.mediaDevices),i=r.AudioContext??r.webkitAudioContext;if(!o||!i)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const d=await o({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),l=new i,u=l.createMediaStreamSource(d),g=l.createScriptProcessor(4096,1,1);let p=!1,w=!1,a=0,h=0;return g.onaudioprocess=s=>{const f=s.inputBuffer.getChannelData(0),m=p?0:re(f);if(e.onLevel(m),p)return;if(e.onAudio(oe(f,l.sampleRate)),e.isTurnActive()){h=m>=e.interruptThreshold?h+1:0,h>=e.interruptChunks&&(h=0,e.onInterrupt());return}h=0;const x=f.length/l.sampleRate*1e3;if(m>=e.silenceThreshold){w=!0,a=0;return}w&&(a+=x,a>=e.silenceDurationMs&&(w=!1,a=0,e.onSilence()))},u.connect(g),g.connect(l.destination),{setMuted:s=>{p=s},stop:()=>{g.disconnect(),u.disconnect();for(const s of d.getTracks())s.stop();l.close()}}},ce=()=>{const e=globalThis,r=e.AudioContext??e.webkitAudioContext;if(!r)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const o=new r,i=new Set;let d=0,l=Promise.resolve(),u=0;const g=async(a,h)=>{if(h!==u)return;let s;try{s=await o.decodeAudioData(a.buffer)}catch{return}if(h!==u)return;const f=o.createBufferSource();f.buffer=s,f.connect(o.destination);const m=Math.max(o.currentTime,d);f.start(m),d=m+s.duration,i.add(f),f.onended=()=>{i.delete(f)}},p=a=>{const h=Uint8Array.from(a),s=u;l=l.then(()=>g(h,s))},w=()=>{u+=1;for(const a of i)try{a.stop()}catch{}i.clear(),d=o.currentTime};return{enqueue:p,interrupt:w,stop:()=>{w(),o.close()}}},P=1,ie=.01,ae=1200,ue=.15,le=3,he=e=>{const{createMicrophone:r=se,createSpeaker:o=ce,createSocket:i,interruptChunks:d=le,interruptThreshold:l=ue,silenceDurationMs:u=ae,silenceThreshold:g=ie,threadKey:p,voice:w}=e,a=X(),[h,s]=T("idle"),[f,m]=T(!1),[x,M]=T(""),[H,b]=T(""),[$,R]=T(0),[I,U]=T(!1),[B,E]=T(void 0),c=W(void 0),_=W(!1),v=y(t=>{const n=c.current?.socket;return n?.readyState===P?(n.send(JSON.stringify(t)),!0):!1},[]),A=y(()=>{const t=c.current;if(c.current=void 0,t){t.unwatchIdentity?.(),t.microphone?.stop(),t.speaker?.stop(),t.socket.onmessage=null,t.socket.onerror=null,t.socket.onclose=null;try{t.socket.close()}catch{}}_.current=!1,m(!1),s("idle"),R(0)},[]),L=y(t=>{const n=c.current;switch(t.type){case"assistant_delta":{n&&(n.speaking=!0),s("speaking"),b(F=>F+t.text);break}case"assistant_done":{n&&(n.awaitingTurn=!1,n.speaking=!1),b(t.text),s("listening");break}case"error":{n&&(n.awaitingTurn=!1,n.speaking=!1),E(new Error(t.message)),s("listening");break}case"interrupted":{n&&(n.awaitingTurn=!1,n.speaking=!1,n.suppressAudio=!1),n?.speaker?.interrupt(),s("listening");break}case"ready":{n&&(n.audioFormat=t.audioFormat,n.suppressAudio=!1),m(!0),s("listening");break}case"user_transcript":{n&&(n.suppressAudio=!1),M(t.text),b(""),s("thinking");break}}},[]),D=y(t=>{const n=c.current;!n||n.suppressAudio||(n.speaker??=o({audioFormat:n.audioFormat}),n.speaking=!0,s("speaking"),n.speaker.enqueue(t))},[o]),q=y(async()=>{if(c.current||_.current)return;_.current=!0,E(void 0),M(""),b("");let t;try{const n=Z({agent:Q(w.__lunoraRef),httpUrl:a.url,threadKey:p,wsUrl:a.wsUrl}),S=(i??(k=>{const C=a.getWebSocketImpl();if(!C)throw new Error("useVoiceAgent: no WebSocket implementation available (pass createSocket explicitly)");return new C(k)}))(n);S.binaryType="arraybuffer",t={audioFormat:"mp3",microphone:void 0,socket:S,speaker:void 0,speaking:!1,awaitingTurn:!1,suppressAudio:!1,unwatchIdentity:void 0},c.current=t,t.unwatchIdentity=te(a,"useVoiceAgent",k=>{c.current===t&&(E(k),A())}),S.onmessage=k=>{if(typeof k.data=="string"){try{L(JSON.parse(k.data))}catch{}return}D(new Uint8Array(k.data))},S.onerror=()=>{E(new Error("useVoiceAgent: voice socket error"))},S.onclose=k=>{if(c.current!==t)return;const C=ee("useVoiceAgent",k);C&&E(C),A()};const V=await r({interruptChunks:d,interruptThreshold:l,isTurnActive:()=>(c.current?.speaking??!1)||(c.current?.awaitingTurn??!1),onAudio:k=>{S.readyState===P&&S.send(k)},onInterrupt:()=>{v({type:"interrupt"}),c.current?.speaker?.interrupt(),c.current&&(c.current.awaitingTurn=!1,c.current.speaking=!1,c.current.suppressAudio=!0),s("listening")},onLevel:R,onSilence:()=>{v({type:"commit"}),c.current&&(c.current.awaitingTurn=!0),s("thinking")},silenceDurationMs:u,silenceThreshold:g});c.current===t?(t.microphone=V,U(!1),t.speaking||s("listening")):V.stop()}catch(n){c.current===t&&(E(n instanceof Error?n:new Error(String(n))),A())}finally{_.current=!1}},[a,r,i,D,L,d,l,v,u,g,A,p,w]),K=y(()=>{const t=!I;return c.current?.microphone?.setMuted(t),U(t),t},[I]),J=y(t=>{v({text:t,type:"text"})&&(c.current&&(c.current.awaitingTurn=!0),s("thinking"))},[v]);return G(()=>A,[A]),{audioLevel:$,connected:f,endCall:A,error:B,interimTranscript:H,isMuted:I,sendText:J,startCall:q,status:h,toggleMute:K,transcript:x}};export{he as useVoiceAgent};
@@ -1 +0,0 @@
1
- import{s as g}from"./stable-key-B_BlboiY.mjs";const y=r=>{let n="";for(let c=0;c<r.length;c+=32768)n+=String.fromCharCode(...r.subarray(c,c+32768));return btoa(n)},t="$lunora.wire$",d=64,m="__proto__",p=r=>{if(r===null||typeof r!="object")return!1;const n=Object.getPrototypeOf(r);return n===null||n===Object.prototype},i=(r,n=0)=>{if(n>d)throw new RangeError(`wire-codec: value nesting exceeds the ${d}-level limit`);if(r===void 0)return[t,"undefined"];if(r===null)return null;const a=typeof r;if(a==="bigint")return[t,"bigint",r.toString()];if(a==="number"){const e=r;return Number.isNaN(e)?[t,"nan"]:e===1/0?[t,"inf"]:e===-1/0?[t,"-inf"]:e}if(a!=="object")return r;if(r instanceof Date)return[t,"date",i(r.getTime(),n+1)];if(r instanceof Error){const e=r,o={};for(const f of Object.keys(e)){if(e[f]===void 0)continue;const b=i(e[f],n+1);f===m?Object.defineProperty(o,f,{configurable:!0,enumerable:!0,value:b,writable:!0}):o[f]=b}const s=[t,"error",String(e.name),String(e.message),o];return e.cause!==void 0&&s.push(i(e.cause,n+1)),s}if(r instanceof URL)return[t,"url",r.href];if(r instanceof Map)return[t,"map",[...r.entries()].map(([e,o])=>[i(e,n+1),i(o,n+1)])];if(r instanceof Set)return[t,"set",[...r].map(e=>i(e,n+1))];if(r instanceof ArrayBuffer)return[t,"bytes",y(new Uint8Array(r)),"ArrayBuffer"];if(ArrayBuffer.isView(r)){const e=r,o=e.constructor.name,s=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return o==="Uint8Array"?[t,"bytes",y(s)]:[t,"bytes",y(s),o]}if(Array.isArray(r)){const e=r.map(o=>i(o,n+1));return e.length>0&&e[0]===t?[t,"arr",e]:e}if(!p(r)){const e=r.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${e} 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 c=r,u={};for(const e of Object.keys(c)){const o=c[e];if(o===void 0)continue;const s=i(o,n+1);e===m?Object.defineProperty(u,e,{configurable:!0,enumerable:!0,value:s,writable:!0}):u[e]=s}return u},l=r=>g(i(r));export{l as s};