@lunora/vue 1.0.0-alpha.48 → 1.0.0-alpha.49

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 (45) hide show
  1. package/dist/index.mjs +1 -19
  2. package/dist/packem_shared/AuthLoading-CST_mkXL.mjs +1 -0
  3. package/dist/packem_shared/LUNORA_INJECTION_KEY-CswQb5zb.mjs +1 -0
  4. package/dist/packem_shared/hydratePreloaded-D8EcBXmG.mjs +1 -0
  5. package/dist/packem_shared/stable-key-BSG0zK_E.mjs +1 -0
  6. package/dist/packem_shared/subscribeToQuery-CGvPMz37.mjs +1 -0
  7. package/dist/packem_shared/useAgent-DyWC-Sm8.mjs +1 -0
  8. package/dist/packem_shared/useAgentChat-ScvDvEFO.mjs +1 -0
  9. package/dist/packem_shared/useAgentState-CUHDV3h7.mjs +1 -0
  10. package/dist/packem_shared/useAgentToolEvents-DvcPNShc.mjs +1 -0
  11. package/dist/packem_shared/useAuth-DwDFjvto.mjs +1 -0
  12. package/dist/packem_shared/useConnectionStatus-BwLyL_L_.mjs +1 -0
  13. package/dist/packem_shared/useFlag-Bxoq8mH9.mjs +1 -0
  14. package/dist/packem_shared/useInfiniteQuery-Czncoie-.mjs +1 -0
  15. package/dist/packem_shared/useMutation-MdgW9pRE.mjs +1 -0
  16. package/dist/packem_shared/useMutator-DRVDOhcj.mjs +1 -0
  17. package/dist/packem_shared/usePresence-AiurcGAB.mjs +1 -0
  18. package/dist/packem_shared/useRateLimit-z8EUFuYJ.mjs +1 -0
  19. package/dist/packem_shared/useStream-CYkKEcDf.mjs +1 -0
  20. package/dist/packem_shared/useSubscription-D4Ap-tJr.mjs +1 -0
  21. package/dist/packem_shared/useVoiceAgent-Ba0SIP06.mjs +1 -0
  22. package/dist/server.mjs +1 -1
  23. package/dist/upload.mjs +1 -2
  24. package/dist/worker.mjs +1 -1
  25. package/package.json +3 -3
  26. package/dist/packem_shared/AuthLoading-DKra8yfG.mjs +0 -29
  27. package/dist/packem_shared/LUNORA_INJECTION_KEY-DQM5MgsC.mjs +0 -26
  28. package/dist/packem_shared/hydratePreloaded-Cnd2GmG1.mjs +0 -14
  29. package/dist/packem_shared/stable-key-C8JHuJL7.mjs +0 -40
  30. package/dist/packem_shared/subscribeToQuery-hVYyvgOD.mjs +0 -51
  31. package/dist/packem_shared/useAgent-TEp9OWs3.mjs +0 -28
  32. package/dist/packem_shared/useAgentChat-DQmekE-E.mjs +0 -108
  33. package/dist/packem_shared/useAgentState-CeDpLTib.mjs +0 -12
  34. package/dist/packem_shared/useAgentToolEvents-DfCy9INR.mjs +0 -62
  35. package/dist/packem_shared/useAuth-yXaaF-ro.mjs +0 -28
  36. package/dist/packem_shared/useConnectionStatus-DM_TOaW5.mjs +0 -20
  37. package/dist/packem_shared/useFlag-B8Gq7oUu.mjs +0 -70
  38. package/dist/packem_shared/useInfiniteQuery-CMAUPQyd.mjs +0 -309
  39. package/dist/packem_shared/useMutation-BKIwT8Jk.mjs +0 -29
  40. package/dist/packem_shared/useMutator-B_Ahs_ZN.mjs +0 -19
  41. package/dist/packem_shared/usePresence-Bg671Pt0.mjs +0 -75
  42. package/dist/packem_shared/useRateLimit-DlPWjcX1.mjs +0 -67
  43. package/dist/packem_shared/useStream-DK2TNPo4.mjs +0 -65
  44. package/dist/packem_shared/useSubscription-B2s-lc5e.mjs +0 -48
  45. package/dist/packem_shared/useVoiceAgent-DuNU5TE_.mjs +0 -388
@@ -1,70 +0,0 @@
1
- import { shallowRef, watch, toValue } from 'vue';
2
- import { s as stableStringify } from './stable-key-C8JHuJL7.mjs';
3
- import { useLunora } from './LUNORA_INJECTION_KEY-DQM5MgsC.mjs';
4
-
5
- const FLAGS_EVAL_PATH = "__lunora_flags__:eval";
6
- const flagKind = (value) => {
7
- const kind = typeof value;
8
- if (kind === "boolean" || kind === "number" || kind === "string") {
9
- return kind;
10
- }
11
- return "object";
12
- };
13
- const flagsReference = { __lunoraRef: FLAGS_EVAL_PATH };
14
- const serializeContext = (context) => context === void 0 ? "" : stableStringify(context);
15
- const useFlag = (key, defaultValue, context) => {
16
- const client = useLunora();
17
- const type = flagKind(defaultValue);
18
- const value = shallowRef(defaultValue);
19
- watch(
20
- () => `${toValue(key)}\0${serializeContext(toValue(context))}`,
21
- (_serialized, _previous, onCleanup) => {
22
- const currentKey = toValue(key);
23
- const currentContext = toValue(context);
24
- value.value = defaultValue;
25
- let unsubscribe;
26
- try {
27
- unsubscribe = client.subscribe(flagsReference, { context: currentContext, default: defaultValue, key: currentKey, type }, (next) => {
28
- value.value = next;
29
- });
30
- } catch {
31
- return;
32
- }
33
- onCleanup(unsubscribe);
34
- },
35
- { immediate: true }
36
- );
37
- return value;
38
- };
39
- const useFlags = (flags, context) => {
40
- const client = useLunora();
41
- const values = shallowRef(flags);
42
- const spec = stableStringify(flags);
43
- watch(
44
- () => `${spec}\0${serializeContext(toValue(context))}`,
45
- (_serialized, _previous, onCleanup) => {
46
- const currentContext = toValue(context);
47
- values.value = flags;
48
- const unsubscribes = [];
49
- for (const [key, defaultValue] of Object.entries(flags)) {
50
- try {
51
- unsubscribes.push(
52
- client.subscribe(flagsReference, { context: currentContext, default: defaultValue, key, type: flagKind(defaultValue) }, (next) => {
53
- values.value = { ...values.value, [key]: next };
54
- })
55
- );
56
- } catch {
57
- }
58
- }
59
- onCleanup(() => {
60
- for (const unsubscribe of unsubscribes) {
61
- unsubscribe();
62
- }
63
- });
64
- },
65
- { immediate: true }
66
- );
67
- return values;
68
- };
69
-
70
- export { useFlag, useFlags };
@@ -1,309 +0,0 @@
1
- import { shallowRef, watch, toValue, onScopeDispose, computed } from 'vue';
2
- import { initialPages, derivePaginationStatus, rebalance, applyLoadMore } from '@lunora/client/pagination';
3
- import { s as stableStringify } from './stable-key-C8JHuJL7.mjs';
4
- import { useLunora } from './LUNORA_INJECTION_KEY-DQM5MgsC.mjs';
5
-
6
- const toBase64 = (bytes) => {
7
- let binary = "";
8
- const chunk = 32768;
9
- for (let index = 0; index < bytes.length; index += chunk) {
10
- binary += String.fromCharCode(...bytes.subarray(index, index + chunk));
11
- }
12
- return btoa(binary);
13
- };
14
-
15
- const TAG = "$lunora.wire$";
16
- const MAX_DEPTH = 64;
17
- const encodeWire = (value, depth = 0) => {
18
- if (depth > MAX_DEPTH) {
19
- throw new RangeError(`wire-codec: value nesting exceeds the ${MAX_DEPTH}-level limit`);
20
- }
21
- if (value === void 0) {
22
- return [TAG, "undefined"];
23
- }
24
- if (value === null) {
25
- return null;
26
- }
27
- const kind = typeof value;
28
- if (kind === "bigint") {
29
- return [TAG, "bigint", value.toString()];
30
- }
31
- if (kind === "number") {
32
- const numeric = value;
33
- if (Number.isNaN(numeric)) {
34
- return [TAG, "nan"];
35
- }
36
- if (numeric === Infinity) {
37
- return [TAG, "inf"];
38
- }
39
- if (numeric === -Infinity) {
40
- return [TAG, "-inf"];
41
- }
42
- return numeric;
43
- }
44
- if (kind !== "object") {
45
- return value;
46
- }
47
- if (value instanceof Date) {
48
- return [TAG, "date", encodeWire(value.getTime(), depth + 1)];
49
- }
50
- if (value instanceof Error) {
51
- const error = value;
52
- const properties = {};
53
- for (const key of Object.keys(error)) {
54
- if (error[key] !== void 0) {
55
- properties[key] = encodeWire(error[key], depth + 1);
56
- }
57
- }
58
- const encodedError = [TAG, "error", error.name, error.message, properties];
59
- if (error.cause !== void 0) {
60
- encodedError.push(encodeWire(error.cause, depth + 1));
61
- }
62
- return encodedError;
63
- }
64
- if (value instanceof URL) {
65
- return [TAG, "url", value.href];
66
- }
67
- if (value instanceof Map) {
68
- return [TAG, "map", [...value.entries()].map(([k, v]) => [encodeWire(k, depth + 1), encodeWire(v, depth + 1)])];
69
- }
70
- if (value instanceof Set) {
71
- return [TAG, "set", [...value].map((item) => encodeWire(item, depth + 1))];
72
- }
73
- if (value instanceof ArrayBuffer) {
74
- return [TAG, "bytes", toBase64(new Uint8Array(value)), "ArrayBuffer"];
75
- }
76
- if (ArrayBuffer.isView(value)) {
77
- const view = value;
78
- const ctorName = view.constructor.name;
79
- const bytes = new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
80
- return ctorName === "Uint8Array" ? [TAG, "bytes", toBase64(bytes)] : [TAG, "bytes", toBase64(bytes), ctorName];
81
- }
82
- if (Array.isArray(value)) {
83
- const encoded = value.map((item) => encodeWire(item, depth + 1));
84
- return encoded.length > 0 && encoded[0] === TAG ? [TAG, "arr", encoded] : encoded;
85
- }
86
- const proto = Object.getPrototypeOf(value);
87
- if (proto !== null && proto !== Object.prototype) {
88
- const name = value.constructor?.name ?? "value";
89
- throw new TypeError(
90
- `wire-codec: cannot encode a ${name} over the Lunora wire — only plain objects, arrays, and the supported built-ins (Date, Error, URL, Map, Set, ArrayBuffer/typed arrays, bigint) round-trip`
91
- );
92
- }
93
- const source = value;
94
- const result = {};
95
- for (const key of Object.keys(source)) {
96
- const field = source[key];
97
- if (field !== void 0) {
98
- result[key] = encodeWire(field, depth + 1);
99
- }
100
- }
101
- return result;
102
- };
103
-
104
- const stableWireKey = (value) => stableStringify(encodeWire(value));
105
-
106
- const buildPageKey = (functionPath, pageArgs) => `${functionPath}::${stableWireKey(pageArgs)}`;
107
- const buildPageArgs = (page, baseArgs) => {
108
- return {
109
- ...baseArgs,
110
- paginationOpts: { cursor: page.lower, endCursor: page.upper, numItems: page.numItems }
111
- };
112
- };
113
- const usePaginatedCore = (function_, args, options) => {
114
- const client = useLunora();
115
- const { initialNumItems, shardKey } = options;
116
- const pages = shallowRef(initialPages(initialNumItems));
117
- const pageResults = shallowRef([]);
118
- let lastLoadMoreCursor;
119
- const activeSubs = /* @__PURE__ */ new Map();
120
- const resultsByKey = /* @__PURE__ */ new Map();
121
- const pendingPageKeys = /* @__PURE__ */ new Set();
122
- const rebuildPageResults = (currentPages, baseArgs) => {
123
- pageResults.value = currentPages.map((page) => {
124
- const key = buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs));
125
- return resultsByKey.get(key);
126
- });
127
- };
128
- const migrateResultsForRebalance = (oldPages, newPages, baseArgs) => {
129
- const keyOf = (page) => buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs));
130
- for (const newPage of newPages) {
131
- const newKey = keyOf(newPage);
132
- if (resultsByKey.has(newKey)) {
133
- continue;
134
- }
135
- const donor = oldPages.find((op) => op.lower === newPage.lower);
136
- if (donor) {
137
- const carried = resultsByKey.get(keyOf(donor));
138
- if (carried) {
139
- resultsByKey.set(newKey, carried);
140
- }
141
- }
142
- }
143
- };
144
- const syncSubscriptions = (currentPages, baseArgs) => {
145
- const wantedKeys = /* @__PURE__ */ new Set();
146
- for (const page of currentPages) {
147
- wantedKeys.add(buildPageKey(function_["__lunoraRef"], buildPageArgs(page, baseArgs)));
148
- }
149
- for (const [originalKey, entry] of activeSubs) {
150
- if (!wantedKeys.has(entry.currentKey)) {
151
- entry.unsub();
152
- activeSubs.delete(originalKey);
153
- resultsByKey.delete(entry.currentKey);
154
- pendingPageKeys.delete(entry.currentKey);
155
- }
156
- }
157
- const coveredKeys = new Set([...activeSubs.values()].map((subEntry) => subEntry.currentKey));
158
- for (const page of currentPages) {
159
- const pageArgs = buildPageArgs(page, baseArgs);
160
- const key = buildPageKey(function_["__lunoraRef"], pageArgs);
161
- if (coveredKeys.has(key)) {
162
- continue;
163
- }
164
- const entry = {
165
- currentKey: key,
166
- unsub: void 0
167
- };
168
- pendingPageKeys.add(key);
169
- const unsub = client.subscribe(
170
- function_,
171
- pageArgs,
172
- (value) => {
173
- resultsByKey.set(entry.currentKey, value);
174
- pendingPageKeys.delete(entry.currentKey);
175
- const currentBaseArgs = toValue(args);
176
- rebuildPageResults(pages.value, currentBaseArgs);
177
- if (pendingPageKeys.size === 0) {
178
- const latestPages = pages.value;
179
- const next = rebalance(latestPages, pageResults.value);
180
- if (next) {
181
- migrateResultsForRebalance(latestPages, next, currentBaseArgs);
182
- pages.value = next;
183
- }
184
- }
185
- },
186
- { shardKey }
187
- );
188
- entry.unsub = unsub;
189
- activeSubs.set(key, entry);
190
- coveredKeys.add(key);
191
- }
192
- };
193
- const teardownAll = () => {
194
- for (const entry of activeSubs.values()) {
195
- entry.unsub();
196
- }
197
- activeSubs.clear();
198
- resultsByKey.clear();
199
- pendingPageKeys.clear();
200
- };
201
- watch(
202
- () => stableWireKey(toValue(args)),
203
- () => {
204
- const current = toValue(args);
205
- teardownAll();
206
- pages.value = initialPages(initialNumItems);
207
- pageResults.value = [];
208
- lastLoadMoreCursor = void 0;
209
- if (current !== "skip") {
210
- syncSubscriptions(pages.value, current);
211
- rebuildPageResults(pages.value, current);
212
- }
213
- },
214
- { immediate: true }
215
- );
216
- watch(
217
- () => pages.value,
218
- (currentPages) => {
219
- const current = toValue(args);
220
- if (current !== "skip") {
221
- syncSubscriptions(currentPages, current);
222
- rebuildPageResults(currentPages, current);
223
- }
224
- }
225
- );
226
- onScopeDispose(teardownAll);
227
- const status = shallowRef("LoadingFirstPage");
228
- watch(
229
- [() => toValue(args), pageResults],
230
- ([currentArgs, currentResults]) => {
231
- status.value = derivePaginationStatus(currentArgs === "skip", currentResults).status;
232
- },
233
- { immediate: true }
234
- );
235
- const loadMore = (numberItems) => {
236
- const currentArgs = toValue(args);
237
- if (currentArgs === "skip") {
238
- return;
239
- }
240
- const { nextCursor, status: currentStatus } = derivePaginationStatus(false, pageResults.value);
241
- if (currentStatus !== "CanLoadMore") {
242
- return;
243
- }
244
- if (nextCursor === lastLoadMoreCursor) {
245
- return;
246
- }
247
- const next = applyLoadMore(pages.value, nextCursor, numberItems);
248
- if (!next) {
249
- return;
250
- }
251
- lastLoadMoreCursor = nextCursor;
252
- const oldTail = pages.value.at(-1);
253
- const newPinnedPage = next.at(-2);
254
- if (oldTail && newPinnedPage) {
255
- const oldKey = buildPageKey(function_["__lunoraRef"], buildPageArgs(oldTail, currentArgs));
256
- const newKey = buildPageKey(function_["__lunoraRef"], buildPageArgs(newPinnedPage, currentArgs));
257
- const entry = activeSubs.get(oldKey);
258
- if (entry && oldKey !== newKey) {
259
- entry.currentKey = newKey;
260
- activeSubs.set(newKey, entry);
261
- activeSubs.delete(oldKey);
262
- const carried = resultsByKey.get(oldKey);
263
- if (carried) {
264
- resultsByKey.set(newKey, carried);
265
- resultsByKey.delete(oldKey);
266
- }
267
- }
268
- }
269
- pages.value = next;
270
- };
271
- return { loadMore, pageResults, status };
272
- };
273
-
274
- const usePaginatedQuery = (function_, args, options) => {
275
- const { loadMore, pageResults, status } = usePaginatedCore(function_, args, options);
276
- const results = computed(() => {
277
- const items = [];
278
- for (const result of pageResults.value) {
279
- if (result) {
280
- items.push(...result.page);
281
- }
282
- }
283
- return items;
284
- });
285
- const isLoading = computed(() => status.value === "LoadingFirstPage" || status.value === "LoadingMore");
286
- return { isLoading, loadMore, results, status };
287
- };
288
- const useInfiniteQuery = (function_, args, options) => {
289
- const { initialNumItems } = options;
290
- const { loadMore, pageResults, status } = usePaginatedCore(function_, args, options);
291
- const pages = computed(() => {
292
- const result = [];
293
- for (const page of pageResults.value) {
294
- if (page) {
295
- result.push(page.page);
296
- }
297
- }
298
- return result;
299
- });
300
- const isLoading = computed(() => status.value === "LoadingFirstPage");
301
- const hasNextPage = computed(() => status.value === "CanLoadMore");
302
- const isFetchingNextPage = computed(() => status.value === "LoadingMore");
303
- const fetchNextPage = (numberItems) => {
304
- loadMore(numberItems ?? initialNumItems);
305
- };
306
- return { fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, pages, status };
307
- };
308
-
309
- export { useInfiniteQuery, usePaginatedQuery };
@@ -1,29 +0,0 @@
1
- import { createMutationRunner } from '@lunora/client';
2
- import { shallowRef, ref } from 'vue';
3
- import { useLunora } from './LUNORA_INJECTION_KEY-DQM5MgsC.mjs';
4
-
5
- const useMutation = (function_) => {
6
- const client = useLunora();
7
- const data = shallowRef(void 0);
8
- const error = shallowRef(void 0);
9
- const pending = ref(false);
10
- const reset = () => {
11
- data.value = void 0;
12
- error.value = void 0;
13
- };
14
- const mutate = createMutationRunner(client, function_, {
15
- setError: (next) => {
16
- error.value = next;
17
- },
18
- setPending: (next) => {
19
- pending.value = next;
20
- },
21
- setResult: (result) => {
22
- data.value = result;
23
- error.value = void 0;
24
- }
25
- });
26
- return { data, error, mutate, pending, reset };
27
- };
28
-
29
- export { useMutation };
@@ -1,19 +0,0 @@
1
- import { createMutatorRunner } from '@lunora/client';
2
- import { shallowRef, computed } from 'vue';
3
-
4
- const useMutator = (handle) => {
5
- const error = shallowRef(void 0);
6
- const pending = shallowRef(false);
7
- const isError = computed(() => error.value !== void 0);
8
- const { mutate, reset } = createMutatorRunner(handle, {
9
- setError: (value) => {
10
- error.value = value;
11
- },
12
- setPending: (value) => {
13
- pending.value = value;
14
- }
15
- });
16
- return { error, isError, mutate, pending, reset };
17
- };
18
-
19
- export { useMutator };
@@ -1,75 +0,0 @@
1
- import { shallowRef, getCurrentScope, onScopeDispose } from 'vue';
2
- import { useLunora } from './LUNORA_INJECTION_KEY-DQM5MgsC.mjs';
3
-
4
- const randomSessionId = (prefix = "sess") => {
5
- if (typeof crypto !== "undefined") {
6
- if (typeof crypto.randomUUID === "function") {
7
- return crypto.randomUUID();
8
- }
9
- if (typeof crypto.getRandomValues === "function") {
10
- const bytes = crypto.getRandomValues(new Uint8Array(16));
11
- return `${prefix}-${Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
12
- }
13
- }
14
- return `${prefix}-${Date.now().toString(36)}`;
15
- };
16
-
17
- const DEFAULT_INTERVAL_MS = 1e4;
18
- const usePresence = (roomId, options) => {
19
- const client = useLunora();
20
- const { heartbeat, intervalMs = DEFAULT_INTERVAL_MS, listPresent, shardKey } = options;
21
- const sessionId = options.sessionId ?? randomSessionId();
22
- const present = shallowRef(void 0);
23
- let latestData = options.data;
24
- const sendHeartbeat = () => {
25
- const args = {
26
- roomId,
27
- sessionId,
28
- ...latestData === void 0 ? {} : { data: latestData }
29
- };
30
- client.mutation(heartbeat, args, { shardKey }).catch(() => void 0);
31
- };
32
- const setData = (next) => {
33
- latestData = next;
34
- sendHeartbeat();
35
- };
36
- if (globalThis.window !== void 0) {
37
- sendHeartbeat();
38
- const intervalHandle = setInterval(sendHeartbeat, intervalMs);
39
- const onVisible = () => {
40
- if (typeof document !== "undefined" && document.visibilityState === "visible") {
41
- sendHeartbeat();
42
- }
43
- };
44
- if (typeof document !== "undefined") {
45
- document.addEventListener("visibilitychange", onVisible);
46
- }
47
- const releaseConnectionContext = client.acquireConnectionContext({ roomId, sessionId }, { shardKey });
48
- const unsubscribe = client.subscribe(
49
- listPresent,
50
- { roomId },
51
- (value) => {
52
- present.value = value;
53
- },
54
- { shardKey }
55
- );
56
- const teardown = () => {
57
- clearInterval(intervalHandle);
58
- if (typeof document !== "undefined") {
59
- document.removeEventListener("visibilitychange", onVisible);
60
- }
61
- releaseConnectionContext();
62
- unsubscribe();
63
- };
64
- if (getCurrentScope()) {
65
- onScopeDispose(teardown);
66
- } else {
67
- console.warn(
68
- "[@lunora/vue] usePresence called with no active effect scope — its heartbeat interval and live subscription will not be cleaned up automatically. Call it inside setup()/an effect scope."
69
- );
70
- }
71
- }
72
- return { present, sessionId, setData };
73
- };
74
-
75
- export { usePresence };
@@ -1,67 +0,0 @@
1
- import { evaluate } from '@lunora/ratelimit';
2
- import { shallowRef, toValue, watchEffect, onScopeDispose, computed } from 'vue';
3
-
4
- const useRateLimit = (config, options = {}) => {
5
- const now = options.now ?? Date.now;
6
- const tickMs = options.tickMs ?? 1e3;
7
- let value;
8
- const epoch = shallowRef(0);
9
- const bump = () => {
10
- epoch.value += 1;
11
- };
12
- const status = shallowRef(evaluate(toValue(config), value, { consume: false, count: 1, now: now(), reserve: false }).status);
13
- const stopStatusEffect = watchEffect(
14
- () => {
15
- status.value = evaluate(toValue(config), value, { consume: false, count: 1, now: now(), reserve: false }).status;
16
- },
17
- { flush: "sync" }
18
- );
19
- let intervalHandle;
20
- const stopInterval = () => {
21
- if (intervalHandle !== void 0) {
22
- clearInterval(intervalHandle);
23
- intervalHandle = void 0;
24
- }
25
- };
26
- const startIntervalIfThrottled = () => {
27
- if (status.value.ok || intervalHandle !== void 0) {
28
- return;
29
- }
30
- intervalHandle = setInterval(() => {
31
- bump();
32
- if (status.value.ok) {
33
- stopInterval();
34
- }
35
- }, tickMs);
36
- };
37
- onScopeDispose(() => {
38
- stopInterval();
39
- stopStatusEffect();
40
- });
41
- startIntervalIfThrottled();
42
- const consume = (count = 1) => {
43
- const result = evaluate(toValue(config), value, { consume: true, count, now: now(), reserve: false });
44
- if (result.value !== void 0) {
45
- value = result.value;
46
- }
47
- bump();
48
- startIntervalIfThrottled();
49
- return result.status;
50
- };
51
- const check = (count = 1) => evaluate(toValue(config), value, { consume: false, count, now: now(), reserve: false }).status.ok;
52
- const reset = () => {
53
- value = void 0;
54
- stopInterval();
55
- bump();
56
- };
57
- return {
58
- check,
59
- consume,
60
- disabled: computed(() => !status.value.ok),
61
- ok: computed(() => status.value.ok),
62
- reset,
63
- retryAfter: computed(() => status.value.retryAfter)
64
- };
65
- };
66
-
67
- export { useRateLimit };
@@ -1,65 +0,0 @@
1
- import { ref, watch, toValue, onScopeDispose } from 'vue';
2
- import { useLunora } from './LUNORA_INJECTION_KEY-DQM5MgsC.mjs';
3
-
4
- const useStream = (function_, args, options = {}) => {
5
- const client = useLunora();
6
- const chunks = ref([]);
7
- const error = ref(void 0);
8
- const status = ref("idle");
9
- let cancelCurrent;
10
- const cancel = () => {
11
- cancelCurrent?.();
12
- };
13
- watch(
14
- () => toValue(args),
15
- (currentArgs, _previous, onCleanup) => {
16
- chunks.value = [];
17
- error.value = void 0;
18
- if (currentArgs === "skip") {
19
- status.value = "idle";
20
- return;
21
- }
22
- status.value = "streaming";
23
- let active = true;
24
- const iterable = client.stream(function_, currentArgs, { maxBuffer: options.maxBuffer, shardKey: options.shardKey });
25
- const cancelIterable = () => {
26
- iterable.cancel();
27
- };
28
- cancelCurrent = cancelIterable;
29
- (async () => {
30
- try {
31
- for await (const chunk of iterable) {
32
- if (!active) {
33
- return;
34
- }
35
- chunks.value = [...chunks.value, chunk];
36
- }
37
- if (active) {
38
- status.value = "complete";
39
- }
40
- } catch (streamError) {
41
- if (!active) {
42
- return;
43
- }
44
- error.value = streamError instanceof Error ? streamError : new Error(String(streamError));
45
- status.value = "error";
46
- }
47
- })().catch(() => {
48
- });
49
- onCleanup(() => {
50
- active = false;
51
- cancelIterable();
52
- if (cancelCurrent === cancelIterable) {
53
- cancelCurrent = void 0;
54
- }
55
- });
56
- },
57
- { immediate: true }
58
- );
59
- onScopeDispose(() => {
60
- cancel();
61
- });
62
- return { cancel, chunks, error, status };
63
- };
64
-
65
- export { useStream };
@@ -1,48 +0,0 @@
1
- import { createQuerySubscription } from '@lunora/client/query';
2
- import { LunoraError } from '@lunora/errors';
3
- import { ref, watch, toValue, onScopeDispose } from 'vue';
4
- import { useLunora } from './LUNORA_INJECTION_KEY-DQM5MgsC.mjs';
5
-
6
- const useSubscription = (function_, args, options = {}) => {
7
- const client = useLunora();
8
- const data = ref(void 0);
9
- const error = ref(void 0);
10
- watch(
11
- () => toValue(args),
12
- (currentArgs, _previous, onCleanup) => {
13
- if (currentArgs === "skip") {
14
- data.value = void 0;
15
- error.value = void 0;
16
- return;
17
- }
18
- const unsubscribe = createQuerySubscription(
19
- client,
20
- function_,
21
- currentArgs,
22
- {
23
- onData: (value) => {
24
- data.value = value;
25
- error.value = void 0;
26
- },
27
- onError: (subscriptionError) => {
28
- error.value = subscriptionError.code === void 0 ? new Error(subscriptionError.message) : new LunoraError(subscriptionError.code, subscriptionError.message);
29
- data.value = void 0;
30
- },
31
- onReset: () => {
32
- data.value = void 0;
33
- }
34
- },
35
- { shardKey: options.shardKey }
36
- );
37
- onCleanup(unsubscribe);
38
- },
39
- { immediate: true }
40
- );
41
- onScopeDispose(() => {
42
- data.value = void 0;
43
- error.value = void 0;
44
- });
45
- return { data, error };
46
- };
47
-
48
- export { useSubscription };