@lunora/react 1.0.0-alpha.9 → 1.0.0-alpha.90

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 +1157 -355
  4. package/dist/index.d.ts +1157 -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-C2UbTWee.mjs +1 -0
  9. package/dist/packem_shared/hydratePreloaded-DYvzkKqH.mjs +2 -0
  10. package/dist/packem_shared/lunoraQueryOptions-BVgQsR9d.mjs +1 -0
  11. package/dist/packem_shared/query-key-By_ZIdza.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-BZaJ5Xam.mjs +2 -0
  17. package/dist/packem_shared/useAction-CUSJu4yq.mjs +2 -0
  18. package/dist/packem_shared/useAgent-DtQfMu4S.mjs +2 -0
  19. package/dist/packem_shared/useAgentChat-g4ZNMq1B.mjs +2 -0
  20. package/dist/packem_shared/useAgentState-BuMYPWb2.mjs +2 -0
  21. package/dist/packem_shared/useAgentToolEvents-B1ItKmZi.mjs +2 -0
  22. package/dist/packem_shared/useAuth-x4boOoAR.mjs +2 -0
  23. package/dist/packem_shared/useAuthSessions-gBDeNFnd.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-DWtB9sAr.mjs +2 -0
  29. package/dist/packem_shared/useInfiniteQuery-D6zw7PwB.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-hCSqOGFy.mjs +2 -0
  33. package/dist/packem_shared/usePresence-BVjZyltT.mjs +2 -0
  34. package/dist/packem_shared/useQuery-DIu5vJyH.mjs +2 -0
  35. package/dist/packem_shared/useRateLimit-Cckxi8m9.mjs +2 -0
  36. package/dist/packem_shared/useStream-Cor62Cu-.mjs +2 -0
  37. package/dist/packem_shared/useSubscription-egFPCaGE.mjs +2 -0
  38. package/dist/packem_shared/useVoiceAgent-DHdUlo0G.mjs +2 -0
  39. package/dist/packem_shared/wire-key-p_JEwJ1j.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 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-x4boOoAR.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-D6zw7PwB.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-hCSqOGFy.mjs";import{hydratePreloaded as W,default as X}from"./packem_shared/hydratePreloaded-DYvzkKqH.mjs";import{usePresence as Z}from"./packem_shared/usePresence-BVjZyltT.mjs";import{default as $}from"./packem_shared/useQuery-DIu5vJyH.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};
@@ -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 a}from"./query-key-By_ZIdza.mjs";class d{constructor(e){this.client=e}client;entries=new Map;keyOf(e){return a(e)}hasConsumers(e){return this.entries.has(a(e))}attach(e,c,f,b,h,k={}){const s=a(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 C of t.errorCallbacks)C(n)},shardKey:h})}catch(n){throw this.entries.delete(s),n}}r.refCount+=1;const{onError:o}=k;o&&r.errorCallbacks.add(o);let u=!1;return()=>{if(u)return;u=!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,y=i=>{let e=l.get(i);return e||(e=new d(i),l.set(i,e)),e};export{y 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-C2UbTWee.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};
@@ -0,0 +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};
@@ -0,0 +1 @@
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};
@@ -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 N,rebalance as j,derivePaginationStatus as O,applyLoadMore as H}from"@lunora/client/pagination";import{useQueryClient as V}from"@tanstack/react-query";import{useRef as h,useReducer as Y,useState as T,useEffect as d,useCallback as B}from"react";import{g as G}from"./cache-C2UbTWee.mjs";import{useLunora as J}from"./LunoraProvider-DC06S-p1.mjs";import{s as c,l as I}from"./query-key-By_ZIdza.mjs";const U=function(u){const m=h(void 0);return m.current??=u(),m},te=function(u,m,R){const i=J(),a=V(),{initialNumItems:Q,shardKey:g}=R,y=m==="skip",p=y?{}:m,[,D]=Y(e=>e+1,0),[A,K]=T(()=>N(Q)),[z,k]=T(void 0),P=h(R.onError);d(()=>{P.current=R.onError});const q=`${c(I(u,p,g))}::${String(Q)}`,x=h(q);x.current!==q&&(x.current=q,K(N(Q)),k(void 0));const b=A.map(e=>{const r={...p,paginationOpts:{cursor:e.lower,endCursor:e.upper,numItems:e.numItems}},t=I(u,r,g);return{args:r,key:t}}),F=b.map(({key:e})=>c(e)).join("|"),v=h({baseArgs:p,entries:[],fn:u,shardKey:g});d(()=>{v.current={baseArgs:p,entries:b,fn:u,shardKey:g}});const L=(e,r,t)=>{k(t),K(o=>{const s=v.current,n=o.at(-1);if(o.length<=1||!n||a.getQueryData(r)!==void 0)return o;const w={...s.baseArgs,paginationOpts:{cursor:n.lower,endCursor:n.upper,numItems:n.numItems}};return c(I(s.fn,w,s.shardKey))===e?o.slice(0,-1):o}),P.current?.(t)},E=U(()=>new Map),M=h(i);d(()=>{const e=E.current;if(M.current!==i){for(const s of e.values())s();e.clear(),M.current=i}if(y){for(const s of e.values())s();e.clear();return}const r=v.current,t=G(i),o=new Set(r.entries.map(({key:s})=>c(s)));for(const[s,n]of e)o.has(s)||(n(),e.delete(s));for(const s of r.entries){const n=c(s.key);if(e.has(n))continue;a.fetchQuery({gcTime:Number.POSITIVE_INFINITY,queryFn:()=>i.query(r.fn,s.args,{shardKey:r.shardKey}),queryKey:s.key,staleTime:0}).catch(f=>{L(n,s.key,f instanceof Error?{code:f.code,message:f.message}:{message:String(f)})});const l=t.attach(a,s.key,r.fn,s.args,r.shardKey,{onError:f=>{L(n,s.key,f)}}),C=s.key;e.set(n,()=>{l(),t.hasConsumers(C)||a.removeQueries({exact:!0,queryKey:C})})}},[i,a,F,y]),d(()=>()=>{for(const e of E.current.values())e();E.current.clear()},[]),d(()=>a.getQueryCache().subscribe(t=>{if(t.type!=="updated")return;const o=c(t.query.queryKey);b.some(({key:s})=>c(s)===o)&&(k(void 0),D())}),[a,F]);const S=y?[]:b.map(({key:e})=>a.getQueryData(e));d(()=>{if(y)return;const e=j(A,S);e&&K(e)});const{status:_}=O(y,S),$=B(e=>{k(void 0),K(r=>{const t=v.current,o=r.map(l=>{const C={...t.baseArgs,paginationOpts:{cursor:l.lower,endCursor:l.upper,numItems:l.numItems}};return a.getQueryData(I(t.fn,C,t.shardKey))}),{nextCursor:s,status:n}=O(!1,o);return H(r,n==="CanLoadMore"?s:void 0,e)??r})},[a]);return{error:z,loadMore:$,pageResults:S,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-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};
@@ -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-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};
@@ -0,0 +1,2 @@
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};
@@ -0,0 +1,2 @@
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};
@@ -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 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};
@@ -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"./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};
@@ -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-BZaJ5Xam.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-BZaJ5Xam.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-C2UbTWee.mjs";import{useLunora as q}from"./LunoraProvider-DC06S-p1.mjs";import{l as K,s as C}from"./query-key-By_ZIdza.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-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};
@@ -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-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};
@@ -0,0 +1,2 @@
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};
@@ -0,0 +1 @@
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};
@@ -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};