@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
@@ -0,0 +1,127 @@
1
+ 'use client';
2
+ import { useReducer, useRef, useEffect } from 'react';
3
+ import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
4
+ import { s as stableStringify } from './stable-key-DePnevIy.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 useHttpStream = (route, 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
+ dispatch({
59
+ type: "reset"
60
+ });
61
+ return () => {
62
+ };
63
+ }
64
+ dispatch({
65
+ type: "reset"
66
+ });
67
+ dispatch({
68
+ type: "start"
69
+ });
70
+ let stillMounted = true;
71
+ let cancelled = false;
72
+ const iterable = client.httpStream(route, args, {
73
+ maxBuffer: options.maxBuffer
74
+ });
75
+ const cancel = () => {
76
+ if (cancelled) {
77
+ return;
78
+ }
79
+ cancelled = true;
80
+ iterable.cancel();
81
+ };
82
+ cancelRef.current = cancel;
83
+ (async () => {
84
+ try {
85
+ for await (const chunk of iterable) {
86
+ if (!stillMounted) {
87
+ return;
88
+ }
89
+ dispatch({
90
+ chunk,
91
+ type: "chunk"
92
+ });
93
+ }
94
+ if (stillMounted) {
95
+ dispatch({
96
+ type: "complete"
97
+ });
98
+ }
99
+ } catch (error) {
100
+ if (!stillMounted) {
101
+ return;
102
+ }
103
+ const normalized = error instanceof Error ? error : new Error(String(error));
104
+ dispatch({
105
+ error: normalized,
106
+ type: "error"
107
+ });
108
+ }
109
+ })().catch(() => {
110
+ });
111
+ return () => {
112
+ stillMounted = false;
113
+ cancel();
114
+ cancelRef.current = void 0;
115
+ };
116
+ }, [client, route.method, route.path, serialized, skipped, options.maxBuffer]);
117
+ return {
118
+ cancel: () => {
119
+ cancelRef.current?.();
120
+ },
121
+ chunks: state.chunks,
122
+ error: state.error,
123
+ status: state.status
124
+ };
125
+ };
126
+
127
+ export { useHttpStream };
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { c } from 'react/compiler-runtime';
3
3
  import { useRef, useEffect } from 'react';
4
- import { u as usePaginatedCore } from './use-paginated-core-CoOfcc-p.mjs';
4
+ import { u as usePaginatedCore } from './use-paginated-core-xxvd1YA0.mjs';
5
5
 
6
6
  const useInfiniteQuery = (function_, args, options) => {
7
7
  const $ = c(15);
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { useMutation as useMutation$1 } from '@tanstack/react-query';
3
3
  import { useRef, useState, useCallback } from 'react';
4
- import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
4
+ import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
5
5
 
6
6
  const useMutation = (function_) => {
7
7
  const client = useLunora();
@@ -0,0 +1,47 @@
1
+ 'use client';
2
+ import { c } from 'react/compiler-runtime';
3
+ import { createMutatorRunner } from '@lunora/client';
4
+ import { useState } from 'react';
5
+
6
+ const useMutator = function useMutator2(handle) {
7
+ const $ = c(8);
8
+ const [pending, setPending] = useState(false);
9
+ const [error, setError] = useState(void 0);
10
+ let t0;
11
+ if ($[0] !== handle) {
12
+ t0 = createMutatorRunner(handle, {
13
+ setError,
14
+ setPending
15
+ });
16
+ $[0] = handle;
17
+ $[1] = t0;
18
+ } else {
19
+ t0 = $[1];
20
+ }
21
+ const {
22
+ mutate,
23
+ reset
24
+ } = t0;
25
+ const t1 = error !== void 0;
26
+ let t2;
27
+ if ($[2] !== error || $[3] !== mutate || $[4] !== pending || $[5] !== reset || $[6] !== t1) {
28
+ t2 = {
29
+ error,
30
+ isError: t1,
31
+ mutate,
32
+ pending,
33
+ reset
34
+ };
35
+ $[2] = error;
36
+ $[3] = mutate;
37
+ $[4] = pending;
38
+ $[5] = reset;
39
+ $[6] = t1;
40
+ $[7] = t2;
41
+ } else {
42
+ t2 = $[7];
43
+ }
44
+ return t2;
45
+ };
46
+
47
+ export { useMutator };
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { c } from 'react/compiler-runtime';
3
- import { u as usePaginatedCore } from './use-paginated-core-CoOfcc-p.mjs';
3
+ import { u as usePaginatedCore } from './use-paginated-core-xxvd1YA0.mjs';
4
4
 
5
5
  const usePaginatedQuery = (function_, args, options) => {
6
6
  const $ = c(7);
@@ -1,13 +1,20 @@
1
1
  'use client';
2
2
  import { useMemo, useState, useRef, useEffect, useCallback } from 'react';
3
- import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
3
+ import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
4
4
 
5
- const makeSessionId = () => {
6
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
7
- return crypto.randomUUID();
5
+ const randomSessionId = (prefix = "sess") => {
6
+ if (typeof crypto !== "undefined") {
7
+ if (typeof crypto.randomUUID === "function") {
8
+ return crypto.randomUUID();
9
+ }
10
+ if (typeof crypto.getRandomValues === "function") {
11
+ const bytes = crypto.getRandomValues(new Uint8Array(16));
12
+ return `${prefix}-${Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
13
+ }
8
14
  }
9
- return `sess-${Math.random().toString(36).slice(2)}-${String(Date.now())}`;
15
+ return `${prefix}-${Date.now().toString(36)}`;
10
16
  };
17
+
11
18
  const DEFAULT_INTERVAL_MS = 1e4;
12
19
  const usePresence = (roomId, options) => {
13
20
  const client = useLunora();
@@ -17,7 +24,7 @@ const usePresence = (roomId, options) => {
17
24
  listPresent,
18
25
  shardKey
19
26
  } = options;
20
- const generatedSessionId = useMemo(() => options.sessionId ?? makeSessionId(), [options.sessionId]);
27
+ const generatedSessionId = useMemo(() => options.sessionId ?? randomSessionId(), [options.sessionId]);
21
28
  const [present, setPresent] = useState(void 0);
22
29
  const dataRef = useRef(options.data);
23
30
  const inputsRef = useRef({
@@ -0,0 +1,77 @@
1
+ 'use client';
2
+ import { c } from 'react/compiler-runtime';
3
+ import { useQueryClient, useQuery as useQuery$1 } from '@tanstack/react-query';
4
+ import { useState, 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 useQuery = (function_, args, t0) => {
10
+ const $ = c(9);
11
+ const options = t0 === void 0 ? {} : t0;
12
+ const client = useLunora();
13
+ const queryClient = useQueryClient();
14
+ const {
15
+ shardKey
16
+ } = options;
17
+ const skipped = args === "skip";
18
+ const argsRecord = skipped ? {} : args;
19
+ const queryKey = lunoraQueryKey(function_, argsRecord, shardKey);
20
+ const [hydrated, setHydrated] = useState(client.isReady);
21
+ let t1;
22
+ let t2;
23
+ if ($[0] !== client || $[1] !== hydrated) {
24
+ t1 = () => {
25
+ if (!hydrated) {
26
+ client.whenReady().then(() => {
27
+ setHydrated(true);
28
+ });
29
+ }
30
+ };
31
+ t2 = [client, hydrated];
32
+ $[0] = client;
33
+ $[1] = hydrated;
34
+ $[2] = t1;
35
+ $[3] = t2;
36
+ } else {
37
+ t1 = $[2];
38
+ t2 = $[3];
39
+ }
40
+ useEffect(t1, t2);
41
+ const cachedData = skipped ? void 0 : client.peekHydratedQuery(function_.__lunoraRef, argsRecord, shardKey);
42
+ const {
43
+ data
44
+ } = useQuery$1({
45
+ enabled: !skipped && hydrated,
46
+ initialData: cachedData,
47
+ queryFn: () => client.query(function_, argsRecord, {
48
+ shardKey
49
+ }),
50
+ queryKey,
51
+ staleTime: Number.POSITIVE_INFINITY
52
+ });
53
+ const t3 = serializeQueryKey(queryKey);
54
+ let t4;
55
+ if ($[4] !== client || $[5] !== queryClient || $[6] !== skipped || $[7] !== t3) {
56
+ t4 = [client, queryClient, t3, skipped];
57
+ $[4] = client;
58
+ $[5] = queryClient;
59
+ $[6] = skipped;
60
+ $[7] = t3;
61
+ $[8] = t4;
62
+ } else {
63
+ t4 = $[8];
64
+ }
65
+ useEffect(() => {
66
+ if (skipped) {
67
+ return _temp;
68
+ }
69
+ const registry = getSubscriptionRegistry(client);
70
+ return registry.attach(queryClient, queryKey, function_, argsRecord, shardKey);
71
+ }, t4);
72
+ return skipped ? void 0 : data;
73
+ };
74
+ function _temp() {
75
+ }
76
+
77
+ export { useQuery as default };
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { useReducer, useRef, useEffect } from 'react';
3
- import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
4
- import { a as stableStringify } from './query-key-C5rufkEE.mjs';
3
+ import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
4
+ import { s as stableWireKey } from './wire-key-Bg8BJ8YM.mjs';
5
5
 
6
6
  const reducer = function(state, action) {
7
7
  switch (action.type) {
@@ -51,10 +51,13 @@ const useStream = (function_, args, options = {}) => {
51
51
  status: "idle"
52
52
  });
53
53
  const skipped = args === "skip";
54
- const serialized = skipped ? "skip" : stableStringify(args);
54
+ const serialized = skipped ? "skip" : stableWireKey(args);
55
55
  const cancelRef = useRef(void 0);
56
56
  useEffect(() => {
57
57
  if (skipped) {
58
+ dispatch({
59
+ type: "reset"
60
+ });
58
61
  return () => {
59
62
  };
60
63
  }
@@ -2,8 +2,8 @@
2
2
  import { c } from 'react/compiler-runtime';
3
3
  import { createQuerySubscription } from '@lunora/client/query';
4
4
  import { useState, useRef, useEffect } from 'react';
5
- import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
6
- import { a as stableStringify } from './query-key-C5rufkEE.mjs';
5
+ import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
6
+ import { s as stableWireKey } from './wire-key-Bg8BJ8YM.mjs';
7
7
 
8
8
  const useSubscription = (function_, args, t0) => {
9
9
  const $ = c(22);
@@ -31,7 +31,7 @@ const useSubscription = (function_, args, t0) => {
31
31
  const skipped = args === "skip";
32
32
  let t3;
33
33
  if ($[3] !== args || $[4] !== skipped) {
34
- t3 = skipped ? "skip" : stableStringify(args);
34
+ t3 = skipped ? "skip" : stableWireKey(args);
35
35
  $[3] = args;
36
36
  $[4] = skipped;
37
37
  $[5] = t3;