@lunora/react 1.0.0-alpha.6 → 1.0.0-alpha.60

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 (69) hide show
  1. package/LICENSE.md +6 -0
  2. package/dist/index.d.mts +1091 -285
  3. package/dist/index.d.ts +1091 -285
  4. package/dist/index.mjs +1 -17
  5. package/dist/packem_shared/AuthLoading-dC08yqew.mjs +2 -0
  6. package/dist/packem_shared/CheckoutButton-D8MutXhg.mjs +2 -0
  7. package/dist/packem_shared/LunoraProvider-DC06S-p1.mjs +2 -0
  8. package/dist/packem_shared/cache-CTiPqpnJ.mjs +1 -0
  9. package/dist/packem_shared/hydratePreloaded-BPpDZCHN.mjs +2 -0
  10. package/dist/packem_shared/lunoraQueryOptions-DD7WJ_yD.mjs +1 -0
  11. package/dist/packem_shared/query-key-ClQy24bz.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-ITGZkfuz.mjs +1 -0
  15. package/dist/packem_shared/stream-state-abygFxmy.mjs +1 -0
  16. package/dist/packem_shared/use-paginated-core-h9Wli0Mz.mjs +2 -0
  17. package/dist/packem_shared/useAction-CUSJu4yq.mjs +2 -0
  18. package/dist/packem_shared/useAgent-CS_LwSOE.mjs +2 -0
  19. package/dist/packem_shared/useAgentChat-DkJWSaoP.mjs +2 -0
  20. package/dist/packem_shared/useAgentState-IDjPrM2M.mjs +2 -0
  21. package/dist/packem_shared/useAgentToolEvents-BkmO_ier.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-D1_5nm0u.mjs +2 -0
  28. package/dist/packem_shared/useHttpStream-G6MZua0D.mjs +2 -0
  29. package/dist/packem_shared/useInfiniteQuery-vjMIP0oP.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-CmjjsHpF.mjs +2 -0
  33. package/dist/packem_shared/usePresence-DsYEO_XX.mjs +2 -0
  34. package/dist/packem_shared/useQuery-DF5z4yjg.mjs +2 -0
  35. package/dist/packem_shared/useRateLimit-Cckxi8m9.mjs +2 -0
  36. package/dist/packem_shared/useStream-CHFc-JdW.mjs +2 -0
  37. package/dist/packem_shared/useSubscription-CgncCiE2.mjs +2 -0
  38. package/dist/packem_shared/useVoiceAgent-BziH3D-1.mjs +2 -0
  39. package/dist/packem_shared/wire-key-D-_PTDGR.mjs +1 -0
  40. package/dist/server.d.mts +47 -29
  41. package/dist/server.d.ts +47 -29
  42. package/dist/server.mjs +1 -31
  43. package/dist/upload.d.mts +23 -0
  44. package/dist/upload.d.ts +23 -0
  45. package/dist/upload.mjs +2 -0
  46. package/package.json +10 -4
  47. package/dist/packem_shared/AuthLoading-DtKgZT2Z.mjs +0 -33
  48. package/dist/packem_shared/CheckoutButton-CVSry8U1.mjs +0 -185
  49. package/dist/packem_shared/LunoraProvider-D38Xp16l.mjs +0 -80
  50. package/dist/packem_shared/cache-CAp1fVNL.mjs +0 -75
  51. package/dist/packem_shared/hydratePreloaded-B6OHn0eL.mjs +0 -46
  52. package/dist/packem_shared/lunoraQueryOptions-Cij4KWBK.mjs +0 -16
  53. package/dist/packem_shared/query-key-B5eRQCbR.mjs +0 -13
  54. package/dist/packem_shared/query-options.d-D4okOpO8.d.mts +0 -38
  55. package/dist/packem_shared/query-options.d-D4okOpO8.d.ts +0 -38
  56. package/dist/packem_shared/stable-key-CaKZv9lp.mjs +0 -30
  57. package/dist/packem_shared/use-paginated-core-DxGvzQVR.mjs +0 -161
  58. package/dist/packem_shared/useAuth-CNUKtOOp.mjs +0 -129
  59. package/dist/packem_shared/useAuthState-BiGhtSCs.mjs +0 -36
  60. package/dist/packem_shared/useConnectionStatus-DRSY9ldm.mjs +0 -30
  61. package/dist/packem_shared/useFlag-Bg5DpkGv.mjs +0 -224
  62. package/dist/packem_shared/useInfiniteQuery-HjOCDd3R.mjs +0 -97
  63. package/dist/packem_shared/useMutation-CrvMXRsk.mjs +0 -67
  64. package/dist/packem_shared/usePaginatedQuery-BGYvICZU.mjs +0 -46
  65. package/dist/packem_shared/usePresence-D7jLuxj0.mjs +0 -108
  66. package/dist/packem_shared/useQuery-EB74gtBJ.mjs +0 -42
  67. package/dist/packem_shared/useRateLimit-DTEffQEi.mjs +0 -64
  68. package/dist/packem_shared/useStream-MdYnWDL_.mjs +0 -125
  69. package/dist/packem_shared/useSubscription-DSJuryrU.mjs +0 -139
@@ -1,67 +0,0 @@
1
- 'use client';
2
- import { useMutation as useMutation$1 } from '@tanstack/react-query';
3
- import { useRef, useState, useCallback } from 'react';
4
- import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
5
-
6
- const useMutation = (function_) => {
7
- const client = useLunora();
8
- const pendingCountRef = useRef(0);
9
- const [pending, setPending] = useState(false);
10
- const mutation = useMutation$1({
11
- mutationFn: ({
12
- args,
13
- options
14
- }) => client.mutation(function_, args, options),
15
- // `onMutate` fires when a call starts, `onSettled` when it resolves or
16
- // rejects — so overlapping calls compose and `pending` only clears once
17
- // the last one settles.
18
- onMutate: () => {
19
- pendingCountRef.current += 1;
20
- setPending(true);
21
- },
22
- onSettled: () => {
23
- pendingCountRef.current -= 1;
24
- setPending(pendingCountRef.current > 0);
25
- }
26
- });
27
- const {
28
- data,
29
- error,
30
- isError,
31
- mutateAsync,
32
- reset
33
- } = mutation;
34
- const mutate = useCallback((args_0, options_0) => mutateAsync({
35
- args: args_0,
36
- options: options_0
37
- }), [mutateAsync]);
38
- const withOptimisticUpdate = useCallback((update) => {
39
- const boundMutate = (args_1, options_1) => mutateAsync({
40
- args: args_1,
41
- options: {
42
- optimisticUpdate: update,
43
- ...options_1
44
- }
45
- });
46
- return {
47
- data,
48
- error,
49
- isError,
50
- mutate: boundMutate,
51
- pending,
52
- reset,
53
- withOptimisticUpdate
54
- };
55
- }, [mutateAsync, data, error, isError, pending, reset]);
56
- return {
57
- data,
58
- error,
59
- isError,
60
- mutate,
61
- pending,
62
- reset,
63
- withOptimisticUpdate
64
- };
65
- };
66
-
67
- export { useMutation };
@@ -1,46 +0,0 @@
1
- 'use client';
2
- import { c } from 'react/compiler-runtime';
3
- import { u as usePaginatedCore } from './use-paginated-core-DxGvzQVR.mjs';
4
-
5
- const usePaginatedQuery = (function_, args, options) => {
6
- const $ = c(7);
7
- const {
8
- loadMore,
9
- pageResults,
10
- status
11
- } = usePaginatedCore(function_, args === "skip" ? "skip" : args, options);
12
- let results;
13
- if ($[0] !== pageResults) {
14
- results = [];
15
- for (const result of pageResults) {
16
- if (result) {
17
- results.push(...result.page);
18
- }
19
- }
20
- $[0] = pageResults;
21
- $[1] = results;
22
- } else {
23
- results = $[1];
24
- }
25
- const skipped = args === "skip";
26
- const t0 = !skipped && (status === "LoadingFirstPage" || status === "LoadingMore");
27
- let t1;
28
- if ($[2] !== loadMore || $[3] !== results || $[4] !== status || $[5] !== t0) {
29
- t1 = {
30
- isLoading: t0,
31
- loadMore,
32
- results,
33
- status
34
- };
35
- $[2] = loadMore;
36
- $[3] = results;
37
- $[4] = status;
38
- $[5] = t0;
39
- $[6] = t1;
40
- } else {
41
- t1 = $[6];
42
- }
43
- return t1;
44
- };
45
-
46
- export { usePaginatedQuery };
@@ -1,108 +0,0 @@
1
- 'use client';
2
- import { useMemo, useState, useRef, useEffect, useCallback } from 'react';
3
- import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
4
-
5
- const makeSessionId = () => {
6
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
7
- return crypto.randomUUID();
8
- }
9
- return `sess-${Math.random().toString(36).slice(2)}-${String(Date.now())}`;
10
- };
11
- const DEFAULT_INTERVAL_MS = 1e4;
12
- const usePresence = (roomId, options) => {
13
- const client = useLunora();
14
- const {
15
- heartbeat,
16
- intervalMs = DEFAULT_INTERVAL_MS,
17
- listPresent,
18
- shardKey
19
- } = options;
20
- const generatedSessionId = useMemo(() => options.sessionId ?? makeSessionId(), [options.sessionId]);
21
- const [present, setPresent] = useState(void 0);
22
- const dataRef = useRef(options.data);
23
- const inputsRef = useRef({
24
- client,
25
- heartbeat,
26
- roomId,
27
- sessionId: generatedSessionId,
28
- shardKey
29
- });
30
- useEffect(() => {
31
- inputsRef.current = {
32
- client,
33
- heartbeat,
34
- roomId,
35
- sessionId: generatedSessionId,
36
- shardKey
37
- };
38
- });
39
- const sendHeartbeat = useCallback(() => {
40
- const {
41
- client: c,
42
- heartbeat: hb,
43
- roomId: room,
44
- sessionId: sid,
45
- shardKey: sk
46
- } = inputsRef.current;
47
- const args = {
48
- roomId: room,
49
- sessionId: sid,
50
- ...dataRef.current === void 0 ? {} : {
51
- data: dataRef.current
52
- }
53
- };
54
- c.mutation(hb, args, {
55
- shardKey: sk
56
- }).catch(() => void 0);
57
- }, []);
58
- const setData = useCallback((next) => {
59
- dataRef.current = next;
60
- sendHeartbeat();
61
- }, [sendHeartbeat]);
62
- useEffect(() => {
63
- sendHeartbeat();
64
- const handle = setInterval(sendHeartbeat, intervalMs);
65
- const onVisible = () => {
66
- if (document.visibilityState === "visible") {
67
- sendHeartbeat();
68
- }
69
- };
70
- document.addEventListener("visibilitychange", onVisible);
71
- return () => {
72
- clearInterval(handle);
73
- document.removeEventListener("visibilitychange", onVisible);
74
- };
75
- }, [sendHeartbeat, intervalMs]);
76
- useEffect(() => {
77
- const release = client.acquireConnectionContext({
78
- roomId,
79
- sessionId: generatedSessionId
80
- }, {
81
- shardKey
82
- });
83
- return release;
84
- }, [client, roomId, generatedSessionId, shardKey]);
85
- useEffect(() => {
86
- let cancelled = false;
87
- const unsubscribe = client.subscribe(listPresent, {
88
- roomId
89
- }, (value) => {
90
- if (!cancelled) {
91
- setPresent(value);
92
- }
93
- }, {
94
- shardKey
95
- });
96
- return () => {
97
- cancelled = true;
98
- unsubscribe();
99
- };
100
- }, [client, listPresent.__lunoraRef, roomId, shardKey]);
101
- return {
102
- present,
103
- sessionId: generatedSessionId,
104
- setData
105
- };
106
- };
107
-
108
- export { usePresence };
@@ -1,42 +0,0 @@
1
- 'use client';
2
- import { useQueryClient, useQuery as useQuery$1 } from '@tanstack/react-query';
3
- import { useMemo, useEffect } from 'react';
4
- import { g as getSubscriptionRegistry } from './cache-CAp1fVNL.mjs';
5
- import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
6
- import { l as lunoraQueryKey, s as serializeQueryKey } from './query-key-B5eRQCbR.mjs';
7
- import { s as stableStringify } from './stable-key-CaKZv9lp.mjs';
8
-
9
- const useQuery = (function_, args, options = {}) => {
10
- const client = useLunora();
11
- const queryClient = useQueryClient();
12
- const {
13
- shardKey
14
- } = options;
15
- const skipped = args === "skip";
16
- const argsRecord = skipped ? {} : args;
17
- const queryKey = useMemo(() => lunoraQueryKey(function_, argsRecord, shardKey), [function_.__lunoraRef, stableStringify(argsRecord), shardKey]);
18
- const {
19
- data
20
- } = useQuery$1({
21
- enabled: !skipped,
22
- queryFn: () => client.query(function_, argsRecord, {
23
- shardKey
24
- }),
25
- queryKey,
26
- // Lunora is push-driven: once the initial fetch resolves, the WS owns
27
- // freshness. Staleness only matters when the subscription is missing,
28
- // and the registry handles that with a polling fallback.
29
- staleTime: Number.POSITIVE_INFINITY
30
- });
31
- useEffect(() => {
32
- if (skipped) {
33
- return () => {
34
- };
35
- }
36
- const registry = getSubscriptionRegistry(client);
37
- return registry.attach(queryClient, queryKey, function_, argsRecord, shardKey);
38
- }, [client, queryClient, serializeQueryKey(queryKey), skipped]);
39
- return data;
40
- };
41
-
42
- export { useQuery as default };
@@ -1,64 +0,0 @@
1
- 'use client';
2
- import { evaluate } from '@lunora/ratelimit';
3
- import { useRef, useReducer, useCallback, useEffect } from 'react';
4
-
5
- const useRateLimit = (config, options = {}) => {
6
- const now = options.now ?? Date.now;
7
- const tickMs = options.tickMs ?? 1e3;
8
- const valueRef = useRef(void 0);
9
- const [, forceRender] = useReducer((count) => count + 1, 0);
10
- const consume = useCallback((count_0 = 1) => {
11
- const {
12
- status,
13
- value
14
- } = evaluate(config, valueRef.current, {
15
- consume: true,
16
- count: count_0,
17
- now: now(),
18
- reserve: false
19
- });
20
- if (value !== void 0) {
21
- valueRef.current = value;
22
- }
23
- forceRender();
24
- return status;
25
- }, [config, now]);
26
- const check = useCallback((count_1 = 1) => evaluate(config, valueRef.current, {
27
- consume: false,
28
- count: count_1,
29
- now: now(),
30
- reserve: false
31
- }).status.ok, [config, now]);
32
- const reset = useCallback(() => {
33
- valueRef.current = void 0;
34
- forceRender();
35
- }, []);
36
- const {
37
- status: status_0
38
- } = evaluate(config, valueRef.current, {
39
- consume: false,
40
- count: 1,
41
- now: now(),
42
- reserve: false
43
- });
44
- useEffect(() => {
45
- if (status_0.ok) {
46
- return () => {
47
- };
48
- }
49
- const handle = setInterval(forceRender, tickMs);
50
- return () => {
51
- clearInterval(handle);
52
- };
53
- }, [status_0.ok, tickMs]);
54
- return {
55
- check,
56
- consume,
57
- disabled: !status_0.ok,
58
- ok: status_0.ok,
59
- reset,
60
- retryAfter: status_0.retryAfter
61
- };
62
- };
63
-
64
- export { useRateLimit };
@@ -1,125 +0,0 @@
1
- 'use client';
2
- import { useReducer, useRef, useEffect } from 'react';
3
- import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
4
- import { s as stableStringify } from './stable-key-CaKZv9lp.mjs';
5
-
6
- const reducer = function(state, action) {
7
- switch (action.type) {
8
- case "chunk": {
9
- return {
10
- chunks: [...state.chunks, action.chunk],
11
- error: void 0,
12
- status: "streaming"
13
- };
14
- }
15
- case "complete": {
16
- return {
17
- ...state,
18
- status: "complete"
19
- };
20
- }
21
- case "error": {
22
- return {
23
- ...state,
24
- error: action.error,
25
- status: "error"
26
- };
27
- }
28
- case "reset": {
29
- return {
30
- chunks: [],
31
- error: void 0,
32
- status: "idle"
33
- };
34
- }
35
- case "start": {
36
- return {
37
- ...state,
38
- status: "streaming"
39
- };
40
- }
41
- default: {
42
- return state;
43
- }
44
- }
45
- };
46
- const useStream = (function_, args, options = {}) => {
47
- const client = useLunora();
48
- const [state, dispatch] = useReducer(reducer, {
49
- chunks: [],
50
- error: void 0,
51
- status: "idle"
52
- });
53
- const skipped = args === "skip";
54
- const serialized = skipped ? "skip" : stableStringify(args);
55
- const cancelRef = useRef(void 0);
56
- useEffect(() => {
57
- if (skipped) {
58
- return () => {
59
- };
60
- }
61
- dispatch({
62
- type: "reset"
63
- });
64
- dispatch({
65
- type: "start"
66
- });
67
- let stillMounted = true;
68
- let cancelled = false;
69
- const iterable = client.stream(function_, args, {
70
- maxBuffer: options.maxBuffer,
71
- shardKey: options.shardKey
72
- });
73
- const cancel = () => {
74
- if (cancelled) {
75
- return;
76
- }
77
- cancelled = true;
78
- iterable.cancel();
79
- };
80
- cancelRef.current = cancel;
81
- (async () => {
82
- try {
83
- for await (const chunk of iterable) {
84
- if (!stillMounted) {
85
- return;
86
- }
87
- dispatch({
88
- chunk,
89
- type: "chunk"
90
- });
91
- }
92
- if (stillMounted) {
93
- dispatch({
94
- type: "complete"
95
- });
96
- }
97
- } catch (error) {
98
- if (!stillMounted) {
99
- return;
100
- }
101
- const normalized = error instanceof Error ? error : new Error(String(error));
102
- dispatch({
103
- error: normalized,
104
- type: "error"
105
- });
106
- }
107
- })().catch(() => {
108
- });
109
- return () => {
110
- stillMounted = false;
111
- cancel();
112
- cancelRef.current = void 0;
113
- };
114
- }, [client, function_.__lunoraRef, serialized, skipped, options.shardKey, options.maxBuffer]);
115
- return {
116
- cancel: () => {
117
- cancelRef.current?.();
118
- },
119
- chunks: state.chunks,
120
- error: state.error,
121
- status: state.status
122
- };
123
- };
124
-
125
- export { useStream };
@@ -1,139 +0,0 @@
1
- 'use client';
2
- import { c } from 'react/compiler-runtime';
3
- import { createQuerySubscription } from '@lunora/client/query';
4
- import { useState, useRef, useEffect } from 'react';
5
- import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
6
- import { s as stableStringify } from './stable-key-CaKZv9lp.mjs';
7
-
8
- const useSubscription = (function_, args, t0) => {
9
- const $ = c(22);
10
- let t1;
11
- if ($[0] !== t0) {
12
- t1 = t0 === void 0 ? {} : t0;
13
- $[0] = t0;
14
- $[1] = t1;
15
- } else {
16
- t1 = $[1];
17
- }
18
- const options = t1;
19
- const client = useLunora();
20
- let t2;
21
- if ($[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
22
- t2 = {
23
- data: void 0,
24
- error: void 0
25
- };
26
- $[2] = t2;
27
- } else {
28
- t2 = $[2];
29
- }
30
- const [state, setState] = useState(t2);
31
- const skipped = args === "skip";
32
- let t3;
33
- if ($[3] !== args || $[4] !== skipped) {
34
- t3 = skipped ? "skip" : stableStringify(args);
35
- $[3] = args;
36
- $[4] = skipped;
37
- $[5] = t3;
38
- } else {
39
- t3 = $[5];
40
- }
41
- const serialized = t3;
42
- let t4;
43
- if ($[6] !== args || $[7] !== function_) {
44
- t4 = {
45
- args,
46
- fn: function_
47
- };
48
- $[6] = args;
49
- $[7] = function_;
50
- $[8] = t4;
51
- } else {
52
- t4 = $[8];
53
- }
54
- const subscribeRef = useRef(t4);
55
- let t5;
56
- if ($[9] !== args || $[10] !== function_) {
57
- t5 = () => {
58
- subscribeRef.current = {
59
- args,
60
- fn: function_
61
- };
62
- };
63
- $[9] = args;
64
- $[10] = function_;
65
- $[11] = t5;
66
- } else {
67
- t5 = $[11];
68
- }
69
- useEffect(t5);
70
- let t6;
71
- if ($[12] !== client || $[13] !== options.shardKey || $[14] !== skipped) {
72
- t6 = () => {
73
- if (skipped) {
74
- setState({
75
- data: void 0,
76
- error: void 0
77
- });
78
- return _temp;
79
- }
80
- let cancelled = false;
81
- const {
82
- args: currentArgs,
83
- fn: currentFunction
84
- } = subscribeRef.current;
85
- const unsubscribe = createQuerySubscription(client, currentFunction, currentArgs, {
86
- onData: (value) => {
87
- if (cancelled) {
88
- return;
89
- }
90
- setState({
91
- data: value,
92
- error: void 0
93
- });
94
- },
95
- onError: (error) => {
96
- const normalized = new Error(error.message);
97
- queueMicrotask(() => {
98
- if (!cancelled) {
99
- setState({
100
- data: void 0,
101
- error: normalized
102
- });
103
- }
104
- });
105
- }
106
- }, {
107
- shardKey: options.shardKey
108
- });
109
- return () => {
110
- cancelled = true;
111
- unsubscribe();
112
- };
113
- };
114
- $[12] = client;
115
- $[13] = options.shardKey;
116
- $[14] = skipped;
117
- $[15] = t6;
118
- } else {
119
- t6 = $[15];
120
- }
121
- let t7;
122
- if ($[16] !== client || $[17] !== function_.__lunoraRef || $[18] !== options.shardKey || $[19] !== serialized || $[20] !== skipped) {
123
- t7 = [client, function_.__lunoraRef, serialized, options.shardKey, skipped];
124
- $[16] = client;
125
- $[17] = function_.__lunoraRef;
126
- $[18] = options.shardKey;
127
- $[19] = serialized;
128
- $[20] = skipped;
129
- $[21] = t7;
130
- } else {
131
- t7 = $[21];
132
- }
133
- useEffect(t6, t7);
134
- return state;
135
- };
136
- function _temp() {
137
- }
138
-
139
- export { useSubscription as default };