@lunora/react 1.0.0-alpha.8 → 1.0.0-alpha.81

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 (73) hide show
  1. package/LICENSE.md +6 -0
  2. package/README.md +25 -18
  3. package/dist/index.d.mts +1127 -355
  4. package/dist/index.d.ts +1127 -355
  5. package/dist/index.mjs +1 -18
  6. package/dist/packem_shared/AuthLoading-dC08yqew.mjs +2 -0
  7. package/dist/packem_shared/LunoraProvider-DC06S-p1.mjs +2 -0
  8. package/dist/packem_shared/cache-DmbajSjf.mjs +1 -0
  9. package/dist/packem_shared/hydratePreloaded-CcBW4phD.mjs +2 -0
  10. package/dist/packem_shared/lunoraQueryOptions-B5PEocLy.mjs +1 -0
  11. package/dist/packem_shared/query-key-C6iUhRuD.mjs +1 -0
  12. package/dist/packem_shared/query-options.d-CdgGQ9s4.d.mts +38 -0
  13. package/dist/packem_shared/query-options.d-CdgGQ9s4.d.ts +38 -0
  14. package/dist/packem_shared/stable-key-B_BlboiY.mjs +1 -0
  15. package/dist/packem_shared/stream-state-abygFxmy.mjs +1 -0
  16. package/dist/packem_shared/use-paginated-core-CWfn4qb4.mjs +2 -0
  17. package/dist/packem_shared/useAction-CUSJu4yq.mjs +2 -0
  18. package/dist/packem_shared/useAgent-CNDRZNk_.mjs +2 -0
  19. package/dist/packem_shared/useAgentChat-CXJldvLG.mjs +2 -0
  20. package/dist/packem_shared/useAgentState-BOIQjgxe.mjs +2 -0
  21. package/dist/packem_shared/useAgentToolEvents-B4gy1Q5z.mjs +2 -0
  22. package/dist/packem_shared/useAuth-x4boOoAR.mjs +2 -0
  23. package/dist/packem_shared/useAuthSessions-Bq4-f3g-.mjs +2 -0
  24. package/dist/packem_shared/useAuthState-CoOG9XdT.mjs +2 -0
  25. package/dist/packem_shared/useClientQuery-DFs7trEf.mjs +2 -0
  26. package/dist/packem_shared/useConnectionStatus-XYsYGiT6.mjs +2 -0
  27. package/dist/packem_shared/useFlag-BDM923ke.mjs +2 -0
  28. package/dist/packem_shared/useHttpStream-D9vum8Qx.mjs +2 -0
  29. package/dist/packem_shared/useInfiniteQuery-C7wp0W2d.mjs +2 -0
  30. package/dist/packem_shared/useMutation-BnKec7bE.mjs +2 -0
  31. package/dist/packem_shared/useMutator-BtUd-xEA.mjs +2 -0
  32. package/dist/packem_shared/usePaginatedQuery-DJNa8KKD.mjs +2 -0
  33. package/dist/packem_shared/usePresence-BVjZyltT.mjs +2 -0
  34. package/dist/packem_shared/useQuery-BUzNP_Vb.mjs +2 -0
  35. package/dist/packem_shared/useRateLimit-Cckxi8m9.mjs +2 -0
  36. package/dist/packem_shared/useStream-CmGOT0qj.mjs +2 -0
  37. package/dist/packem_shared/useSubscription-BHVICtbD.mjs +2 -0
  38. package/dist/packem_shared/useVoiceAgent-C9NI6Vzl.mjs +2 -0
  39. package/dist/packem_shared/wire-key-L5JSXhhG.mjs +1 -0
  40. package/dist/payment.d.mts +93 -0
  41. package/dist/payment.d.ts +93 -0
  42. package/dist/payment.mjs +2 -0
  43. package/dist/server.d.mts +47 -29
  44. package/dist/server.d.ts +47 -29
  45. package/dist/server.mjs +1 -31
  46. package/dist/upload.d.mts +23 -0
  47. package/dist/upload.d.ts +23 -0
  48. package/dist/upload.mjs +2 -0
  49. package/package.json +14 -4
  50. package/dist/packem_shared/AuthLoading-DtKgZT2Z.mjs +0 -33
  51. package/dist/packem_shared/CheckoutButton-CVSry8U1.mjs +0 -185
  52. package/dist/packem_shared/LunoraProvider-D38Xp16l.mjs +0 -80
  53. package/dist/packem_shared/cache-CAp1fVNL.mjs +0 -75
  54. package/dist/packem_shared/hydratePreloaded-B6OHn0eL.mjs +0 -46
  55. package/dist/packem_shared/lunoraQueryOptions-Cij4KWBK.mjs +0 -16
  56. package/dist/packem_shared/query-key-B5eRQCbR.mjs +0 -13
  57. package/dist/packem_shared/query-options.d-D4okOpO8.d.mts +0 -38
  58. package/dist/packem_shared/query-options.d-D4okOpO8.d.ts +0 -38
  59. package/dist/packem_shared/stable-key-CaKZv9lp.mjs +0 -30
  60. package/dist/packem_shared/use-paginated-core-DP72UNWn.mjs +0 -176
  61. package/dist/packem_shared/useAuth-CNUKtOOp.mjs +0 -129
  62. package/dist/packem_shared/useAuthState-BiGhtSCs.mjs +0 -36
  63. package/dist/packem_shared/useConnectionStatus-DRSY9ldm.mjs +0 -30
  64. package/dist/packem_shared/useFlag-Bg5DpkGv.mjs +0 -224
  65. package/dist/packem_shared/useInfiniteQuery-BBIDFXBN.mjs +0 -97
  66. package/dist/packem_shared/useMutation-CrvMXRsk.mjs +0 -67
  67. package/dist/packem_shared/useMutator-IIrLtDiM.mjs +0 -47
  68. package/dist/packem_shared/usePaginatedQuery-AQO3kdp1.mjs +0 -46
  69. package/dist/packem_shared/usePresence-D7jLuxj0.mjs +0 -108
  70. package/dist/packem_shared/useQuery-EB74gtBJ.mjs +0 -42
  71. package/dist/packem_shared/useRateLimit-DTEffQEi.mjs +0 -64
  72. package/dist/packem_shared/useStream-MdYnWDL_.mjs +0 -125
  73. package/dist/packem_shared/useSubscription-DSJuryrU.mjs +0 -139
package/dist/index.mjs CHANGED
@@ -1,19 +1,2 @@
1
1
  'use client';
2
- export { AuthLoading, Authenticated, Unauthenticated } from './packem_shared/AuthLoading-DtKgZT2Z.mjs';
3
- export { useAuthState } from './packem_shared/useAuthState-BiGhtSCs.mjs';
4
- export { LunoraProvider, useLunora } from './packem_shared/LunoraProvider-D38Xp16l.mjs';
5
- export { CheckoutButton, CustomerPortalButton, useCheckout } from './packem_shared/CheckoutButton-CVSry8U1.mjs';
6
- export { lunoraQueryOptions } from './packem_shared/lunoraQueryOptions-Cij4KWBK.mjs';
7
- export { default as useAuth } from './packem_shared/useAuth-CNUKtOOp.mjs';
8
- export { default as useConnectionStatus } from './packem_shared/useConnectionStatus-DRSY9ldm.mjs';
9
- export { useFlag, useFlags } from './packem_shared/useFlag-Bg5DpkGv.mjs';
10
- export { default as useInfiniteQuery } from './packem_shared/useInfiniteQuery-BBIDFXBN.mjs';
11
- export { useMutation } from './packem_shared/useMutation-CrvMXRsk.mjs';
12
- export { useMutator } from './packem_shared/useMutator-IIrLtDiM.mjs';
13
- export { usePaginatedQuery } from './packem_shared/usePaginatedQuery-AQO3kdp1.mjs';
14
- export { hydratePreloaded, default as usePreloadedQuery } from './packem_shared/hydratePreloaded-B6OHn0eL.mjs';
15
- export { usePresence } from './packem_shared/usePresence-D7jLuxj0.mjs';
16
- export { default as useQuery } from './packem_shared/useQuery-EB74gtBJ.mjs';
17
- export { useRateLimit } from './packem_shared/useRateLimit-DTEffQEi.mjs';
18
- export { useStream } from './packem_shared/useStream-MdYnWDL_.mjs';
19
- export { default as useSubscription } from './packem_shared/useSubscription-DSJuryrU.mjs';
2
+ import{AuthLoading as o,Authenticated as t,Unauthenticated as u}from"./packem_shared/AuthLoading-dC08yqew.mjs";import{useAuthState as a}from"./packem_shared/useAuthState-CoOG9XdT.mjs";import{LunoraProvider as f,useLunora as n}from"./packem_shared/LunoraProvider-DC06S-p1.mjs";import{lunoraQueryOptions as m}from"./packem_shared/lunoraQueryOptions-B5PEocLy.mjs";import{useAction as x}from"./packem_shared/useAction-CUSJu4yq.mjs";import{useAuthSessions as A,useAuthUsers as g,useImpersonate as h,useOrganizations as c}from"./packem_shared/useAuthSessions-Bq4-f3g-.mjs";import{useAgent as y}from"./packem_shared/useAgent-CNDRZNk_.mjs";import{useAgentChat as E}from"./packem_shared/useAgentChat-CXJldvLG.mjs";import{useAgentState as S}from"./packem_shared/useAgentState-BOIQjgxe.mjs";import{useAgentToolEvents as L}from"./packem_shared/useAgentToolEvents-B4gy1Q5z.mjs";import{default as F}from"./packem_shared/useAuth-x4boOoAR.mjs";import{default as I}from"./packem_shared/useClientQuery-DFs7trEf.mjs";import{default as v}from"./packem_shared/useConnectionStatus-XYsYGiT6.mjs";import{useFlag as O,useFlags as T}from"./packem_shared/useFlag-BDM923ke.mjs";import{useHttpStream as H}from"./packem_shared/useHttpStream-D9vum8Qx.mjs";import{default as j}from"./packem_shared/useInfiniteQuery-C7wp0W2d.mjs";import{useMutation as w}from"./packem_shared/useMutation-BnKec7bE.mjs";import{useMutator as D}from"./packem_shared/useMutator-BtUd-xEA.mjs";import{usePaginatedQuery as J}from"./packem_shared/usePaginatedQuery-DJNa8KKD.mjs";import{hydratePreloaded as N,default as W}from"./packem_shared/hydratePreloaded-CcBW4phD.mjs";import{usePresence as Y}from"./packem_shared/usePresence-BVjZyltT.mjs";import{default as _}from"./packem_shared/useQuery-BUzNP_Vb.mjs";import{useRateLimit as ee}from"./packem_shared/useRateLimit-Cckxi8m9.mjs";import{useStream as oe}from"./packem_shared/useStream-CmGOT0qj.mjs";import{default as ue}from"./packem_shared/useSubscription-BHVICtbD.mjs";import{useVoiceAgent as ae}from"./packem_shared/useVoiceAgent-C9NI6Vzl.mjs";import{createClientQuery as fe,getErrorCode as ne,getRetryAfterMs as ie,isConflictError as me,isForbiddenError as de,isRateLimitedError as xe,isUnauthorizedError as le}from"@lunora/client";import{RestrictionError as ge,UploadControl as he,UploadError as ce}from"@visulima/storage-client";import{useChunkedRestUpload as ye,useFileInput as Ce,useMultipartUpload as Ee,usePasteUpload as Qe,useTusUpload as Se,useUpload as Pe}from"@visulima/storage-client/react";export{o as AuthLoading,t as Authenticated,f as LunoraProvider,ge as RestrictionError,u as Unauthenticated,he as UploadControl,ce as UploadError,fe as createClientQuery,ne as getErrorCode,ie as getRetryAfterMs,N as hydratePreloaded,me as isConflictError,de as isForbiddenError,xe as isRateLimitedError,le as isUnauthorizedError,m as lunoraQueryOptions,x as useAction,y as useAgent,E as useAgentChat,S as useAgentState,L as useAgentToolEvents,F as useAuth,A as useAuthSessions,a as useAuthState,g as useAuthUsers,ye as useChunkedRestUpload,I as useClientQuery,v as useConnectionStatus,Ce as useFileInput,O as useFlag,T as useFlags,H as useHttpStream,h as useImpersonate,j as useInfiniteQuery,n as useLunora,Ee as useMultipartUpload,w as useMutation,D as useMutator,c as useOrganizations,J as usePaginatedQuery,Qe as usePasteUpload,W as usePreloadedQuery,Y as usePresence,_ as useQuery,ee as useRateLimit,oe as useStream,ue as useSubscription,Se as useTusUpload,Pe as useUpload,ae as useVoiceAgent};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{useAuthState as o}from"./useAuthState-CoOG9XdT.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,2 @@
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};
@@ -0,0 +1 @@
1
+ import{k as u}from"./query-key-C6iUhRuD.mjs";class g{constructor(e){this.client=e}client;entries=new Map;keyOf(e){return u(e)}attach(e,c,f,b,h,k={}){const s=u(c);let r=this.entries.get(s);if(!r){r={errorCallbacks:new Set,refCount:0,unsubscribe:void 0},this.entries.set(s,r);const t=r;try{r.unsubscribe=this.client.subscribe(f,b,n=>{e.setQueryData(c,n)},{onError:n=>{for(const d of t.errorCallbacks)d(n)},shardKey:h})}catch(n){throw this.entries.delete(s),n}}r.refCount+=1;const{onError:o}=k;o&&r.errorCallbacks.add(o);let a=!1;return()=>{if(a)return;a=!0;const t=this.entries.get(s);t&&(t.refCount-=1,o&&t.errorCallbacks.delete(o),t.refCount<=0&&(t.unsubscribe?.(),this.entries.delete(s)))}}}const l=new WeakMap,C=i=>{let e=l.get(i);return e||(e=new g(i),l.set(i,e)),e};export{C as g};
@@ -0,0 +1,2 @@
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-DmbajSjf.mjs";import{useLunora as v}from"./LunoraProvider-DC06S-p1.mjs";import{l as N,s as S}from"./query-key-C6iUhRuD.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};
@@ -0,0 +1 @@
1
+ import{l as u}from"./query-key-C6iUhRuD.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
+ import{s as r}from"./wire-key-L5JSXhhG.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};
@@ -0,0 +1,38 @@
1
+ import { FunctionReference, ReturnOf, LunoraClient, ArgsOf } from '@lunora/client';
2
+ import { QueryKey } from '@tanstack/react-query';
3
+ /**
4
+ * Pure, transport-free adapter between a Lunora function reference and a
5
+ * TanStack Query options object. No `"use client"` directive and only a
6
+ * type-level `@lunora/client` import, so it is safe to use on either side of an
7
+ * RSC boundary (the runtime transport is the `LunoraClient` you pass in).
8
+ *
9
+ * Use it when you want to drive a Lunora query through TanStack's own hooks —
10
+ * `useSuspenseQuery`, `useQueries`, or the server-side
11
+ * `queryClient.ensureQueryData` / `prefetchQuery` — rather than the first-class
12
+ * `useQuery` from `@lunora/react`.
13
+ */
14
+ /** Shape returned by `lunoraQueryOptions`, spread into a TanStack hook. */
15
+ interface LunoraQueryOptions<F extends FunctionReference> {
16
+ queryFn: () => Promise<ReturnOf<F>>;
17
+ queryKey: QueryKey;
18
+ staleTime: number;
19
+ }
20
+ /**
21
+ * Build a TanStack Query options object for a Lunora query, keyed identically
22
+ * to the first-class hooks (see `lunoraQueryKey`) so a value fetched through
23
+ * this adapter shares cache identity with anything `useQuery` /
24
+ * `prefetchQuery` reads or writes for the same `(fn, args, shardKey)` triple.
25
+ *
26
+ * ```ts
27
+ * const { data } = useSuspenseQuery(lunoraQueryOptions(client, api.posts.list, {}));
28
+ * ```
29
+ *
30
+ * This is a one-shot fetch: it resolves once and `staleTime` is infinite, so
31
+ * TanStack never refetches on its own. It does not open a WebSocket — for live
32
+ * updates that re-render on every server push, use `useQuery` from
33
+ * `@lunora/react`, which attaches a shared subscription to the same cache key.
34
+ */
35
+ declare const lunoraQueryOptions: <F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F>, options?: {
36
+ shardKey?: string;
37
+ }) => LunoraQueryOptions<F>;
38
+ export { LunoraQueryOptions as L, lunoraQueryOptions as l };
@@ -0,0 +1,38 @@
1
+ import { FunctionReference, ReturnOf, LunoraClient, ArgsOf } from '@lunora/client';
2
+ import { QueryKey } from '@tanstack/react-query';
3
+ /**
4
+ * Pure, transport-free adapter between a Lunora function reference and a
5
+ * TanStack Query options object. No `"use client"` directive and only a
6
+ * type-level `@lunora/client` import, so it is safe to use on either side of an
7
+ * RSC boundary (the runtime transport is the `LunoraClient` you pass in).
8
+ *
9
+ * Use it when you want to drive a Lunora query through TanStack's own hooks —
10
+ * `useSuspenseQuery`, `useQueries`, or the server-side
11
+ * `queryClient.ensureQueryData` / `prefetchQuery` — rather than the first-class
12
+ * `useQuery` from `@lunora/react`.
13
+ */
14
+ /** Shape returned by `lunoraQueryOptions`, spread into a TanStack hook. */
15
+ interface LunoraQueryOptions<F extends FunctionReference> {
16
+ queryFn: () => Promise<ReturnOf<F>>;
17
+ queryKey: QueryKey;
18
+ staleTime: number;
19
+ }
20
+ /**
21
+ * Build a TanStack Query options object for a Lunora query, keyed identically
22
+ * to the first-class hooks (see `lunoraQueryKey`) so a value fetched through
23
+ * this adapter shares cache identity with anything `useQuery` /
24
+ * `prefetchQuery` reads or writes for the same `(fn, args, shardKey)` triple.
25
+ *
26
+ * ```ts
27
+ * const { data } = useSuspenseQuery(lunoraQueryOptions(client, api.posts.list, {}));
28
+ * ```
29
+ *
30
+ * This is a one-shot fetch: it resolves once and `staleTime` is infinite, so
31
+ * TanStack never refetches on its own. It does not open a WebSocket — for live
32
+ * updates that re-render on every server push, use `useQuery` from
33
+ * `@lunora/react`, which attaches a shared subscription to the same cache key.
34
+ */
35
+ declare const lunoraQueryOptions: <F extends FunctionReference>(client: LunoraClient, function_: F, args: ArgsOf<F>, options?: {
36
+ shardKey?: string;
37
+ }) => LunoraQueryOptions<F>;
38
+ export { LunoraQueryOptions as L, lunoraQueryOptions as l };
@@ -0,0 +1 @@
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};
@@ -0,0 +1 @@
1
+ const u=function(r,e){switch(e.type){case"chunk":return{chunks:[...r.chunks,e.chunk],error:void 0,status:"streaming"};case"complete":return{...r,status:"complete"};case"error":return{...r,error:e.error,status:"error"};case"reset":return{chunks:[],error:void 0,status:"idle"};case"start":return{...r,status:"streaming"};default:return r}},o=function(r,e){let n=!0,c=!1;const s=()=>{c||(c=!0,r.cancel())};return(async()=>{try{for await(const t of r){if(!n)return;e({chunk:t,type:"chunk"})}n&&e({type:"complete"})}catch(t){if(!n)return;e({error:t instanceof Error?t:new Error(String(t)),type:"error"})}})().catch(()=>{}),{cancel:s,cleanup:()=>{n=!1,s()}}};export{o as c,u as s};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{initialPages as x,rebalance as N,derivePaginationStatus as D,applyLoadMore as T}from"@lunora/client/pagination";import{useQueryClient as B}from"@tanstack/react-query";import{useRef as m,useReducer as G,useState as F,useEffect as y,useCallback as J}from"react";import{g as U}from"./cache-DmbajSjf.mjs";import{useLunora as V}from"./LunoraProvider-DC06S-p1.mjs";import{s as u,l as v}from"./query-key-C6iUhRuD.mjs";const W=function(i){const l=m(void 0);return l.current??=i(),l},te=function(i,l,C){const f=V(),c=B(),{initialNumItems:R,shardKey:p}=C,d=l==="skip",g=d?{}:l,[,O]=G(e=>e+1,0),[q,h]=F(()=>x(R)),[z,k]=F(void 0),w=m(C.onError);y(()=>{w.current=C.onError});const Q=`${u(v(i,g,p))}::${String(R)}`,A=m(Q);A.current!==Q&&(A.current=Q,h(x(R)),k(void 0));const K=q.map(e=>{const t={...g,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}},r=v(i,t,p);return{args:t,key:r}}),P=K.map(({key:e})=>u(e)).join("|"),b=m({baseArgs:g,entries:[],fn:i,shardKey:p});y(()=>{b.current={baseArgs:g,entries:K,fn:i,shardKey:p}});const L=(e,t,r)=>{k(r),h(o=>{const s=b.current,n=o.at(-1);if(o.length<=1||!n||c.getQueryData(t)!==void 0)return o;const S={...s.baseArgs,paginationOpts:{cursor:n.lower,endCursor:n.upper,numItems:n.numItems}};return u(v(s.fn,S,s.shardKey))===e?o.slice(0,-1):o}),w.current?.(r)},E=W(()=>new Map),M=m(f);y(()=>{const e=E.current;if(M.current!==f){for(const s of e.values())s();e.clear(),M.current=f}if(d){for(const s of e.values())s();e.clear();return}const t=b.current,r=U(f),o=new Set(t.entries.map(({key:s})=>u(s)));for(const[s,n]of e)o.has(s)||(n(),e.delete(s));for(const s of t.entries){const n=u(s.key);if(e.has(n))continue;c.fetchQuery({queryFn:()=>f.query(t.fn,s.args,{shardKey:t.shardKey}),queryKey:s.key,staleTime:0}).catch(a=>{L(n,s.key,a instanceof Error?{code:a.code,message:a.message}:{message:String(a)})}),e.set(n,r.attach(c,s.key,t.fn,s.args,t.shardKey,{onError:a=>{L(n,s.key,a)}}))}},[f,c,P,d]),y(()=>()=>{for(const e of E.current.values())e();E.current.clear()},[]),y(()=>c.getQueryCache().subscribe(r=>{if(r.type!=="updated")return;const o=u(r.query.queryKey);K.some(({key:s})=>u(s)===o)&&(k(void 0),O())}),[c,P]);const I=d?[]:K.map(({key:e})=>c.getQueryData(e));y(()=>{if(d)return;const e=N(q,I);e&&h(e)});const{status:$}=D(d,I),j=J(e=>{k(void 0),h(t=>{const r=b.current,o=t.map(a=>{const H={...r.baseArgs,paginationOpts:{cursor:a.lower,endCursor:a.upper,numItems:a.numItems}};return c.getQueryData(v(r.fn,H,r.shardKey))}),{nextCursor:s,status:n}=D(!1,o);return T(t,n==="CanLoadMore"?s:void 0,e)??t})},[c]);return{error:z,loadMore:j,pageResults:I,status:$}};export{te 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{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};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as N}from"react/compiler-runtime";import{useMutation as R}from"./useMutation-BnKec7bE.mjs";import O from"./useSubscription-BHVICtbD.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};
@@ -0,0 +1,2 @@
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-CmGOT0qj.mjs";import A from"./useSubscription-BHVICtbD.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};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as o}from"react/compiler-runtime";import d from"./useSubscription-BHVICtbD.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};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as y}from"react/compiler-runtime";import{useStream as I}from"./useStream-CmGOT0qj.mjs";import N from"./useSubscription-BHVICtbD.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 b}from"react/compiler-runtime";import{useSyncExternalStore as g}from"react";import{useLunora as p}from"./LunoraProvider-DC06S-p1.mjs";const k=new WeakMap,S=e=>{const t=new Set;let o=null;const i=()=>{for(const n of t)n()};let s=0;const r=n=>{o!==n&&(o=n,i())},l=()=>{s+=1;const n=s;if(e.getAuthToken()===null){r(null);return}e.getCurrentUser().then(u=>{n===s&&r(u)}).catch(()=>{n===s&&r(null)})};let c;return{getSnapshot:()=>o,subscribe:n=>{const u=t.size===0;return t.add(n),u&&(c=e.onAuthTokenChange(l),l()),()=>{t.delete(n),t.size===0&&(c?.(),c=void 0)}}}},T=e=>{let t=k.get(e);return t||(t=S(e),k.set(e,t)),t},w=()=>{const e=b(12),t=p();let o;e[0]!==t?(o=T(t),e[0]=t,e[1]=o):o=e[1];const i=o;let s,r,l;e[2]!==t?(s=h=>t.onAuthTokenChange(h),r=()=>t.getAuthToken(),l=()=>t.getAuthToken(),e[2]=t,e[3]=s,e[4]=r,e[5]=l):(s=e[3],r=e[4],l=e[5]);const c=g(s,r,l),n=g(i.subscribe,i.getSnapshot,m);let u;e[6]!==t?(u=h=>{t.setAuthToken(h)},e[6]=t,e[7]=u):u=e[7];const a=u;let f;return e[8]!==a||e[9]!==c||e[10]!==n?(f={setToken:a,token:c,user:n},e[8]=a,e[9]=c,e[10]=n,e[11]=f):f=e[11],f};function m(){return null}export{w as default};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as A}from"react/compiler-runtime";import{useMutation as v,useQuery as z,keepPreviousData as I}from"@tanstack/react-query";import{useState as _,useSyncExternalStore as b}from"react";import{useLunora as y}from"./LunoraProvider-DC06S-p1.mjs";const D="lunora-react-admin-auth",E=50;function S(t,e,r,u={}){const{enabled:a=!0,pageSize:c=E}=u,[i,s]=_(c),l=b(g=>t.onAuthTokenChange(g),()=>t.currentIdentity(),()=>t.currentIdentity()),n=[D,l??"anon",...e,i],o=z({enabled:a,placeholderData:I,queryFn:()=>r(i),queryKey:n,staleTime:0}),d=o.data?.rows,f=o.data?.total,m=f!==void 0&&d!==void 0&&d.length<f,h=()=>{m&&s(g=>g+c)},p=()=>{o.refetch().catch(()=>{})};return{data:d,error:o.error??void 0,hasMore:m,loadMore:h,loading:o.isLoading,refetch:p,total:f}}const M=t=>{const e=A(20);let r;e[0]!==t?(r=t===void 0?{}:t,e[0]=t,e[1]=r):r=e[1];const u=r,a=y(),{enabled:c,filterField:i,filterValue:s,pageSize:l,search:n,searchField:o,sortBy:d,sortDirection:f}=u;let m;e[2]!==i||e[3]!==s||e[4]!==n||e[5]!==o||e[6]!==d||e[7]!==f?(m=["users",{filterField:i,filterValue:s,search:n,searchField:o,sortBy:d,sortDirection:f}],e[2]=i,e[3]=s,e[4]=n,e[5]=o,e[6]=d,e[7]=f,e[8]=m):m=e[8];let h;e[9]!==a||e[10]!==i||e[11]!==s||e[12]!==n||e[13]!==o||e[14]!==d||e[15]!==f?(h=g=>a.listAuthUsers({filterField:i,filterValue:s,limit:g,search:n,searchField:o,sortBy:d,sortDirection:f}),e[9]=a,e[10]=i,e[11]=s,e[12]=n,e[13]=o,e[14]=d,e[15]=f,e[16]=h):h=e[16];let p;return e[17]!==c||e[18]!==l?(p={enabled:c,pageSize:l},e[17]=c,e[18]=l,e[19]=p):p=e[19],S(a,m,h,p)},T=t=>{const e=A(8);let r;e[0]!==t?(r=t===void 0?{}:t,e[0]=t,e[1]=r):r=e[1];const u=r,a=y(),{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]!==a?(l=o=>a.listAuthOrganizations({limit:o}),e[3]=a,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],S(a,s,l,n)},$=t=>{const e=A(10);let r;e[0]!==t?(r=t===void 0?{}:t,e[0]=t,e[1]=r):r=e[1];const u=r,a=y(),{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]!==a||e[5]!==s?(n=d=>a.listAuthSessions({limit:d,userId:s}),e[4]=a,e[5]=s,e[6]=n):n=e[6];let o;return e[7]!==c||e[8]!==i?(o={enabled:c,pageSize:i},e[7]=c,e[8]=i,e[9]=o):o=e[9],S(a,l,n,o)},q=()=>{const t=A(10),e=y();let r;t[0]!==e?(r={mutationFn:o=>e.impersonateAuthUser({userId:o})},t[0]=e,t[1]=r):r=t[1];const u=v(r),{mutateAsync:a,reset:c}=u;let i;t[2]!==a?(i=o=>a(o),t[2]=a,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{$ as useAuthSessions,M as useAuthUsers,q as useImpersonate,T as useOrganizations};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as u}from"react/compiler-runtime";import{useSyncExternalStore as c}from"react";import i from"./useAuth-x4boOoAR.mjs";const m=()=>()=>{},h=()=>{const t=u(3),{token:s}=i(),r=c(m,f,a),n=r&&s!==null,o=!r;let e;return t[0]!==n||t[1]!==o?(e={isAuthenticated:n,isLoading:o},t[0]=n,t[1]=o,t[2]=e):e=t[2],e};function f(){return!0}function a(){return!1}export{h as useAuthState};
@@ -0,0 +1,2 @@
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};
@@ -0,0 +1,2 @@
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};
@@ -0,0 +1,2 @@
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};
@@ -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{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"./stable-key-B_BlboiY.mjs";const C=(t,c,o)=>{const e=S(24);let m;e[0]!==o?(m=o===void 0?{}:o,e[0]=o,e[1]=m):m=e[1];const f=m,n=b();let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={chunks:[],error:void 0,status:"idle"},e[2]=i):i=e[2];const[s,a]=_(z,i),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]!==n||e[8]!==f.maxBuffer||e[9]!==t||e[10]!==r?(u=()=>{if(r)return a({type:"reset"}),L;a({type:"reset"}),a({type:"start"});const{cancel:B,cleanup:y}=E(n.httpStream(t,c,{maxBuffer:f.maxBuffer}),a);return x.current=B,()=>{y(),x.current=void 0}},e[6]=c,e[7]=n,e[8]=f.maxBuffer,e[9]=t,e[10]=r,e[11]=u):u=e[11];let p;e[12]!==n||e[13]!==f.maxBuffer||e[14]!==t.method||e[15]!==t.path||e[16]!==k||e[17]!==r?(p=[n,t.method,t.path,k,r,f.maxBuffer],e[12]=n,e[13]=f.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 L(){}export{C as useHttpStream};
@@ -0,0 +1,2 @@
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-CWfn4qb4.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 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};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as p}from"react/compiler-runtime";import{createMutatorRunner as l}from"@lunora/client";import{useState as f}from"react";const E=function(s){const t=p(8),[n,m]=f(!1),[r,a]=f(void 0);let e;t[0]!==s?(e=l(s,{setError:a,setPending:m}),t[0]=s,t[1]=e):e=t[1];const{mutate:i,reset:u}=e,c=r!==void 0;let o;return t[2]!==r||t[3]!==i||t[4]!==n||t[5]!==u||t[6]!==c?(o={error:r,isError:c,mutate:i,pending:n,reset:u},t[2]=r,t[3]=i,t[4]=n,t[5]=u,t[6]=c,t[7]=o):o=t[7],o};export{E as useMutator};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c}from"react/compiler-runtime";import{u as f}from"./use-paginated-core-CWfn4qb4.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{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};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{useQueryClient as h,useQuery as E}from"@tanstack/react-query";import{useRef as b,useEffect as n,useCallback as g,useState as I}from"react";import{g as k}from"./cache-DmbajSjf.mjs";import{useLunora as q}from"./LunoraProvider-DC06S-p1.mjs";import{l as K,s as C}from"./query-key-C6iUhRuD.mjs";const F=(t,i,p={})=>{const e=q(),y=h(),{onError:c,shardKey:s}=p,d=b(c);n(()=>{d.current=c});const l=g(m=>{d.current?.(m)},[]),r=i==="skip",o=r?{}:i,a=K(t,o,s),[u,f]=I(e.isReady);n(()=>{u||e.whenReady().then(()=>{f(!0)})},[e,u]);const Q=r?void 0:e.peekHydratedQuery(t.__lunoraRef,o,s),{data:R}=E({enabled:!r&&u,initialData:Q,queryFn:()=>e.query(t,o,{shardKey:s}),queryKey:a,staleTime:Number.POSITIVE_INFINITY});return n(()=>r?()=>{}:k(e).attach(y,a,t,o,s,{onError:l}),[e,y,C(a),r,l]),r?void 0:R};export{F as default};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{evaluate as u}from"@lunora/ratelimit";import{useRef as i,useReducer as w,useCallback as c,useEffect as R}from"react";const p=(t,a={})=>{const r=a.now??Date.now,l=a.tickMs??1e3,s=i(void 0),[,n]=w(e=>e+1,0),v=c((e=1)=>{const{status:d,value:f}=u(t,s.current,{consume:!0,count:e,now:r(),reserve:!1});return f!==void 0&&(s.current=f),n(),d},[t,r]),k=c((e=1)=>u(t,s.current,{consume:!1,count:e,now:r(),reserve:!1}).status.ok,[t,r]),m=c(()=>{s.current=void 0,n()},[]),{status:o}=u(t,s.current,{consume:!1,count:1,now:r(),reserve:!1});return R(()=>{if(o.ok)return()=>{};const e=setInterval(n,l);return()=>{clearInterval(e)}},[o.ok,l]),{check:k,consume:v,disabled:!o.ok,ok:o.ok,reset:m,retryAfter:o.retryAfter}};export{p as useRateLimit};
@@ -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{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-L5JSXhhG.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{useLunora as M}from"./LunoraProvider-DC06S-p1.mjs";import{s as Q}from"./wire-key-L5JSXhhG.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};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{useState as w,useRef as N,useCallback as E,useEffect as G}from"react";import{useLunora as X}from"./LunoraProvider-DC06S-p1.mjs";const O="/_lunora/ws",j="/_lunora/voice/",z=4001,P=e=>e.startsWith("https://")?`wss://${e.slice(8)}`:e.startsWith("http://")?`ws://${e.slice(7)}`:e,Q=e=>{const n=e.startsWith("agents:")?e.slice(7):e;return n.endsWith("Voice")?n.slice(0,-5):n},Y=(e,n)=>{if(n===void 0||n==="")return P(e);if(n.endsWith(O))return n.slice(0,-O.length);try{return new URL(n).origin}catch{return P(e)}},Z=e=>{const n=Y(e.httpUrl,e.wsUrl),s=n.endsWith("/")?n.slice(0,-1):n,i=new URLSearchParams({threadKey:e.threadKey});return`${s}${j}${encodeURIComponent(e.agent)}?${i.toString()}`},ee=(e,n)=>{if(n?.code===z)return new Error(`${e}: authentication token expired — refresh the credential and start a new call`)},te=16e3,ne=e=>{if(e.length===0)return 0;let n=0;for(const s of e)n+=s*s;return Math.sqrt(n/e.length)},re=(e,n)=>{const s=n/te,i=s>1?Math.floor(e.length/s):e.length,d=new ArrayBuffer(i*2),l=new DataView(d);for(let a=0;a<i;a+=1){const k=e[Math.floor(a*s)]??0,p=Math.max(-1,Math.min(1,k));l.setInt16(a*2,p<0?p*32768:p*32767,!0)}return new Uint8Array(d)},oe=async e=>{const n=globalThis,s=n.navigator?.mediaDevices?.getUserMedia.bind(n.navigator.mediaDevices),i=n.AudioContext??n.webkitAudioContext;if(!s||!i)throw new Error("useVoiceAgent: microphone capture requires getUserMedia + AudioContext (no browser audio available)");const d=await s({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),l=new i,a=l.createMediaStreamSource(d),k=l.createScriptProcessor(4096,1,1);let p=!1,g=!1,u=0,h=0;return k.onaudioprocess=o=>{const f=o.inputBuffer.getChannelData(0),m=p?0:ne(f);if(e.onLevel(m),p)return;if(e.onAudio(re(f,l.sampleRate)),e.isSpeaking()){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){g=!0,u=0;return}g&&(u+=x,u>=e.silenceDurationMs&&(g=!1,u=0,e.onSilence()))},a.connect(k),k.connect(l.destination),{setMuted:o=>{p=o},stop:()=>{k.disconnect(),a.disconnect();for(const o of d.getTracks())o.stop();l.close()}}},se=()=>{const e=globalThis,n=e.AudioContext??e.webkitAudioContext;if(!n)throw new Error("useVoiceAgent: audio playback requires AudioContext (no browser audio available)");const s=new n,i=new Set;let d=0,l=Promise.resolve(),a=0;const k=async(u,h)=>{if(h!==a)return;let o;try{o=await s.decodeAudioData(u.buffer)}catch{return}if(h!==a)return;const f=s.createBufferSource();f.buffer=o,f.connect(s.destination);const m=Math.max(s.currentTime,d);f.start(m),d=m+o.duration,i.add(f),f.onended=()=>{i.delete(f)}},p=u=>{const h=Uint8Array.from(u),o=a;l=l.then(()=>k(h,o))},g=()=>{a+=1;for(const u of i)try{u.stop()}catch{}i.clear(),d=s.currentTime};return{enqueue:p,interrupt:g,stop:()=>{g(),s.close()}}},V=1,ce=.01,ie=1200,ae=.15,ue=3,pe=e=>{const{createMicrophone:n=oe,createSpeaker:s=se,createSocket:i,interruptChunks:d=ue,interruptThreshold:l=ae,silenceDurationMs:a=ie,silenceThreshold:k=ce,threadKey:p,voice:g}=e,u=X(),[h,o]=w("idle"),[f,m]=w(!1),[x,R]=w(""),[H,v]=w(""),[$,U]=w(0),[M,L]=w(!1),[B,C]=w(void 0),c=N(void 0),_=N(!1),T=E(t=>{const r=c.current?.socket;return r?.readyState===V?(r.send(JSON.stringify(t)),!0):!1},[]),y=E(()=>{const t=c.current;if(c.current=void 0,t){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),o("idle"),U(0)},[]),D=E(t=>{const r=c.current;switch(t.type){case"assistant_delta":{r&&(r.speaking=!0),o("speaking"),v(F=>F+t.text);break}case"assistant_done":{r&&(r.speaking=!1),v(t.text),o("listening");break}case"error":{r&&(r.speaking=!1),C(new Error(t.message)),o("listening");break}case"interrupted":{r&&(r.speaking=!1,r.suppressAudio=!1),r?.speaker?.interrupt(),o("listening");break}case"ready":{r&&(r.audioFormat=t.audioFormat,r.suppressAudio=!1),m(!0),o("listening");break}case"user_transcript":{r&&(r.suppressAudio=!1),R(t.text),v(""),o("thinking");break}}},[]),I=E(t=>{const r=c.current;!r||r.suppressAudio||(r.speaker??=s({audioFormat:r.audioFormat}),r.speaking=!0,o("speaking"),r.speaker.enqueue(t))},[s]),q=E(async()=>{if(c.current||_.current)return;_.current=!0,C(void 0),R(""),v("");let t;try{const r=Z({agent:Q(g.__lunoraRef),httpUrl:u.url,threadKey:p,wsUrl:u.wsUrl}),A=(i??(S=>{const b=u.getWebSocketImpl();if(!b)throw new Error("useVoiceAgent: no WebSocket implementation available (pass createSocket explicitly)");return new b(S)}))(r);A.binaryType="arraybuffer",t={audioFormat:"mp3",microphone:void 0,socket:A,speaker:void 0,speaking:!1,suppressAudio:!1},c.current=t,A.onmessage=S=>{if(typeof S.data=="string"){try{D(JSON.parse(S.data))}catch{}return}I(new Uint8Array(S.data))},A.onerror=()=>{C(new Error("useVoiceAgent: voice socket error"))},A.onclose=S=>{if(c.current!==t)return;const b=ee("useVoiceAgent",S);b&&C(b),y()};const W=await n({interruptChunks:d,interruptThreshold:l,isSpeaking:()=>c.current?.speaking??!1,onAudio:S=>{A.readyState===V&&A.send(S)},onInterrupt:()=>{T({type:"interrupt"}),c.current?.speaker?.interrupt(),c.current&&(c.current.speaking=!1,c.current.suppressAudio=!0),o("listening")},onLevel:U,onSilence:()=>{T({type:"commit"}),o("thinking")},silenceDurationMs:a,silenceThreshold:k});c.current===t?(t.microphone=W,L(!1),t.speaking||o("listening")):W.stop()}catch(r){c.current===t&&(C(r instanceof Error?r:new Error(String(r))),y())}finally{_.current=!1}},[u,n,i,I,D,d,l,T,a,k,y,p,g]),K=E(()=>{const t=!M;return c.current?.microphone?.setMuted(t),L(t),t},[M]),J=E(t=>{T({text:t,type:"text"})&&o("thinking")},[T]);return G(()=>y,[y]),{audioLevel:$,connected:f,endCall:y,error:B,interimTranscript:H,isMuted:M,sendText:J,startCall:q,status:h,toggleMute:K,transcript:x}};export{pe as useVoiceAgent};
@@ -0,0 +1 @@
1
+ import{s as d}from"./stable-key-B_BlboiY.mjs";const u=r=>{let t="";for(let c=0;c<r.length;c+=32768)t+=String.fromCharCode(...r.subarray(c,c+32768));return btoa(t)},e="$lunora.wire$",b=64,m="__proto__",p=r=>{if(r===null||typeof r!="object")return!1;const t=Object.getPrototypeOf(r);return t===null||t===Object.prototype},i=(r,t=0)=>{if(t>b)throw new RangeError(`wire-codec: value nesting exceeds the ${b}-level limit`);if(r===void 0)return[e,"undefined"];if(r===null)return null;const f=typeof r;if(f==="bigint")return[e,"bigint",r.toString()];if(f==="number"){const n=r;return Number.isNaN(n)?[e,"nan"]:n===1/0?[e,"inf"]:n===-1/0?[e,"-inf"]:n}if(f!=="object")return r;if(r instanceof Date)return[e,"date",i(r.getTime(),t+1)];if(r instanceof Error){const n=r,o={};for(const y of Object.keys(n))n[y]!==void 0&&(o[y]=i(n[y],t+1));const s=[e,"error",n.name,n.message,o];return n.cause!==void 0&&s.push(i(n.cause,t+1)),s}if(r instanceof URL)return[e,"url",r.href];if(r instanceof Map)return[e,"map",[...r.entries()].map(([n,o])=>[i(n,t+1),i(o,t+1)])];if(r instanceof Set)return[e,"set",[...r].map(n=>i(n,t+1))];if(r instanceof ArrayBuffer)return[e,"bytes",u(new Uint8Array(r)),"ArrayBuffer"];if(ArrayBuffer.isView(r)){const n=r,o=n.constructor.name,s=new Uint8Array(n.buffer,n.byteOffset,n.byteLength);return o==="Uint8Array"?[e,"bytes",u(s)]:[e,"bytes",u(s),o]}if(Array.isArray(r)){const n=r.map(o=>i(o,t+1));return n.length>0&&n[0]===e?[e,"arr",n]:n}if(!p(r)){const n=r.constructor?.name??"value";throw new TypeError(`wire-codec: cannot encode a ${n} 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,a={};for(const n of Object.keys(c)){const o=c[n];if(o===void 0)continue;const s=i(o,t+1);n===m?Object.defineProperty(a,n,{configurable:!0,enumerable:!0,value:s,writable:!0}):a[n]=s}return a},w=r=>d(i(r));export{w as s};
@@ -0,0 +1,93 @@
1
+ import { ReactNode } from 'react';
2
+ /**
3
+ * Stable provider identifier. Mirror of `@lunora/payment`'s `ProviderId` — the
4
+ * value is persisted verbatim, so an app branching on it must see every provider
5
+ * that has an adapter, not just the two that shipped first.
6
+ */
7
+ type ProviderId = "autumn" | "creem" | "dodopayments" | "polar" | "stripe";
8
+ /**
9
+ * Client-safe mirror of `@lunora/payment`'s `Subscription`. Re-declared here
10
+ * (rather than imported) so this React entry never pulls in the server-only
11
+ * `@lunora/payment` module graph — the kit stays React + DOM only.
12
+ * `__tests__/payment-mirror.test.ts` fails when this drifts from
13
+ * `packages/payment/src/types.ts`.
14
+ */
15
+ interface Subscription {
16
+ readonly cancelAtPeriodEnd: boolean;
17
+ readonly createdAt: number;
18
+ readonly currentPeriodEnd?: number;
19
+ /** Start of the current billing period — the window metered usage is summed over. */
20
+ readonly currentPeriodStart?: number;
21
+ readonly id: string;
22
+ readonly priceId: string;
23
+ readonly provider: ProviderId;
24
+ readonly quantity: number;
25
+ readonly referenceId: string;
26
+ readonly state: "active" | "canceled" | "past_due" | "paused" | "trialing";
27
+ readonly updatedAt: number;
28
+ }
29
+ /** The `{ url }` shape every checkout/portal trigger resolves to. */
30
+ interface RedirectTarget {
31
+ readonly url: string;
32
+ }
33
+ /** A thunk the app supplies that calls its own Lunora action and resolves a redirect URL. */
34
+ type RedirectTrigger = () => Promise<RedirectTarget>;
35
+ interface UseCheckoutResult {
36
+ /** Run the trigger and redirect the browser to the resolved URL. Resolves once the redirect is issued; rejects on failure. */
37
+ checkout: () => Promise<void>;
38
+ /** The most recent failure, or `undefined`. */
39
+ error: Error | undefined;
40
+ /** `true` while the trigger is in flight (before the redirect is issued). */
41
+ pending: boolean;
42
+ }
43
+ /**
44
+ * Decoupled redirect-on-resolve primitive shared by `CheckoutButton` and
45
+ * `CustomerPortalButton`. The app passes a `trigger` thunk that calls its own
46
+ * Lunora action (the one wrapping `LunoraPayment.createCheckout` /
47
+ * `createPortalSession`) and resolves `{ url }`; this hook awaits it, flips
48
+ * `pending`, surfaces any `error`, and on success navigates via
49
+ * `location.assign(url)`.
50
+ *
51
+ * Mirrors Convex's `CheckoutLink` / `CustomerPortalLink` flow (trigger an action
52
+ * that returns a URL, then redirect) while staying agnostic of the app's
53
+ * function names.
54
+ */
55
+ declare const useCheckout: (trigger: RedirectTrigger) => UseCheckoutResult;
56
+ /**
57
+ * Presentational props shared by the redirect buttons. Kept to a curated set
58
+ * (rather than spreading arbitrary button attributes) so the component stays
59
+ * within the repo's `react/jsx-props-no-spreading` rule while covering the
60
+ * common styling / accessibility hooks.
61
+ */
62
+ interface RedirectButtonOwnProps {
63
+ /** Accessible label when the visible `children` are icon-only. */
64
+ "aria-label"?: string;
65
+ children?: ReactNode;
66
+ className?: string;
67
+ /** Force-disable the control regardless of pending state. */
68
+ disabled?: boolean;
69
+ /** Called with the failure when the trigger rejects. The error is also surfaced via `useCheckout`. */
70
+ onError?: (error: Error) => void;
71
+ title?: string;
72
+ }
73
+ interface CheckoutButtonProps extends RedirectButtonOwnProps {
74
+ /** Calls the app's checkout action and resolves the hosted-checkout `{ url }`. */
75
+ onCheckout: RedirectTrigger;
76
+ }
77
+ interface CustomerPortalButtonProps extends RedirectButtonOwnProps {
78
+ /** Calls the app's portal action and resolves the customer-portal `{ url }`. */
79
+ onPortal: RedirectTrigger;
80
+ }
81
+ /**
82
+ * Button that starts a hosted checkout. On click it awaits `onCheckout` (a thunk
83
+ * that calls the app's checkout action) and redirects to the returned URL,
84
+ * disabling itself while the request is in flight.
85
+ */
86
+ declare const CheckoutButton: ({ onCheckout, ...rest }: CheckoutButtonProps) => ReactNode;
87
+ /**
88
+ * Button that opens the provider's customer portal. On click it awaits
89
+ * `onPortal` (a thunk that calls the app's portal action) and redirects to the
90
+ * returned URL, disabling itself while the request is in flight.
91
+ */
92
+ declare const CustomerPortalButton: ({ onPortal, ...rest }: CustomerPortalButtonProps) => ReactNode;
93
+ export { CheckoutButton, type CheckoutButtonProps, CustomerPortalButton, type CustomerPortalButtonProps, type ProviderId, type RedirectTarget, type RedirectTrigger, type Subscription, type UseCheckoutResult, useCheckout };
@@ -0,0 +1,93 @@
1
+ import { ReactNode } from 'react';
2
+ /**
3
+ * Stable provider identifier. Mirror of `@lunora/payment`'s `ProviderId` — the
4
+ * value is persisted verbatim, so an app branching on it must see every provider
5
+ * that has an adapter, not just the two that shipped first.
6
+ */
7
+ type ProviderId = "autumn" | "creem" | "dodopayments" | "polar" | "stripe";
8
+ /**
9
+ * Client-safe mirror of `@lunora/payment`'s `Subscription`. Re-declared here
10
+ * (rather than imported) so this React entry never pulls in the server-only
11
+ * `@lunora/payment` module graph — the kit stays React + DOM only.
12
+ * `__tests__/payment-mirror.test.ts` fails when this drifts from
13
+ * `packages/payment/src/types.ts`.
14
+ */
15
+ interface Subscription {
16
+ readonly cancelAtPeriodEnd: boolean;
17
+ readonly createdAt: number;
18
+ readonly currentPeriodEnd?: number;
19
+ /** Start of the current billing period — the window metered usage is summed over. */
20
+ readonly currentPeriodStart?: number;
21
+ readonly id: string;
22
+ readonly priceId: string;
23
+ readonly provider: ProviderId;
24
+ readonly quantity: number;
25
+ readonly referenceId: string;
26
+ readonly state: "active" | "canceled" | "past_due" | "paused" | "trialing";
27
+ readonly updatedAt: number;
28
+ }
29
+ /** The `{ url }` shape every checkout/portal trigger resolves to. */
30
+ interface RedirectTarget {
31
+ readonly url: string;
32
+ }
33
+ /** A thunk the app supplies that calls its own Lunora action and resolves a redirect URL. */
34
+ type RedirectTrigger = () => Promise<RedirectTarget>;
35
+ interface UseCheckoutResult {
36
+ /** Run the trigger and redirect the browser to the resolved URL. Resolves once the redirect is issued; rejects on failure. */
37
+ checkout: () => Promise<void>;
38
+ /** The most recent failure, or `undefined`. */
39
+ error: Error | undefined;
40
+ /** `true` while the trigger is in flight (before the redirect is issued). */
41
+ pending: boolean;
42
+ }
43
+ /**
44
+ * Decoupled redirect-on-resolve primitive shared by `CheckoutButton` and
45
+ * `CustomerPortalButton`. The app passes a `trigger` thunk that calls its own
46
+ * Lunora action (the one wrapping `LunoraPayment.createCheckout` /
47
+ * `createPortalSession`) and resolves `{ url }`; this hook awaits it, flips
48
+ * `pending`, surfaces any `error`, and on success navigates via
49
+ * `location.assign(url)`.
50
+ *
51
+ * Mirrors Convex's `CheckoutLink` / `CustomerPortalLink` flow (trigger an action
52
+ * that returns a URL, then redirect) while staying agnostic of the app's
53
+ * function names.
54
+ */
55
+ declare const useCheckout: (trigger: RedirectTrigger) => UseCheckoutResult;
56
+ /**
57
+ * Presentational props shared by the redirect buttons. Kept to a curated set
58
+ * (rather than spreading arbitrary button attributes) so the component stays
59
+ * within the repo's `react/jsx-props-no-spreading` rule while covering the
60
+ * common styling / accessibility hooks.
61
+ */
62
+ interface RedirectButtonOwnProps {
63
+ /** Accessible label when the visible `children` are icon-only. */
64
+ "aria-label"?: string;
65
+ children?: ReactNode;
66
+ className?: string;
67
+ /** Force-disable the control regardless of pending state. */
68
+ disabled?: boolean;
69
+ /** Called with the failure when the trigger rejects. The error is also surfaced via `useCheckout`. */
70
+ onError?: (error: Error) => void;
71
+ title?: string;
72
+ }
73
+ interface CheckoutButtonProps extends RedirectButtonOwnProps {
74
+ /** Calls the app's checkout action and resolves the hosted-checkout `{ url }`. */
75
+ onCheckout: RedirectTrigger;
76
+ }
77
+ interface CustomerPortalButtonProps extends RedirectButtonOwnProps {
78
+ /** Calls the app's portal action and resolves the customer-portal `{ url }`. */
79
+ onPortal: RedirectTrigger;
80
+ }
81
+ /**
82
+ * Button that starts a hosted checkout. On click it awaits `onCheckout` (a thunk
83
+ * that calls the app's checkout action) and redirects to the returned URL,
84
+ * disabling itself while the request is in flight.
85
+ */
86
+ declare const CheckoutButton: ({ onCheckout, ...rest }: CheckoutButtonProps) => ReactNode;
87
+ /**
88
+ * Button that opens the provider's customer portal. On click it awaits
89
+ * `onPortal` (a thunk that calls the app's portal action) and redirects to the
90
+ * returned URL, disabling itself while the request is in flight.
91
+ */
92
+ declare const CustomerPortalButton: ({ onPortal, ...rest }: CustomerPortalButtonProps) => ReactNode;
93
+ export { CheckoutButton, type CheckoutButtonProps, CustomerPortalButton, type CustomerPortalButtonProps, type ProviderId, type RedirectTarget, type RedirectTrigger, type Subscription, type UseCheckoutResult, useCheckout };
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{c as p}from"react/compiler-runtime";import{useState as k,useCallback as C}from"react";import{jsx as m}from"react/jsx-runtime";const y=n=>{const t=new URL(n,globalThis.location.href);if(t.protocol!=="https:"&&t.protocol!=="http:")throw new Error(`refusing to redirect to a non-http(s) URL: ${t.protocol}`);return t.href},L=n=>{const[t,e]=k(!1),[o,a]=k(void 0);return{checkout:C(async()=>{e(!0),a(void 0);try{const r=await n();globalThis.location.assign(y(r.url))}catch(r){const l=r instanceof Error?r:new Error(String(r));throw a(l),l}finally{e(!1)}},[n]),error:o,pending:t}},E=n=>{const t=p(11),{"aria-label":e,children:o,className:a,disabled:c,onError:r,title:l,trigger:u}=n,{checkout:i,pending:s}=L(u);let d;t[0]!==i||t[1]!==r?(d=()=>{i().catch(g=>{const w=g instanceof Error?g:new Error(String(g));r?.(w)})},t[0]=i,t[1]=r,t[2]=d):d=t[2];const f=d,b=c===!0||s;let h;return t[3]!==e||t[4]!==o||t[5]!==a||t[6]!==f||t[7]!==s||t[8]!==b||t[9]!==l?(h=m("button",{"aria-busy":s,"aria-label":e,className:a,disabled:b,onClick:f,title:l,type:"button",children:o}),t[3]=e,t[4]=o,t[5]=a,t[6]=f,t[7]=s,t[8]=b,t[9]=l,t[10]=h):h=t[10],h},N=n=>{const t=p(11);let e,o;t[0]!==n?({onCheckout:e,...o}=n,t[0]=n,t[1]=e,t[2]=o):(e=t[1],o=t[2]);const{"aria-label":a,children:c,className:r,disabled:l,onError:u,title:i}=o;let s;return t[3]!==a||t[4]!==c||t[5]!==r||t[6]!==l||t[7]!==e||t[8]!==u||t[9]!==i?(s=m(E,{"aria-label":a,className:r,disabled:l,onError:u,title:i,trigger:e,children:c}),t[3]=a,t[4]=c,t[5]=r,t[6]=l,t[7]=e,t[8]=u,t[9]=i,t[10]=s):s=t[10],s},P=n=>{const t=p(11);let e,o;t[0]!==n?({onPortal:e,...o}=n,t[0]=n,t[1]=e,t[2]=o):(e=t[1],o=t[2]);const{"aria-label":a,children:c,className:r,disabled:l,onError:u,title:i}=o;let s;return t[3]!==a||t[4]!==c||t[5]!==r||t[6]!==l||t[7]!==u||t[8]!==e||t[9]!==i?(s=m(E,{"aria-label":a,className:r,disabled:l,onError:u,title:i,trigger:e,children:c}),t[3]=a,t[4]=c,t[5]=r,t[6]=l,t[7]=u,t[8]=e,t[9]=i,t[10]=s):s=t[10],s};export{N as CheckoutButton,P as CustomerPortalButton,L as useCheckout};
package/dist/server.d.mts CHANGED
@@ -4,20 +4,38 @@ import { ServerClientOptions } from '@lunora/client/ssr';
4
4
  export { type AuthLike, type HeadersSource, type ServerClientOptions, type ServerSession, createServerClient, deserializePreloaded, getServerSession, serializePreloaded } from '@lunora/client/ssr';
5
5
  import { QueryClient } from '@tanstack/react-query';
6
6
  export { HydrationBoundary, dehydrate } from '@tanstack/react-query';
7
- export { type L as LunoraQueryOptions, l as lunoraQueryOptions } from "./packem_shared/query-options.d-D4okOpO8.mjs";
7
+ export {
8
8
  /**
9
- * Run a query on the server and seed `queryClient` with the result under the
10
- * same key the client hooks use (see `lunoraQueryKey`), so a later
11
- * `useQuery(fn, args)` reads it straight from the hydrated cache — no loading
12
- * flash, no duplicate fetch on the client.
13
- *
14
- * Pair it with TanStack's `dehydrate` + `HydrationBoundary` (both re-exported
15
- * from this module): prefetch into a fresh `QueryClient`, `dehydrate` it, wrap
16
- * the client subtree in `HydrationBoundary`, and the client hooks pick the value
17
- * up from cache. Errors propagate — wrap the call if you'd rather render a
18
- * fallback than fail the server render. Drop the `await` for fire-and-forget
19
- * prefetch when you don't need the data present on the very first paint.
20
- */
9
+ * Server-side data-loading helpers for React Server Components.
10
+ *
11
+ * This module is the server half of `@lunora/react`: it carries no
12
+ * `"use client"` directive, opens no WebSocket, and touches no browser globals,
13
+ * so it is safe to import from an RSC / Next.js Server Component. The browser
14
+ * hooks (`useQuery`, `usePreloadedQuery`, …) live in the package root,
15
+ * `@lunora/react`, which is a client boundary.
16
+ *
17
+ * Two flows are supported, mirroring the two common RSC patterns. First,
18
+ * hydrating the TanStack cache: `prefetchQuery` runs the query on the server and
19
+ * seeds a `QueryClient` under the exact key the client `useQuery` reads back, so
20
+ * the client renders with data on the first paint and a live WS subscription
21
+ * attaches on mount. Second, the explicit-token flow: `preloadQuery` returns a
22
+ * serializable `Preloaded` value you hand to a client component that calls
23
+ * `usePreloadedQuery`.
24
+ */
25
+ type L as LunoraQueryOptions, l as lunoraQueryOptions } from "./packem_shared/query-options.d-CdgGQ9s4.mjs";
26
+ /**
27
+ * Run a query on the server and seed `queryClient` with the result under the
28
+ * same key the client hooks use (see `lunoraQueryKey`), so a later
29
+ * `useQuery(fn, args)` reads it straight from the hydrated cache — no loading
30
+ * flash, no duplicate fetch on the client.
31
+ *
32
+ * Pair it with TanStack's `dehydrate` + `HydrationBoundary` (both re-exported
33
+ * from this module): prefetch into a fresh `QueryClient`, `dehydrate` it, wrap
34
+ * the client subtree in `HydrationBoundary`, and the client hooks pick the value
35
+ * up from cache. Errors propagate — wrap the call if you'd rather render a
36
+ * fallback than fail the server render. Drop the `await` for fire-and-forget
37
+ * prefetch when you don't need the data present on the very first paint.
38
+ */
21
39
  declare const prefetchQuery: <F extends FunctionReference>(queryClient: QueryClient, client: LunoraClient, function_: F, args: ArgsOf<F>, options?: {
22
40
  shardKey?: string;
23
41
  }) => Promise<void>;
@@ -27,25 +45,25 @@ interface ServerCallOptions {
27
45
  shardKey?: string;
28
46
  }
29
47
  /**
30
- * Run a query once on the server and return its result — the standalone
31
- * counterpart to `prefetchQuery`/`preloadQuery` for when you just want the data
32
- * inline in a Server Component (e.g. to compute metadata or branch on a value)
33
- * rather than seed a cache or hand a `Preloaded` to the client.
34
- *
35
- * Builds a fresh request-scoped client per call (see `createServerClient`), so
36
- * pass `token` to run as the signed-in user. For several reads in one request,
37
- * prefer holding one `createServerClient` and calling `.query()` yourself to
38
- * avoid rebuilding the transport each time. Errors propagate.
39
- */
48
+ * Run a query once on the server and return its result — the standalone
49
+ * counterpart to `prefetchQuery`/`preloadQuery` for when you just want the data
50
+ * inline in a Server Component (e.g. to compute metadata or branch on a value)
51
+ * rather than seed a cache or hand a `Preloaded` to the client.
52
+ *
53
+ * Builds a fresh request-scoped client per call (see `createServerClient`), so
54
+ * pass `token` to run as the signed-in user. For several reads in one request,
55
+ * prefer holding one `createServerClient` and calling `.query()` yourself to
56
+ * avoid rebuilding the transport each time. Errors propagate.
57
+ */
40
58
  declare const fetchQuery: <F extends FunctionReference>(options: ServerClientOptions, function_: F, args: ArgsOf<F>, callOptions?: ServerCallOptions) => Promise<ReturnOf<F>>;
41
59
  /**
42
- * Run a mutation once on the server and return its result. Server-side calls go
43
- * straight over HTTP RPC — the offline queue and optimistic-update machinery are
44
- * client-only and never engage here. Errors propagate.
45
- */
60
+ * Run a mutation once on the server and return its result. Server-side calls go
61
+ * straight over HTTP RPC — the offline queue and optimistic-update machinery are
62
+ * client-only and never engage here. Errors propagate.
63
+ */
46
64
  declare const fetchMutation: <F extends FunctionReference>(options: ServerClientOptions, function_: F, args: ArgsOf<F>, callOptions?: ServerCallOptions) => Promise<ReturnOf<F>>;
47
65
  /**
48
- * Run an action once on the server and return its result. Errors propagate.
49
- */
66
+ * Run an action once on the server and return its result. Errors propagate.
67
+ */
50
68
  declare const fetchAction: <F extends FunctionReference>(options: ServerClientOptions, function_: F, args: ArgsOf<F>, callOptions?: ServerCallOptions) => Promise<ReturnOf<F>>;
51
69
  export { ServerCallOptions, fetchAction, fetchMutation, fetchQuery, prefetchQuery };