@lunora/react 1.0.0-alpha.3 → 1.0.0-alpha.31

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 (49) hide show
  1. package/LICENSE.md +6 -0
  2. package/README.md +2 -0
  3. package/__assets__/package-og.svg +1 -1
  4. package/dist/index.d.mts +915 -276
  5. package/dist/index.d.ts +915 -276
  6. package/dist/index.mjs +27 -15
  7. package/dist/packem_shared/{AuthLoading-DtKgZT2Z.mjs → AuthLoading-DezUWNB2.mjs} +1 -1
  8. package/dist/packem_shared/{CheckoutButton-CVSry8U1.mjs → CheckoutButton-DUite8jJ.mjs} +8 -4
  9. package/dist/packem_shared/{LunoraProvider-D38Xp16l.mjs → LunoraProvider-BsuiW4Lk.mjs} +3 -2
  10. package/dist/packem_shared/{cache-CItk3fgN.mjs → cache-JeuDAXfE.mjs} +6 -1
  11. package/dist/packem_shared/hydratePreloaded-2omLtadR.mjs +54 -0
  12. package/dist/packem_shared/{lunoraQueryOptions-CsuWzjg1.mjs → lunoraQueryOptions-CefbPBId.mjs} +1 -1
  13. package/dist/packem_shared/query-key-LGnArBTB.mjs +13 -0
  14. package/dist/packem_shared/query-options.d-CdgGQ9s4.d.mts +38 -0
  15. package/dist/packem_shared/query-options.d-CdgGQ9s4.d.ts +38 -0
  16. package/dist/packem_shared/stable-key-DePnevIy.mjs +38 -0
  17. package/dist/packem_shared/{use-paginated-core-CoOfcc-p.mjs → use-paginated-core-xxvd1YA0.mjs} +37 -19
  18. package/dist/packem_shared/useAgent-BNLlIYHz.mjs +101 -0
  19. package/dist/packem_shared/useAgentChat-0cebQe7-.mjs +304 -0
  20. package/dist/packem_shared/useAgentState-Cqyd3Dfy.mjs +37 -0
  21. package/dist/packem_shared/useAgentToolEvents-gF7U4_KY.mjs +129 -0
  22. package/dist/packem_shared/{useAuth-CNUKtOOp.mjs → useAuth-BSutjJaa.mjs} +1 -1
  23. package/dist/packem_shared/{useAuthState-BiGhtSCs.mjs → useAuthState-CyF35qZR.mjs} +1 -1
  24. package/dist/packem_shared/useClientQuery-DIkNT4QA.mjs +17 -0
  25. package/dist/packem_shared/{useConnectionStatus-DRSY9ldm.mjs → useConnectionStatus-PJ7vyCHy.mjs} +1 -1
  26. package/dist/packem_shared/useFlag-Beyeiq2b.mjs +128 -0
  27. package/dist/packem_shared/useHttpStream-oc4s1pMy.mjs +127 -0
  28. package/dist/packem_shared/{useInfiniteQuery-MH0x4l8h.mjs → useInfiniteQuery-CJNw1XaZ.mjs} +1 -1
  29. package/dist/packem_shared/{useMutation-CrvMXRsk.mjs → useMutation-BeqeIjTr.mjs} +1 -1
  30. package/dist/packem_shared/useMutator-IIrLtDiM.mjs +47 -0
  31. package/dist/packem_shared/{usePaginatedQuery-D3PTDRGS.mjs → usePaginatedQuery-DWzydaVR.mjs} +1 -1
  32. package/dist/packem_shared/{usePresence-D7jLuxj0.mjs → usePresence-Rnx1Fznc.mjs} +13 -6
  33. package/dist/packem_shared/useQuery-CE8_QUgh.mjs +77 -0
  34. package/dist/packem_shared/{useStream-BRY9nemd.mjs → useStream-GYNgc9J5.mjs} +6 -3
  35. package/dist/packem_shared/{useSubscription-CHMCjyQg.mjs → useSubscription-DcDlvVuI.mjs} +3 -3
  36. package/dist/packem_shared/useVoiceAgent-w7fzAMSB.mjs +422 -0
  37. package/dist/packem_shared/wire-key-Bg8BJ8YM.mjs +101 -0
  38. package/dist/server.d.mts +29 -29
  39. package/dist/server.d.ts +29 -29
  40. package/dist/server.mjs +2 -2
  41. package/dist/upload.d.mts +2 -0
  42. package/dist/upload.d.ts +2 -0
  43. package/dist/upload.mjs +3 -0
  44. package/package.json +11 -5
  45. package/dist/packem_shared/hydratePreloaded-BlFL9FGq.mjs +0 -46
  46. package/dist/packem_shared/query-key-C5rufkEE.mjs +0 -21
  47. package/dist/packem_shared/query-options.d-D4okOpO8.d.mts +0 -38
  48. package/dist/packem_shared/query-options.d-D4okOpO8.d.ts +0 -38
  49. package/dist/packem_shared/useQuery-C5S0W-7K.mjs +0 -41
package/dist/index.mjs CHANGED
@@ -1,17 +1,29 @@
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-CsuWzjg1.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 { default as useInfiniteQuery } from './packem_shared/useInfiniteQuery-MH0x4l8h.mjs';
10
- export { useMutation } from './packem_shared/useMutation-CrvMXRsk.mjs';
11
- export { usePaginatedQuery } from './packem_shared/usePaginatedQuery-D3PTDRGS.mjs';
12
- export { hydratePreloaded, default as usePreloadedQuery } from './packem_shared/hydratePreloaded-BlFL9FGq.mjs';
13
- export { usePresence } from './packem_shared/usePresence-D7jLuxj0.mjs';
14
- export { default as useQuery } from './packem_shared/useQuery-C5S0W-7K.mjs';
2
+ export { AuthLoading, Authenticated, Unauthenticated } from './packem_shared/AuthLoading-DezUWNB2.mjs';
3
+ export { useAuthState } from './packem_shared/useAuthState-CyF35qZR.mjs';
4
+ export { LunoraProvider, useLunora } from './packem_shared/LunoraProvider-BsuiW4Lk.mjs';
5
+ export { CheckoutButton, CustomerPortalButton, useCheckout } from './packem_shared/CheckoutButton-DUite8jJ.mjs';
6
+ export { lunoraQueryOptions } from './packem_shared/lunoraQueryOptions-CefbPBId.mjs';
7
+ export { useAgent } from './packem_shared/useAgent-BNLlIYHz.mjs';
8
+ export { useAgentChat } from './packem_shared/useAgentChat-0cebQe7-.mjs';
9
+ export { useAgentState } from './packem_shared/useAgentState-Cqyd3Dfy.mjs';
10
+ export { useAgentToolEvents } from './packem_shared/useAgentToolEvents-gF7U4_KY.mjs';
11
+ export { default as useAuth } from './packem_shared/useAuth-BSutjJaa.mjs';
12
+ export { default as useClientQuery } from './packem_shared/useClientQuery-DIkNT4QA.mjs';
13
+ export { default as useConnectionStatus } from './packem_shared/useConnectionStatus-PJ7vyCHy.mjs';
14
+ export { useFlag, useFlags } from './packem_shared/useFlag-Beyeiq2b.mjs';
15
+ export { useHttpStream } from './packem_shared/useHttpStream-oc4s1pMy.mjs';
16
+ export { default as useInfiniteQuery } from './packem_shared/useInfiniteQuery-CJNw1XaZ.mjs';
17
+ export { useMutation } from './packem_shared/useMutation-BeqeIjTr.mjs';
18
+ export { useMutator } from './packem_shared/useMutator-IIrLtDiM.mjs';
19
+ export { usePaginatedQuery } from './packem_shared/usePaginatedQuery-DWzydaVR.mjs';
20
+ export { hydratePreloaded, default as usePreloadedQuery } from './packem_shared/hydratePreloaded-2omLtadR.mjs';
21
+ export { usePresence } from './packem_shared/usePresence-Rnx1Fznc.mjs';
22
+ export { default as useQuery } from './packem_shared/useQuery-CE8_QUgh.mjs';
15
23
  export { useRateLimit } from './packem_shared/useRateLimit-DTEffQEi.mjs';
16
- export { useStream } from './packem_shared/useStream-BRY9nemd.mjs';
17
- export { default as useSubscription } from './packem_shared/useSubscription-CHMCjyQg.mjs';
24
+ export { useStream } from './packem_shared/useStream-GYNgc9J5.mjs';
25
+ export { default as useSubscription } from './packem_shared/useSubscription-DcDlvVuI.mjs';
26
+ export { useVoiceAgent } from './packem_shared/useVoiceAgent-w7fzAMSB.mjs';
27
+ export { createClientQuery, getErrorCode, getRetryAfterMs, isConflictError, isForbiddenError, isRateLimitedError, isUnauthorizedError } from '@lunora/client';
28
+ export { RestrictionError, UploadControl, UploadError } from '@visulima/storage-client';
29
+ export { useChunkedRestUpload, useFileInput, useMultipartUpload, usePasteUpload, useTusUpload, useUpload } from '@visulima/storage-client/react';
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { useAuthState } from './useAuthState-BiGhtSCs.mjs';
2
+ import { useAuthState } from './useAuthState-CyF35qZR.mjs';
3
3
 
4
4
  const Authenticated = (t0) => {
5
5
  const {
@@ -3,6 +3,13 @@ import { c } from 'react/compiler-runtime';
3
3
  import { useState, useCallback } from 'react';
4
4
  import { jsxDEV } from 'react/jsx-dev-runtime';
5
5
 
6
+ const safeRedirectHref = (url) => {
7
+ const parsed = new URL(url, globalThis.location.href);
8
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
9
+ throw new Error(`refusing to redirect to a non-http(s) URL: ${parsed.protocol}`);
10
+ }
11
+ return parsed.href;
12
+ };
6
13
  const useCheckout = (trigger) => {
7
14
  const [pending, setPending] = useState(false);
8
15
  const [error, setError] = useState(void 0);
@@ -11,10 +18,7 @@ const useCheckout = (trigger) => {
11
18
  setError(void 0);
12
19
  try {
13
20
  const target = await trigger();
14
- const {
15
- url
16
- } = target;
17
- globalThis.location.assign(url);
21
+ globalThis.location.assign(safeRedirectHref(target.url));
18
22
  } catch (error_) {
19
23
  const normalized = error_ instanceof Error ? error_ : new Error(String(error_));
20
24
  setError(normalized);
@@ -1,5 +1,6 @@
1
1
  'use client';
2
2
  import { c } from 'react/compiler-runtime';
3
+ import { LunoraError } from '@lunora/errors';
3
4
  import { QueryClientContext, QueryClientProvider, QueryClient } from '@tanstack/react-query';
4
5
  import { use, useState, createContext } from 'react';
5
6
  import { jsxDEV } from 'react/jsx-dev-runtime';
@@ -37,7 +38,7 @@ const LunoraProvider = (t0) => {
37
38
  const [internalClient] = useState(t1);
38
39
  const effectiveClient = queryClient ?? parentQueryClient ?? internalClient;
39
40
  if (!effectiveClient) {
40
- throw new Error("LunoraProvider: failed to resolve a QueryClient");
41
+ throw new LunoraError("INTERNAL", "LunoraProvider: failed to resolve a QueryClient");
41
42
  }
42
43
  let t2;
43
44
  if ($[3] !== children || $[4] !== client) {
@@ -72,7 +73,7 @@ const LunoraProvider = (t0) => {
72
73
  const useLunora = () => {
73
74
  const client = use(LunoraContext);
74
75
  if (!client) {
75
- throw new Error("useLunora must be used inside <LunoraProvider />");
76
+ throw new LunoraError("INTERNAL", "useLunora must be used inside <LunoraProvider />");
76
77
  }
77
78
  return client;
78
79
  };
@@ -1,4 +1,4 @@
1
- import { k as keyHash } from './query-key-C5rufkEE.mjs';
1
+ import { k as keyHash } from './query-key-LGnArBTB.mjs';
2
2
 
3
3
  class LunoraSubscriptionRegistry {
4
4
  constructor(client) {
@@ -46,7 +46,12 @@ class LunoraSubscriptionRegistry {
46
46
  }
47
47
  }
48
48
  entry.refCount += 1;
49
+ let detached = false;
49
50
  return () => {
51
+ if (detached) {
52
+ return;
53
+ }
54
+ detached = true;
50
55
  const current = this.entries.get(key);
51
56
  if (!current) {
52
57
  return;
@@ -0,0 +1,54 @@
1
+ 'use client';
2
+ import { c } from 'react/compiler-runtime';
3
+ import { useQueryClient, useQuery } from '@tanstack/react-query';
4
+ import { useEffect } from 'react';
5
+ import { g as getSubscriptionRegistry } from './cache-JeuDAXfE.mjs';
6
+ import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
7
+ import { s as serializeQueryKey, l as lunoraQueryKey } from './query-key-LGnArBTB.mjs';
8
+
9
+ const usePreloadedQuery = function(preloaded) {
10
+ const $ = c(4);
11
+ const client = useLunora();
12
+ const queryClient = useQueryClient();
13
+ const {
14
+ args,
15
+ functionPath,
16
+ shardKey,
17
+ value
18
+ } = preloaded;
19
+ const functionRef = {
20
+ __lunoraRef: functionPath
21
+ };
22
+ const queryKey = lunoraQueryKey(functionRef, args, shardKey);
23
+ const {
24
+ data
25
+ } = useQuery({
26
+ initialData: value,
27
+ queryFn: () => client.query(functionRef, args, {
28
+ shardKey
29
+ }),
30
+ queryKey,
31
+ staleTime: Number.POSITIVE_INFINITY
32
+ });
33
+ const t0 = serializeQueryKey(queryKey);
34
+ let t1;
35
+ if ($[0] !== client || $[1] !== queryClient || $[2] !== t0) {
36
+ t1 = [client, queryClient, t0];
37
+ $[0] = client;
38
+ $[1] = queryClient;
39
+ $[2] = t0;
40
+ $[3] = t1;
41
+ } else {
42
+ t1 = $[3];
43
+ }
44
+ useEffect(() => {
45
+ const registry = getSubscriptionRegistry(client);
46
+ return registry.attach(queryClient, queryKey, functionRef, args, shardKey);
47
+ }, t1);
48
+ return data === void 0 ? value : data;
49
+ };
50
+ const hydratePreloaded = function(preloaded) {
51
+ return usePreloadedQuery(preloaded);
52
+ };
53
+
54
+ export { usePreloadedQuery as default, hydratePreloaded };
@@ -1,4 +1,4 @@
1
- import { l as lunoraQueryKey } from './query-key-C5rufkEE.mjs';
1
+ import { l as lunoraQueryKey } from './query-key-LGnArBTB.mjs';
2
2
 
3
3
  const lunoraQueryOptions = (client, function_, args, options = {}) => {
4
4
  const argsRecord = args ?? {};
@@ -0,0 +1,13 @@
1
+ import { s as stableWireKey } from './wire-key-Bg8BJ8YM.mjs';
2
+
3
+ const keyHash = (queryKey) => stableWireKey(queryKey);
4
+ const lunoraQueryKey = (function_, args, shardKey) => [
5
+ "lunora",
6
+ function_.__lunoraRef,
7
+ args,
8
+ // eslint-disable-next-line unicorn/no-null -- this literal is part of the JSON-serialized query key TanStack hashes for dedup; `null` keeps a stable, distinct slot from an absent shardKey across renders.
9
+ shardKey ?? null
10
+ ];
11
+ const serializeQueryKey = (queryKey) => keyHash(queryKey);
12
+
13
+ export { keyHash as k, lunoraQueryKey as l, serializeQueryKey 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,38 @@
1
+ const compareKeys = (a, b) => {
2
+ if (a < b) {
3
+ return -1;
4
+ }
5
+ return a > b ? 1 : 0;
6
+ };
7
+ const stableStringify = (value) => {
8
+ if (value === void 0) {
9
+ return "null";
10
+ }
11
+ if (typeof value === "bigint") {
12
+ throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");
13
+ }
14
+ if (value === null || typeof value !== "object") {
15
+ return JSON.stringify(value);
16
+ }
17
+ if (Array.isArray(value)) {
18
+ return `[${value.map((item) => stableStringify(item)).join(",")}]`;
19
+ }
20
+ const proto = Object.getPrototypeOf(value);
21
+ if (proto !== null && proto !== Object.prototype) {
22
+ const name = value.constructor?.name ?? "value";
23
+ throw new TypeError(`stableStringify: cannot use a ${name} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`);
24
+ }
25
+ const record = value;
26
+ const keys = Object.keys(record).toSorted(compareKeys);
27
+ const parts = [];
28
+ for (const key of keys) {
29
+ const raw = record[key];
30
+ if (raw === void 0) {
31
+ continue;
32
+ }
33
+ parts.push(`${JSON.stringify(key)}:${stableStringify(raw)}`);
34
+ }
35
+ return `{${parts.join(",")}}`;
36
+ };
37
+
38
+ export { stableStringify as s };
@@ -2,9 +2,9 @@
2
2
  import { initialPages, rebalance, derivePaginationStatus, applyLoadMore } from '@lunora/client/pagination';
3
3
  import { useQueryClient } from '@tanstack/react-query';
4
4
  import { useRef, useReducer, useState, useEffect, useCallback } from 'react';
5
- import { g as getSubscriptionRegistry } from './cache-CItk3fgN.mjs';
6
- import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
7
- import { s as serializeQueryKey, l as lunoraQueryKey } from './query-key-C5rufkEE.mjs';
5
+ import { g as getSubscriptionRegistry } from './cache-JeuDAXfE.mjs';
6
+ import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
7
+ import { s as serializeQueryKey, l as lunoraQueryKey } from './query-key-LGnArBTB.mjs';
8
8
 
9
9
  const useLazyRef = function(create) {
10
10
  const reference = useRef(void 0);
@@ -21,10 +21,9 @@ const usePaginatedCore = function(function_, args, options) {
21
21
  } = options;
22
22
  const skipped = args === "skip";
23
23
  const baseArgs = skipped ? {} : args;
24
- const baseArgsKey = JSON.stringify(baseArgs);
25
24
  const [, forceRender] = useReducer((tick) => tick + 1, 0);
26
25
  const [pages, setPages] = useState(() => initialPages(initialNumItems));
27
- const resetKey = `${function_.__lunoraRef}::${baseArgsKey}::${String(initialNumItems)}::${shardKey ?? ""}`;
26
+ const resetKey = `${serializeQueryKey(lunoraQueryKey(function_, baseArgs, shardKey))}::${String(initialNumItems)}`;
28
27
  const resetKeyRef = useRef(resetKey);
29
28
  if (resetKeyRef.current !== resetKey) {
30
29
  resetKeyRef.current = resetKey;
@@ -49,12 +48,14 @@ const usePaginatedCore = function(function_, args, options) {
49
48
  key: key_0
50
49
  }) => serializeQueryKey(key_0)).join("|");
51
50
  const desiredRef = useRef({
51
+ baseArgs,
52
52
  entries: [],
53
53
  fn: function_,
54
54
  shardKey
55
55
  });
56
56
  useEffect(() => {
57
57
  desiredRef.current = {
58
+ baseArgs,
58
59
  entries: pageEntries,
59
60
  fn: function_,
60
61
  shardKey
@@ -106,12 +107,16 @@ const usePaginatedCore = function(function_, args, options) {
106
107
  detaches.set(hash_0, registry.attach(queryClient, entry.key, desired.fn, entry.args, desired.shardKey));
107
108
  }
108
109
  }, [client, queryClient, pageKeysHash, skipped]);
109
- useEffect(() => () => {
110
- for (const detach_2 of detachesRef.current.values()) {
111
- detach_2();
112
- }
113
- detachesRef.current.clear();
114
- }, []);
110
+ useEffect(
111
+ () => () => {
112
+ for (const detach_2 of detachesRef.current.values()) {
113
+ detach_2();
114
+ }
115
+ detachesRef.current.clear();
116
+ },
117
+ // react-doctor-disable-next-line react-doctor/exhaustive-deps -- intentional: unmount-only cleanup. `detachesRef` is a stable ref, so the empty dep array is correct — the teardown must run once on unmount, not every render.
118
+ []
119
+ );
115
120
  useEffect(() => {
116
121
  const cache = queryClient.getQueryCache();
117
122
  const unsubscribe = cache.subscribe((event) => {
@@ -140,17 +145,30 @@ const usePaginatedCore = function(function_, args, options) {
140
145
  }
141
146
  });
142
147
  const {
143
- nextCursor,
144
148
  status
145
149
  } = derivePaginationStatus(skipped, pageResults);
146
- const nextCursorRef = useRef(void 0);
147
- useEffect(() => {
148
- nextCursorRef.current = status === "CanLoadMore" ? nextCursor : void 0;
149
- });
150
150
  const loadMore = useCallback((numberItems) => {
151
- const cursor = nextCursorRef.current;
152
- setPages((current) => applyLoadMore(current, cursor, numberItems) ?? current);
153
- }, []);
151
+ setPages((current) => {
152
+ const desired_0 = desiredRef.current;
153
+ const results = current.map((page_0) => {
154
+ const pageArgs_0 = {
155
+ ...desired_0.baseArgs,
156
+ paginationOpts: {
157
+ cursor: page_0.lower,
158
+ endCursor: page_0.upper,
159
+ numItems: page_0.numItems
160
+ }
161
+ };
162
+ return queryClient.getQueryData(lunoraQueryKey(desired_0.fn, pageArgs_0, desired_0.shardKey));
163
+ });
164
+ const {
165
+ nextCursor,
166
+ status: liveStatus
167
+ } = derivePaginationStatus(false, results);
168
+ const cursor = liveStatus === "CanLoadMore" ? nextCursor : void 0;
169
+ return applyLoadMore(current, cursor, numberItems) ?? current;
170
+ });
171
+ }, [queryClient]);
154
172
  return {
155
173
  loadMore,
156
174
  pageResults,
@@ -0,0 +1,101 @@
1
+ 'use client';
2
+ import { c } from 'react/compiler-runtime';
3
+ import { useMutation } from './useMutation-BeqeIjTr.mjs';
4
+ import useSubscription from './useSubscription-DcDlvVuI.mjs';
5
+
6
+ const NO_MUTATION_REF = {
7
+ __lunoraRef: ""
8
+ };
9
+ const useAgent = (options) => {
10
+ const $ = c(17);
11
+ const {
12
+ api,
13
+ cancel: cancelReference,
14
+ run: runReference,
15
+ runArgs,
16
+ threadKey
17
+ } = options;
18
+ const runMutation = useMutation(runReference);
19
+ const cancelMutation = useMutation(cancelReference ?? NO_MUTATION_REF);
20
+ let t0;
21
+ if ($[0] !== threadKey) {
22
+ t0 = {
23
+ key: threadKey
24
+ };
25
+ $[0] = threadKey;
26
+ $[1] = t0;
27
+ } else {
28
+ t0 = $[1];
29
+ }
30
+ const {
31
+ data: threadData
32
+ } = useSubscription(api.agents.agentThread, t0);
33
+ const thread = threadData;
34
+ const status = thread?.status;
35
+ const instanceId = thread?.instanceId;
36
+ const {
37
+ mutate: runMutate
38
+ } = runMutation;
39
+ const {
40
+ mutate: cancelMutate
41
+ } = cancelMutation;
42
+ let t1;
43
+ if ($[2] !== runArgs || $[3] !== runMutate || $[4] !== threadKey) {
44
+ t1 = async (input, args) => {
45
+ await runMutate({
46
+ input,
47
+ threadKey,
48
+ ...runArgs,
49
+ ...args
50
+ });
51
+ };
52
+ $[2] = runArgs;
53
+ $[3] = runMutate;
54
+ $[4] = threadKey;
55
+ $[5] = t1;
56
+ } else {
57
+ t1 = $[5];
58
+ }
59
+ const run = t1;
60
+ let t2;
61
+ if ($[6] !== cancelMutate || $[7] !== cancelReference || $[8] !== instanceId || $[9] !== threadKey) {
62
+ t2 = async () => {
63
+ if (cancelReference === void 0 || instanceId === void 0) {
64
+ return;
65
+ }
66
+ await cancelMutate({
67
+ instanceId,
68
+ threadKey
69
+ });
70
+ };
71
+ $[6] = cancelMutate;
72
+ $[7] = cancelReference;
73
+ $[8] = instanceId;
74
+ $[9] = threadKey;
75
+ $[10] = t2;
76
+ } else {
77
+ t2 = $[10];
78
+ }
79
+ const cancel = t2;
80
+ let t3;
81
+ if ($[11] !== cancel || $[12] !== run || $[13] !== runMutation.pending || $[14] !== status || $[15] !== thread) {
82
+ t3 = {
83
+ cancel,
84
+ pending: runMutation.pending,
85
+ run,
86
+ status,
87
+ thread
88
+ };
89
+ $[11] = cancel;
90
+ $[12] = run;
91
+ $[13] = runMutation.pending;
92
+ $[14] = status;
93
+ $[15] = thread;
94
+ $[16] = t3;
95
+ } else {
96
+ t3 = $[16];
97
+ }
98
+ return t3;
99
+ };
100
+
101
+ export { useAgent };