@lunora/react 1.0.0-alpha.29 → 1.0.0-alpha.291
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.
- package/README.md +28 -18
- package/dist/index.d.mts +603 -170
- package/dist/index.d.ts +603 -170
- package/dist/index.mjs +1 -26
- package/dist/packem_shared/AuthLoading-Dqb9692o.mjs +2 -0
- package/dist/packem_shared/LunoraProvider-CypI20I0.mjs +1 -0
- package/dist/packem_shared/hydratePreloaded-C94hJet3.mjs +2 -0
- package/dist/packem_shared/lunora-provider-D15UPNFD.mjs +2 -0
- package/dist/packem_shared/query-core-DG86Lpnw.mjs +2 -0
- package/dist/packem_shared/stream-state-abygFxmy.mjs +1 -0
- package/dist/packem_shared/use-paginated-core-Cw465bR1.mjs +2 -0
- package/dist/packem_shared/useAction-CIlUzQVY.mjs +2 -0
- package/dist/packem_shared/useAgent-BBuc2RNx.mjs +2 -0
- package/dist/packem_shared/useAgentApprovals-yiIGlGck.mjs +2 -0
- package/dist/packem_shared/useAgentChat-Igz_15YO.mjs +2 -0
- package/dist/packem_shared/useAgentState-DbQmCmhH.mjs +2 -0
- package/dist/packem_shared/useAgentToolEvents-vgG15IZX.mjs +2 -0
- package/dist/packem_shared/useAuth-DTiEKNfL.mjs +2 -0
- package/dist/packem_shared/useAuthSessions-BSS2wfV4.mjs +2 -0
- package/dist/packem_shared/useAuthState-CFScqFAf.mjs +2 -0
- package/dist/packem_shared/useClientQuery-D01Sx8wn.mjs +2 -0
- package/dist/packem_shared/useConnectionStatus-VYjmmafS.mjs +2 -0
- package/dist/packem_shared/useFlag-CHzI2R8e.mjs +2 -0
- package/dist/packem_shared/useHttpStream-B32eZ6DN.mjs +2 -0
- package/dist/packem_shared/useInfiniteQuery-ycnpzlqm.mjs +2 -0
- package/dist/packem_shared/useLiveTopic-DzP_8Gf3.mjs +2 -0
- package/dist/packem_shared/useMutation-BfuQVXiY.mjs +2 -0
- package/dist/packem_shared/useMutator-BtUd-xEA.mjs +2 -0
- package/dist/packem_shared/usePaginatedQuery-CYB8h_E5.mjs +2 -0
- package/dist/packem_shared/usePresence-UDDcnYXw.mjs +2 -0
- package/dist/packem_shared/useQuery-BewsLSm_.mjs +2 -0
- package/dist/packem_shared/useRateLimit-Cckxi8m9.mjs +2 -0
- package/dist/packem_shared/useStream-D__0Rgzf.mjs +2 -0
- package/dist/packem_shared/useSubscription-P-_MNJm6.mjs +2 -0
- package/dist/packem_shared/useSuspenseQuery-5wC1or5S.mjs +2 -0
- package/dist/packem_shared/useVoiceAgent-iTIf7__2.mjs +2 -0
- package/dist/payment.d.mts +107 -0
- package/dist/payment.d.ts +107 -0
- package/dist/payment.mjs +2 -0
- package/dist/server.d.mts +74 -2
- package/dist/server.d.ts +74 -2
- package/dist/server.mjs +1 -31
- package/dist/upload.d.mts +24 -0
- package/dist/upload.d.ts +24 -0
- package/dist/upload.mjs +2 -0
- package/package.json +14 -4
- package/dist/packem_shared/AuthLoading-DezUWNB2.mjs +0 -33
- package/dist/packem_shared/CheckoutButton-DUite8jJ.mjs +0 -189
- package/dist/packem_shared/LunoraProvider-BsuiW4Lk.mjs +0 -81
- package/dist/packem_shared/cache-JeuDAXfE.mjs +0 -80
- package/dist/packem_shared/hydratePreloaded-2omLtadR.mjs +0 -54
- package/dist/packem_shared/lunoraQueryOptions-CefbPBId.mjs +0 -16
- package/dist/packem_shared/query-key-LGnArBTB.mjs +0 -13
- package/dist/packem_shared/query-options.d-CdgGQ9s4.d.mts +0 -38
- package/dist/packem_shared/query-options.d-CdgGQ9s4.d.ts +0 -38
- package/dist/packem_shared/stable-key-DePnevIy.mjs +0 -38
- package/dist/packem_shared/use-paginated-core-xxvd1YA0.mjs +0 -179
- package/dist/packem_shared/useAgent-BNLlIYHz.mjs +0 -101
- package/dist/packem_shared/useAgentChat-0cebQe7-.mjs +0 -304
- package/dist/packem_shared/useAgentState-Cqyd3Dfy.mjs +0 -37
- package/dist/packem_shared/useAgentToolEvents-gF7U4_KY.mjs +0 -129
- package/dist/packem_shared/useAuth-BSutjJaa.mjs +0 -129
- package/dist/packem_shared/useAuthState-CyF35qZR.mjs +0 -36
- package/dist/packem_shared/useClientQuery-DIkNT4QA.mjs +0 -17
- package/dist/packem_shared/useConnectionStatus-PJ7vyCHy.mjs +0 -30
- package/dist/packem_shared/useFlag-Beyeiq2b.mjs +0 -128
- package/dist/packem_shared/useHttpStream-oc4s1pMy.mjs +0 -127
- package/dist/packem_shared/useInfiniteQuery-CJNw1XaZ.mjs +0 -97
- package/dist/packem_shared/useMutation-BeqeIjTr.mjs +0 -67
- package/dist/packem_shared/useMutator-IIrLtDiM.mjs +0 -47
- package/dist/packem_shared/usePaginatedQuery-DWzydaVR.mjs +0 -46
- package/dist/packem_shared/usePresence-Rnx1Fznc.mjs +0 -115
- package/dist/packem_shared/useQuery-CE8_QUgh.mjs +0 -77
- package/dist/packem_shared/useRateLimit-DTEffQEi.mjs +0 -64
- package/dist/packem_shared/useStream-GYNgc9J5.mjs +0 -128
- package/dist/packem_shared/useSubscription-DcDlvVuI.mjs +0 -139
- package/dist/packem_shared/useVoiceAgent-w7fzAMSB.mjs +0 -422
- package/dist/packem_shared/wire-key-Bg8BJ8YM.mjs +0 -101
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { c } from 'react/compiler-runtime';
|
|
3
|
-
import useSubscription from './useSubscription-DcDlvVuI.mjs';
|
|
4
|
-
|
|
5
|
-
const useAgentState = (options) => {
|
|
6
|
-
const $ = c(5);
|
|
7
|
-
let t0;
|
|
8
|
-
if ($[0] !== options.threadKey) {
|
|
9
|
-
t0 = {
|
|
10
|
-
key: options.threadKey
|
|
11
|
-
};
|
|
12
|
-
$[0] = options.threadKey;
|
|
13
|
-
$[1] = t0;
|
|
14
|
-
} else {
|
|
15
|
-
t0 = $[1];
|
|
16
|
-
}
|
|
17
|
-
const {
|
|
18
|
-
data,
|
|
19
|
-
error
|
|
20
|
-
} = useSubscription(options.api.agents.agentState, t0);
|
|
21
|
-
const t1 = data;
|
|
22
|
-
let t2;
|
|
23
|
-
if ($[2] !== error || $[3] !== t1) {
|
|
24
|
-
t2 = {
|
|
25
|
-
error,
|
|
26
|
-
state: t1
|
|
27
|
-
};
|
|
28
|
-
$[2] = error;
|
|
29
|
-
$[3] = t1;
|
|
30
|
-
$[4] = t2;
|
|
31
|
-
} else {
|
|
32
|
-
t2 = $[4];
|
|
33
|
-
}
|
|
34
|
-
return t2;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export { useAgentState };
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { c } from 'react/compiler-runtime';
|
|
3
|
-
import { useStream } from './useStream-GYNgc9J5.mjs';
|
|
4
|
-
import useSubscription from './useSubscription-DcDlvVuI.mjs';
|
|
5
|
-
|
|
6
|
-
const NO_STREAM_REF = {
|
|
7
|
-
__lunoraRef: ""
|
|
8
|
-
};
|
|
9
|
-
const EMPTY_MESSAGES = [];
|
|
10
|
-
const toDurableEvent = (message) => {
|
|
11
|
-
if (message.role === "assistant" && message.toolCalls) {
|
|
12
|
-
return message.toolCalls.map((call) => {
|
|
13
|
-
return {
|
|
14
|
-
input: call.input,
|
|
15
|
-
seq: message.seq,
|
|
16
|
-
toolCallId: call.id,
|
|
17
|
-
toolName: call.name,
|
|
18
|
-
type: "call"
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
if (message.role !== "tool") {
|
|
23
|
-
return void 0;
|
|
24
|
-
}
|
|
25
|
-
if (message.status === "awaiting_approval") {
|
|
26
|
-
return [{
|
|
27
|
-
seq: message.seq,
|
|
28
|
-
type: "awaiting-approval",
|
|
29
|
-
...message.toolCallId === void 0 ? {} : {
|
|
30
|
-
toolCallId: message.toolCallId
|
|
31
|
-
},
|
|
32
|
-
...message.toolName === void 0 ? {} : {
|
|
33
|
-
toolName: message.toolName
|
|
34
|
-
}
|
|
35
|
-
}];
|
|
36
|
-
}
|
|
37
|
-
return [{
|
|
38
|
-
output: message.content,
|
|
39
|
-
seq: message.seq,
|
|
40
|
-
type: "result",
|
|
41
|
-
...message.status === "approved" || message.status === "rejected" ? {
|
|
42
|
-
status: message.status
|
|
43
|
-
} : {},
|
|
44
|
-
...message.toolCallId === void 0 ? {} : {
|
|
45
|
-
toolCallId: message.toolCallId
|
|
46
|
-
},
|
|
47
|
-
...message.toolName === void 0 ? {} : {
|
|
48
|
-
toolName: message.toolName
|
|
49
|
-
}
|
|
50
|
-
}];
|
|
51
|
-
};
|
|
52
|
-
const useAgentToolEvents = (options) => {
|
|
53
|
-
const $ = c(12);
|
|
54
|
-
const {
|
|
55
|
-
api,
|
|
56
|
-
limit,
|
|
57
|
-
stream: streamReference,
|
|
58
|
-
threadKey
|
|
59
|
-
} = options;
|
|
60
|
-
let t0;
|
|
61
|
-
if ($[0] !== limit || $[1] !== threadKey) {
|
|
62
|
-
t0 = limit === void 0 ? {
|
|
63
|
-
key: threadKey
|
|
64
|
-
} : {
|
|
65
|
-
key: threadKey,
|
|
66
|
-
limit
|
|
67
|
-
};
|
|
68
|
-
$[0] = limit;
|
|
69
|
-
$[1] = threadKey;
|
|
70
|
-
$[2] = t0;
|
|
71
|
-
} else {
|
|
72
|
-
t0 = $[2];
|
|
73
|
-
}
|
|
74
|
-
const messagesArguments = t0;
|
|
75
|
-
const {
|
|
76
|
-
data: history
|
|
77
|
-
} = useSubscription(api.agents.agentMessages, messagesArguments);
|
|
78
|
-
let t1;
|
|
79
|
-
if ($[3] !== streamReference || $[4] !== threadKey) {
|
|
80
|
-
t1 = streamReference === void 0 ? "skip" : {
|
|
81
|
-
key: threadKey
|
|
82
|
-
};
|
|
83
|
-
$[3] = streamReference;
|
|
84
|
-
$[4] = threadKey;
|
|
85
|
-
$[5] = t1;
|
|
86
|
-
} else {
|
|
87
|
-
t1 = $[5];
|
|
88
|
-
}
|
|
89
|
-
const streamArguments = t1;
|
|
90
|
-
const {
|
|
91
|
-
chunks
|
|
92
|
-
} = useStream(streamReference ?? NO_STREAM_REF, streamArguments);
|
|
93
|
-
const durable = history ?? EMPTY_MESSAGES;
|
|
94
|
-
let events;
|
|
95
|
-
if ($[6] !== chunks || $[7] !== durable || $[8] !== threadKey) {
|
|
96
|
-
events = durable.flatMap(_temp);
|
|
97
|
-
for (const event of chunks) {
|
|
98
|
-
if (event.kind === "progress" && event.threadKey === threadKey) {
|
|
99
|
-
events.push({
|
|
100
|
-
data: event.data,
|
|
101
|
-
toolCallId: event.toolCallId,
|
|
102
|
-
type: "progress"
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
$[6] = chunks;
|
|
107
|
-
$[7] = durable;
|
|
108
|
-
$[8] = threadKey;
|
|
109
|
-
$[9] = events;
|
|
110
|
-
} else {
|
|
111
|
-
events = $[9];
|
|
112
|
-
}
|
|
113
|
-
let t2;
|
|
114
|
-
if ($[10] !== events) {
|
|
115
|
-
t2 = {
|
|
116
|
-
events
|
|
117
|
-
};
|
|
118
|
-
$[10] = events;
|
|
119
|
-
$[11] = t2;
|
|
120
|
-
} else {
|
|
121
|
-
t2 = $[11];
|
|
122
|
-
}
|
|
123
|
-
return t2;
|
|
124
|
-
};
|
|
125
|
-
function _temp(message) {
|
|
126
|
-
return toDurableEvent(message) ?? [];
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export { useAgentToolEvents };
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { c } from 'react/compiler-runtime';
|
|
3
|
-
import { useSyncExternalStore } from 'react';
|
|
4
|
-
import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
|
|
5
|
-
|
|
6
|
-
const stores = /* @__PURE__ */ new WeakMap();
|
|
7
|
-
const createStore = (client) => {
|
|
8
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
9
|
-
let user = null;
|
|
10
|
-
const notify = () => {
|
|
11
|
-
for (const listener of listeners) {
|
|
12
|
-
listener();
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
let generation = 0;
|
|
16
|
-
const setUser = (next) => {
|
|
17
|
-
if (user !== next) {
|
|
18
|
-
user = next;
|
|
19
|
-
notify();
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const refresh = () => {
|
|
23
|
-
generation += 1;
|
|
24
|
-
const current = generation;
|
|
25
|
-
if (client.getAuthToken() === null) {
|
|
26
|
-
setUser(null);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
client.getCurrentUser().then((next) => {
|
|
30
|
-
if (current === generation) {
|
|
31
|
-
setUser(next);
|
|
32
|
-
}
|
|
33
|
-
return void 0;
|
|
34
|
-
}).catch(() => {
|
|
35
|
-
if (current === generation) {
|
|
36
|
-
setUser(null);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
let unsubscribeToken;
|
|
41
|
-
return {
|
|
42
|
-
getSnapshot: () => user,
|
|
43
|
-
subscribe: (onChange) => {
|
|
44
|
-
const firstSubscriber = listeners.size === 0;
|
|
45
|
-
listeners.add(onChange);
|
|
46
|
-
if (firstSubscriber) {
|
|
47
|
-
unsubscribeToken = client.onAuthTokenChange(refresh);
|
|
48
|
-
refresh();
|
|
49
|
-
}
|
|
50
|
-
return () => {
|
|
51
|
-
listeners.delete(onChange);
|
|
52
|
-
if (listeners.size === 0) {
|
|
53
|
-
unsubscribeToken?.();
|
|
54
|
-
unsubscribeToken = void 0;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
const getStore = (client) => {
|
|
61
|
-
let store = stores.get(client);
|
|
62
|
-
if (!store) {
|
|
63
|
-
store = createStore(client);
|
|
64
|
-
stores.set(client, store);
|
|
65
|
-
}
|
|
66
|
-
return store;
|
|
67
|
-
};
|
|
68
|
-
const useAuth = () => {
|
|
69
|
-
const $ = c(12);
|
|
70
|
-
const client = useLunora();
|
|
71
|
-
let t0;
|
|
72
|
-
if ($[0] !== client) {
|
|
73
|
-
t0 = getStore(client);
|
|
74
|
-
$[0] = client;
|
|
75
|
-
$[1] = t0;
|
|
76
|
-
} else {
|
|
77
|
-
t0 = $[1];
|
|
78
|
-
}
|
|
79
|
-
const store = t0;
|
|
80
|
-
let t1;
|
|
81
|
-
let t2;
|
|
82
|
-
let t3;
|
|
83
|
-
if ($[2] !== client) {
|
|
84
|
-
t1 = (onChange) => client.onAuthTokenChange(onChange);
|
|
85
|
-
t2 = () => client.getAuthToken();
|
|
86
|
-
t3 = () => client.getAuthToken();
|
|
87
|
-
$[2] = client;
|
|
88
|
-
$[3] = t1;
|
|
89
|
-
$[4] = t2;
|
|
90
|
-
$[5] = t3;
|
|
91
|
-
} else {
|
|
92
|
-
t1 = $[3];
|
|
93
|
-
t2 = $[4];
|
|
94
|
-
t3 = $[5];
|
|
95
|
-
}
|
|
96
|
-
const token = useSyncExternalStore(t1, t2, t3);
|
|
97
|
-
const user = useSyncExternalStore(store.subscribe, store.getSnapshot, _temp);
|
|
98
|
-
let t4;
|
|
99
|
-
if ($[6] !== client) {
|
|
100
|
-
t4 = (next) => {
|
|
101
|
-
client.setAuthToken(next);
|
|
102
|
-
};
|
|
103
|
-
$[6] = client;
|
|
104
|
-
$[7] = t4;
|
|
105
|
-
} else {
|
|
106
|
-
t4 = $[7];
|
|
107
|
-
}
|
|
108
|
-
const setToken = t4;
|
|
109
|
-
let t5;
|
|
110
|
-
if ($[8] !== setToken || $[9] !== token || $[10] !== user) {
|
|
111
|
-
t5 = {
|
|
112
|
-
setToken,
|
|
113
|
-
token,
|
|
114
|
-
user
|
|
115
|
-
};
|
|
116
|
-
$[8] = setToken;
|
|
117
|
-
$[9] = token;
|
|
118
|
-
$[10] = user;
|
|
119
|
-
$[11] = t5;
|
|
120
|
-
} else {
|
|
121
|
-
t5 = $[11];
|
|
122
|
-
}
|
|
123
|
-
return t5;
|
|
124
|
-
};
|
|
125
|
-
function _temp() {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export { useAuth as default };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { c } from 'react/compiler-runtime';
|
|
3
|
-
import { useSyncExternalStore } from 'react';
|
|
4
|
-
import useAuth from './useAuth-BSutjJaa.mjs';
|
|
5
|
-
|
|
6
|
-
const subscribe = () => () => void 0;
|
|
7
|
-
const useAuthState = () => {
|
|
8
|
-
const $ = c(3);
|
|
9
|
-
const {
|
|
10
|
-
token
|
|
11
|
-
} = useAuth();
|
|
12
|
-
const hydrated = useSyncExternalStore(subscribe, _temp, _temp2);
|
|
13
|
-
const t0 = hydrated && token !== null;
|
|
14
|
-
const t1 = !hydrated;
|
|
15
|
-
let t2;
|
|
16
|
-
if ($[0] !== t0 || $[1] !== t1) {
|
|
17
|
-
t2 = {
|
|
18
|
-
isAuthenticated: t0,
|
|
19
|
-
isLoading: t1
|
|
20
|
-
};
|
|
21
|
-
$[0] = t0;
|
|
22
|
-
$[1] = t1;
|
|
23
|
-
$[2] = t2;
|
|
24
|
-
} else {
|
|
25
|
-
t2 = $[2];
|
|
26
|
-
}
|
|
27
|
-
return t2;
|
|
28
|
-
};
|
|
29
|
-
function _temp() {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
function _temp2() {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { useAuthState };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useCallback, useSyncExternalStore } from 'react';
|
|
3
|
-
import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
|
|
4
|
-
|
|
5
|
-
const useClientQuery = (ref) => {
|
|
6
|
-
const client = useLunora();
|
|
7
|
-
const subscribe = useCallback((onStoreChange) => client.subscribeClientQuery(ref, () => {
|
|
8
|
-
onStoreChange();
|
|
9
|
-
}), [client, ref.key]);
|
|
10
|
-
const value = useSyncExternalStore(subscribe, () => client.getClientQuery(ref), () => client.getClientQuery(ref));
|
|
11
|
-
const setter = useCallback((next) => {
|
|
12
|
-
client.setClientQuery(ref, next);
|
|
13
|
-
}, [client, ref]);
|
|
14
|
-
return [value, setter];
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export { useClientQuery as default };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { c } from 'react/compiler-runtime';
|
|
3
|
-
import { useSyncExternalStore } from 'react';
|
|
4
|
-
import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
|
|
5
|
-
|
|
6
|
-
const useConnectionStatus = () => {
|
|
7
|
-
const $ = c(4);
|
|
8
|
-
const client = useLunora();
|
|
9
|
-
let t0;
|
|
10
|
-
let t1;
|
|
11
|
-
let t2;
|
|
12
|
-
if ($[0] !== client) {
|
|
13
|
-
t0 = (onChange) => client.onConnectionStatus(() => {
|
|
14
|
-
onChange();
|
|
15
|
-
});
|
|
16
|
-
t1 = () => client.connectionStatus();
|
|
17
|
-
t2 = () => client.connectionStatus();
|
|
18
|
-
$[0] = client;
|
|
19
|
-
$[1] = t0;
|
|
20
|
-
$[2] = t1;
|
|
21
|
-
$[3] = t2;
|
|
22
|
-
} else {
|
|
23
|
-
t0 = $[1];
|
|
24
|
-
t1 = $[2];
|
|
25
|
-
t2 = $[3];
|
|
26
|
-
}
|
|
27
|
-
return useSyncExternalStore(t0, t1, t2);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export { useConnectionStatus as default };
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useState, useRef, useEffect } from 'react';
|
|
3
|
-
import { useLunora } from './LunoraProvider-BsuiW4Lk.mjs';
|
|
4
|
-
import { s as stableStringify } from './stable-key-DePnevIy.mjs';
|
|
5
|
-
|
|
6
|
-
const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
|
|
7
|
-
const flagKind = (value) => {
|
|
8
|
-
const kind = typeof value;
|
|
9
|
-
if (kind === "boolean" || kind === "number" || kind === "string") {
|
|
10
|
-
return kind;
|
|
11
|
-
}
|
|
12
|
-
return "object";
|
|
13
|
-
};
|
|
14
|
-
const flagsReference = {
|
|
15
|
-
__lunoraRef: FLAGS_EVAL_PATH
|
|
16
|
-
};
|
|
17
|
-
const useFlag = (key, defaultValue, context) => {
|
|
18
|
-
const client = useLunora();
|
|
19
|
-
const [value, setValue] = useState(defaultValue);
|
|
20
|
-
const type = flagKind(defaultValue);
|
|
21
|
-
const serializedContext = context === void 0 ? "" : stableStringify(context);
|
|
22
|
-
const resetKey = `${key}::${type}::${serializedContext}`;
|
|
23
|
-
const resetKeyRef = useRef(resetKey);
|
|
24
|
-
if (resetKeyRef.current !== resetKey) {
|
|
25
|
-
resetKeyRef.current = resetKey;
|
|
26
|
-
setValue(defaultValue);
|
|
27
|
-
}
|
|
28
|
-
const latest = useRef({
|
|
29
|
-
context,
|
|
30
|
-
defaultValue
|
|
31
|
-
});
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
latest.current = {
|
|
34
|
-
context,
|
|
35
|
-
defaultValue
|
|
36
|
-
};
|
|
37
|
-
});
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
let cancelled = false;
|
|
40
|
-
const {
|
|
41
|
-
context: currentContext,
|
|
42
|
-
defaultValue: currentDefault
|
|
43
|
-
} = latest.current;
|
|
44
|
-
setValue(currentDefault);
|
|
45
|
-
let unsubscribe;
|
|
46
|
-
try {
|
|
47
|
-
unsubscribe = client.subscribe(flagsReference, {
|
|
48
|
-
context: currentContext,
|
|
49
|
-
default: currentDefault,
|
|
50
|
-
key,
|
|
51
|
-
type
|
|
52
|
-
}, (next) => {
|
|
53
|
-
if (!cancelled) {
|
|
54
|
-
setValue(next);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
} catch {
|
|
58
|
-
return () => {
|
|
59
|
-
cancelled = true;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
return () => {
|
|
63
|
-
cancelled = true;
|
|
64
|
-
unsubscribe();
|
|
65
|
-
};
|
|
66
|
-
}, [client, key, type, serializedContext]);
|
|
67
|
-
return value;
|
|
68
|
-
};
|
|
69
|
-
const useFlags = (flags, context) => {
|
|
70
|
-
const client = useLunora();
|
|
71
|
-
const [values, setValues] = useState(flags);
|
|
72
|
-
const spec = stableStringify(flags);
|
|
73
|
-
const serializedContext = context === void 0 ? "" : stableStringify(context);
|
|
74
|
-
const resetKey = `${spec}::${serializedContext}`;
|
|
75
|
-
const resetKeyRef = useRef(resetKey);
|
|
76
|
-
if (resetKeyRef.current !== resetKey) {
|
|
77
|
-
resetKeyRef.current = resetKey;
|
|
78
|
-
setValues(flags);
|
|
79
|
-
}
|
|
80
|
-
const latest = useRef({
|
|
81
|
-
context,
|
|
82
|
-
flags
|
|
83
|
-
});
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
latest.current = {
|
|
86
|
-
context,
|
|
87
|
-
flags
|
|
88
|
-
};
|
|
89
|
-
});
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
let cancelled = false;
|
|
92
|
-
const {
|
|
93
|
-
context: currentContext,
|
|
94
|
-
flags: currentFlags
|
|
95
|
-
} = latest.current;
|
|
96
|
-
setValues(currentFlags);
|
|
97
|
-
const unsubscribes = [];
|
|
98
|
-
for (const [key, defaultValue] of Object.entries(currentFlags)) {
|
|
99
|
-
try {
|
|
100
|
-
unsubscribes.push(client.subscribe(flagsReference, {
|
|
101
|
-
context: currentContext,
|
|
102
|
-
default: defaultValue,
|
|
103
|
-
key,
|
|
104
|
-
type: flagKind(defaultValue)
|
|
105
|
-
}, (next) => {
|
|
106
|
-
if (!cancelled) {
|
|
107
|
-
setValues((previous) => {
|
|
108
|
-
return {
|
|
109
|
-
...previous,
|
|
110
|
-
[key]: next
|
|
111
|
-
};
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}));
|
|
115
|
-
} catch {
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return () => {
|
|
119
|
-
cancelled = true;
|
|
120
|
-
for (const unsubscribe of unsubscribes) {
|
|
121
|
-
unsubscribe();
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}, [client, spec, serializedContext]);
|
|
125
|
-
return values;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
export { useFlag, useFlags };
|
|
@@ -1,127 +0,0 @@
|
|
|
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 };
|