@rekayasa/erica-bubble 1.0.0

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/dist/index.mjs ADDED
@@ -0,0 +1,2633 @@
1
+ import * as e from "react";
2
+ import { createContext as t, createElement as n, forwardRef as r, useCallback as i, useContext as a, useEffect as o, useMemo as s, useRef as c, useState as l } from "react";
3
+ import { jsx as u, jsxs as d } from "react/jsx-runtime";
4
+ import { CopilotKit as f } from "@copilotkit/react-core";
5
+ import { CopilotSidebar as p } from "@copilotkit/react-ui";
6
+ //#region node_modules/@tanstack/query-core/build/modern/subscribable.js
7
+ var m = class {
8
+ constructor() {
9
+ this.listeners = /* @__PURE__ */ new Set(), this.subscribe = this.subscribe.bind(this);
10
+ }
11
+ subscribe(e) {
12
+ return this.listeners.add(e), this.onSubscribe(), () => {
13
+ this.listeners.delete(e), this.onUnsubscribe();
14
+ };
15
+ }
16
+ hasListeners() {
17
+ return this.listeners.size > 0;
18
+ }
19
+ onSubscribe() {}
20
+ onUnsubscribe() {}
21
+ }, h = new class extends m {
22
+ #e;
23
+ #t;
24
+ #n;
25
+ constructor() {
26
+ super(), this.#n = (e) => {
27
+ if (typeof window < "u" && window.addEventListener) {
28
+ let t = () => e();
29
+ return window.addEventListener("visibilitychange", t, !1), () => {
30
+ window.removeEventListener("visibilitychange", t);
31
+ };
32
+ }
33
+ };
34
+ }
35
+ onSubscribe() {
36
+ this.#t || this.setEventListener(this.#n);
37
+ }
38
+ onUnsubscribe() {
39
+ this.hasListeners() || (this.#t?.(), this.#t = void 0);
40
+ }
41
+ setEventListener(e) {
42
+ this.#n = e, this.#t?.(), this.#t = e((e) => {
43
+ typeof e == "boolean" ? this.setFocused(e) : this.onFocus();
44
+ });
45
+ }
46
+ setFocused(e) {
47
+ this.#e !== e && (this.#e = e, this.onFocus());
48
+ }
49
+ onFocus() {
50
+ let e = this.isFocused();
51
+ this.listeners.forEach((t) => {
52
+ t(e);
53
+ });
54
+ }
55
+ isFocused() {
56
+ return typeof this.#e == "boolean" ? this.#e : globalThis.document?.visibilityState !== "hidden";
57
+ }
58
+ }(), g = {
59
+ setTimeout: (e, t) => setTimeout(e, t),
60
+ clearTimeout: (e) => clearTimeout(e),
61
+ setInterval: (e, t) => setInterval(e, t),
62
+ clearInterval: (e) => clearInterval(e)
63
+ }, _ = new class {
64
+ #e = g;
65
+ #t = !1;
66
+ setTimeoutProvider(e) {
67
+ process.env.NODE_ENV !== "production" && this.#t && e !== this.#e && console.error("[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.", {
68
+ previous: this.#e,
69
+ provider: e
70
+ }), this.#e = e, process.env.NODE_ENV !== "production" && (this.#t = !1);
71
+ }
72
+ setTimeout(e, t) {
73
+ return process.env.NODE_ENV !== "production" && (this.#t = !0), this.#e.setTimeout(e, t);
74
+ }
75
+ clearTimeout(e) {
76
+ this.#e.clearTimeout(e);
77
+ }
78
+ setInterval(e, t) {
79
+ return process.env.NODE_ENV !== "production" && (this.#t = !0), this.#e.setInterval(e, t);
80
+ }
81
+ clearInterval(e) {
82
+ this.#e.clearInterval(e);
83
+ }
84
+ }();
85
+ function v(e) {
86
+ setTimeout(e, 0);
87
+ }
88
+ //#endregion
89
+ //#region node_modules/@tanstack/query-core/build/modern/utils.js
90
+ var y = typeof window > "u" || "Deno" in globalThis;
91
+ function b() {}
92
+ function x(e, t) {
93
+ return typeof e == "function" ? e(t) : e;
94
+ }
95
+ function S(e) {
96
+ return typeof e == "number" && e >= 0 && e !== Infinity;
97
+ }
98
+ function C(e, t) {
99
+ return Math.max(e + (t || 0) - Date.now(), 0);
100
+ }
101
+ function w(e, t) {
102
+ return typeof e == "function" ? e(t) : e;
103
+ }
104
+ function T(e, t) {
105
+ return typeof e == "function" ? e(t) : e;
106
+ }
107
+ function E(e, t) {
108
+ let { type: n = "all", exact: r, fetchStatus: i, predicate: a, queryKey: o, stale: s } = e;
109
+ if (o) {
110
+ if (r) {
111
+ if (t.queryHash !== O(o, t.options)) return !1;
112
+ } else if (!A(t.queryKey, o)) return !1;
113
+ }
114
+ if (n !== "all") {
115
+ let e = t.isActive();
116
+ if (n === "active" && !e || n === "inactive" && e) return !1;
117
+ }
118
+ return !(typeof s == "boolean" && t.isStale() !== s || i && i !== t.state.fetchStatus || a && !a(t));
119
+ }
120
+ function D(e, t) {
121
+ let { exact: n, status: r, predicate: i, mutationKey: a } = e;
122
+ if (a) {
123
+ if (!t.options.mutationKey) return !1;
124
+ if (n) {
125
+ if (k(t.options.mutationKey) !== k(a)) return !1;
126
+ } else if (!A(t.options.mutationKey, a)) return !1;
127
+ }
128
+ return !(r && t.state.status !== r || i && !i(t));
129
+ }
130
+ function O(e, t) {
131
+ return (t?.queryKeyHashFn || k)(e);
132
+ }
133
+ function k(e) {
134
+ return JSON.stringify(e, (e, t) => N(t) ? Object.keys(t).sort().reduce((e, n) => (e[n] = t[n], e), {}) : t);
135
+ }
136
+ function A(e, t) {
137
+ return e === t ? !0 : typeof e == typeof t && e && t && typeof e == "object" && typeof t == "object" ? Object.keys(t).every((n) => A(e[n], t[n])) : !1;
138
+ }
139
+ var ee = Object.prototype.hasOwnProperty;
140
+ function j(e, t, n = 0) {
141
+ if (e === t) return e;
142
+ if (n > 500) return t;
143
+ let r = te(e) && te(t);
144
+ if (!r && !(N(e) && N(t))) return t;
145
+ let i = (r ? e : Object.keys(e)).length, a = r ? t : Object.keys(t), o = a.length, s = r ? Array(o) : {}, c = 0;
146
+ for (let l = 0; l < o; l++) {
147
+ let o = r ? l : a[l], u = e[o], d = t[o];
148
+ if (u === d) {
149
+ s[o] = u, (r ? l < i : ee.call(e, o)) && c++;
150
+ continue;
151
+ }
152
+ if (u === null || d === null || typeof u != "object" || typeof d != "object") {
153
+ s[o] = d;
154
+ continue;
155
+ }
156
+ let f = j(u, d, n + 1);
157
+ s[o] = f, f === u && c++;
158
+ }
159
+ return i === o && c === i ? e : s;
160
+ }
161
+ function M(e, t) {
162
+ if (!t || Object.keys(e).length !== Object.keys(t).length) return !1;
163
+ for (let n in e) if (e[n] !== t[n]) return !1;
164
+ return !0;
165
+ }
166
+ function te(e) {
167
+ return Array.isArray(e) && e.length === Object.keys(e).length;
168
+ }
169
+ function N(e) {
170
+ if (!ne(e)) return !1;
171
+ let t = e.constructor;
172
+ if (t === void 0) return !0;
173
+ let n = t.prototype;
174
+ return !(!ne(n) || !n.hasOwnProperty("isPrototypeOf") || Object.getPrototypeOf(e) !== Object.prototype);
175
+ }
176
+ function ne(e) {
177
+ return Object.prototype.toString.call(e) === "[object Object]";
178
+ }
179
+ function re(e) {
180
+ return new Promise((t) => {
181
+ _.setTimeout(t, e);
182
+ });
183
+ }
184
+ function P(e, t, n) {
185
+ if (typeof n.structuralSharing == "function") return n.structuralSharing(e, t);
186
+ if (n.structuralSharing !== !1) {
187
+ if (process.env.NODE_ENV !== "production") try {
188
+ return j(e, t);
189
+ } catch (e) {
190
+ throw console.error(`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${n.queryHash}]: ${e}`), e;
191
+ }
192
+ return j(e, t);
193
+ }
194
+ return t;
195
+ }
196
+ function ie(e, t, n = 0) {
197
+ let r = [...e, t];
198
+ return n && r.length > n ? r.slice(1) : r;
199
+ }
200
+ function ae(e, t, n = 0) {
201
+ let r = [t, ...e];
202
+ return n && r.length > n ? r.slice(0, -1) : r;
203
+ }
204
+ var F = /* @__PURE__ */ Symbol();
205
+ function oe(e, t) {
206
+ return process.env.NODE_ENV !== "production" && e.queryFn === F && console.error(`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${e.queryHash}'`), !e.queryFn && t?.initialPromise ? () => t.initialPromise : !e.queryFn || e.queryFn === F ? () => Promise.reject(/* @__PURE__ */ Error(`Missing queryFn: '${e.queryHash}'`)) : e.queryFn;
207
+ }
208
+ function se(e, t) {
209
+ return typeof e == "function" ? e(...t) : !!e;
210
+ }
211
+ function ce(e, t, n) {
212
+ let r = !1, i;
213
+ return Object.defineProperty(e, "signal", {
214
+ enumerable: !0,
215
+ get: () => (i ??= t(), r ? i : (r = !0, i.aborted ? n() : i.addEventListener("abort", n, { once: !0 }), i))
216
+ }), e;
217
+ }
218
+ //#endregion
219
+ //#region node_modules/@tanstack/query-core/build/modern/environmentManager.js
220
+ var I = /* @__PURE__ */ (() => {
221
+ let e = () => y;
222
+ return {
223
+ isServer() {
224
+ return e();
225
+ },
226
+ setIsServer(t) {
227
+ e = t;
228
+ }
229
+ };
230
+ })();
231
+ //#endregion
232
+ //#region node_modules/@tanstack/query-core/build/modern/thenable.js
233
+ function L() {
234
+ let e, t, n = new Promise((n, r) => {
235
+ e = n, t = r;
236
+ });
237
+ n.status = "pending", n.catch(() => {});
238
+ function r(e) {
239
+ Object.assign(n, e), delete n.resolve, delete n.reject;
240
+ }
241
+ return n.resolve = (t) => {
242
+ r({
243
+ status: "fulfilled",
244
+ value: t
245
+ }), e(t);
246
+ }, n.reject = (e) => {
247
+ r({
248
+ status: "rejected",
249
+ reason: e
250
+ }), t(e);
251
+ }, n;
252
+ }
253
+ //#endregion
254
+ //#region node_modules/@tanstack/query-core/build/modern/notifyManager.js
255
+ var le = v;
256
+ function ue() {
257
+ let e = [], t = 0, n = (e) => {
258
+ e();
259
+ }, r = (e) => {
260
+ e();
261
+ }, i = le, a = (r) => {
262
+ t ? e.push(r) : i(() => {
263
+ n(r);
264
+ });
265
+ }, o = () => {
266
+ let t = e;
267
+ e = [], t.length && i(() => {
268
+ r(() => {
269
+ t.forEach((e) => {
270
+ n(e);
271
+ });
272
+ });
273
+ });
274
+ };
275
+ return {
276
+ batch: (e) => {
277
+ let n;
278
+ t++;
279
+ try {
280
+ n = e();
281
+ } finally {
282
+ t--, t || o();
283
+ }
284
+ return n;
285
+ },
286
+ batchCalls: (e) => (...t) => {
287
+ a(() => {
288
+ e(...t);
289
+ });
290
+ },
291
+ schedule: a,
292
+ setNotifyFunction: (e) => {
293
+ n = e;
294
+ },
295
+ setBatchNotifyFunction: (e) => {
296
+ r = e;
297
+ },
298
+ setScheduler: (e) => {
299
+ i = e;
300
+ }
301
+ };
302
+ }
303
+ var R = ue(), z = new class extends m {
304
+ #e = !0;
305
+ #t;
306
+ #n;
307
+ constructor() {
308
+ super(), this.#n = (e) => {
309
+ if (typeof window < "u" && window.addEventListener) {
310
+ let t = () => e(!0), n = () => e(!1);
311
+ return window.addEventListener("online", t, !1), window.addEventListener("offline", n, !1), () => {
312
+ window.removeEventListener("online", t), window.removeEventListener("offline", n);
313
+ };
314
+ }
315
+ };
316
+ }
317
+ onSubscribe() {
318
+ this.#t || this.setEventListener(this.#n);
319
+ }
320
+ onUnsubscribe() {
321
+ this.hasListeners() || (this.#t?.(), this.#t = void 0);
322
+ }
323
+ setEventListener(e) {
324
+ this.#n = e, this.#t?.(), this.#t = e(this.setOnline.bind(this));
325
+ }
326
+ setOnline(e) {
327
+ this.#e !== e && (this.#e = e, this.listeners.forEach((t) => {
328
+ t(e);
329
+ }));
330
+ }
331
+ isOnline() {
332
+ return this.#e;
333
+ }
334
+ }();
335
+ //#endregion
336
+ //#region node_modules/@tanstack/query-core/build/modern/retryer.js
337
+ function de(e) {
338
+ return Math.min(1e3 * 2 ** e, 3e4);
339
+ }
340
+ function B(e) {
341
+ return (e ?? "online") === "online" ? z.isOnline() : !0;
342
+ }
343
+ var V = class extends Error {
344
+ constructor(e) {
345
+ super("CancelledError"), this.revert = e?.revert, this.silent = e?.silent;
346
+ }
347
+ };
348
+ function H(e) {
349
+ let t = !1, n = 0, r, i = L(), a = () => i.status !== "pending", o = (t) => {
350
+ if (!a()) {
351
+ let n = new V(t);
352
+ f(n), e.onCancel?.(n);
353
+ }
354
+ }, s = () => {
355
+ t = !0;
356
+ }, c = () => {
357
+ t = !1;
358
+ }, l = () => h.isFocused() && (e.networkMode === "always" || z.isOnline()) && e.canRun(), u = () => B(e.networkMode) && e.canRun(), d = (e) => {
359
+ a() || (r?.(), i.resolve(e));
360
+ }, f = (e) => {
361
+ a() || (r?.(), i.reject(e));
362
+ }, p = () => new Promise((t) => {
363
+ r = (e) => {
364
+ (a() || l()) && t(e);
365
+ }, e.onPause?.();
366
+ }).then(() => {
367
+ r = void 0, a() || e.onContinue?.();
368
+ }), m = () => {
369
+ if (a()) return;
370
+ let r, i = n === 0 ? e.initialPromise : void 0;
371
+ try {
372
+ r = i ?? e.fn();
373
+ } catch (e) {
374
+ r = Promise.reject(e);
375
+ }
376
+ Promise.resolve(r).then(d).catch((r) => {
377
+ if (a()) return;
378
+ let i = e.retry ?? (I.isServer() ? 0 : 3), o = e.retryDelay ?? de, s = typeof o == "function" ? o(n, r) : o, c = i === !0 || typeof i == "number" && n < i || typeof i == "function" && i(n, r);
379
+ if (t || !c) {
380
+ f(r);
381
+ return;
382
+ }
383
+ n++, e.onFail?.(n, r), re(s).then(() => l() ? void 0 : p()).then(() => {
384
+ t ? f(r) : m();
385
+ });
386
+ });
387
+ };
388
+ return {
389
+ promise: i,
390
+ status: () => i.status,
391
+ cancel: o,
392
+ continue: () => (r?.(), i),
393
+ cancelRetry: s,
394
+ continueRetry: c,
395
+ canStart: u,
396
+ start: () => (u() ? m() : p().then(m), i)
397
+ };
398
+ }
399
+ //#endregion
400
+ //#region node_modules/@tanstack/query-core/build/modern/removable.js
401
+ var fe = class {
402
+ #e;
403
+ destroy() {
404
+ this.clearGcTimeout();
405
+ }
406
+ scheduleGc() {
407
+ this.clearGcTimeout(), S(this.gcTime) && (this.#e = _.setTimeout(() => {
408
+ this.optionalRemove();
409
+ }, this.gcTime));
410
+ }
411
+ updateGcTime(e) {
412
+ this.gcTime = Math.max(this.gcTime || 0, e ?? (I.isServer() ? Infinity : 300 * 1e3));
413
+ }
414
+ clearGcTimeout() {
415
+ this.#e !== void 0 && (_.clearTimeout(this.#e), this.#e = void 0);
416
+ }
417
+ }, pe = class extends fe {
418
+ #e;
419
+ #t;
420
+ #n;
421
+ #r;
422
+ #i;
423
+ #a;
424
+ #o;
425
+ constructor(e) {
426
+ super(), this.#o = !1, this.#a = e.defaultOptions, this.setOptions(e.options), this.observers = [], this.#r = e.client, this.#n = this.#r.getQueryCache(), this.queryKey = e.queryKey, this.queryHash = e.queryHash, this.#e = he(this.options), this.state = e.state ?? this.#e, this.scheduleGc();
427
+ }
428
+ get meta() {
429
+ return this.options.meta;
430
+ }
431
+ get promise() {
432
+ return this.#i?.promise;
433
+ }
434
+ setOptions(e) {
435
+ if (this.options = {
436
+ ...this.#a,
437
+ ...e
438
+ }, this.updateGcTime(this.options.gcTime), this.state && this.state.data === void 0) {
439
+ let e = he(this.options);
440
+ e.data !== void 0 && (this.setState(me(e.data, e.dataUpdatedAt)), this.#e = e);
441
+ }
442
+ }
443
+ optionalRemove() {
444
+ !this.observers.length && this.state.fetchStatus === "idle" && this.#n.remove(this);
445
+ }
446
+ setData(e, t) {
447
+ let n = P(this.state.data, e, this.options);
448
+ return this.#c({
449
+ data: n,
450
+ type: "success",
451
+ dataUpdatedAt: t?.updatedAt,
452
+ manual: t?.manual
453
+ }), n;
454
+ }
455
+ setState(e, t) {
456
+ this.#c({
457
+ type: "setState",
458
+ state: e,
459
+ setStateOptions: t
460
+ });
461
+ }
462
+ cancel(e) {
463
+ let t = this.#i?.promise;
464
+ return this.#i?.cancel(e), t ? t.then(b).catch(b) : Promise.resolve();
465
+ }
466
+ destroy() {
467
+ super.destroy(), this.cancel({ silent: !0 });
468
+ }
469
+ get resetState() {
470
+ return this.#e;
471
+ }
472
+ reset() {
473
+ this.destroy(), this.setState(this.resetState);
474
+ }
475
+ isActive() {
476
+ return this.observers.some((e) => T(e.options.enabled, this) !== !1);
477
+ }
478
+ isDisabled() {
479
+ return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === F || !this.isFetched();
480
+ }
481
+ isFetched() {
482
+ return this.state.dataUpdateCount + this.state.errorUpdateCount > 0;
483
+ }
484
+ isStatic() {
485
+ return this.getObserversCount() > 0 ? this.observers.some((e) => w(e.options.staleTime, this) === "static") : !1;
486
+ }
487
+ isStale() {
488
+ return this.getObserversCount() > 0 ? this.observers.some((e) => e.getCurrentResult().isStale) : this.state.data === void 0 || this.state.isInvalidated;
489
+ }
490
+ isStaleByTime(e = 0) {
491
+ return this.state.data === void 0 ? !0 : e === "static" ? !1 : this.state.isInvalidated ? !0 : !C(this.state.dataUpdatedAt, e);
492
+ }
493
+ onFocus() {
494
+ this.observers.find((e) => e.shouldFetchOnWindowFocus())?.refetch({ cancelRefetch: !1 }), this.#i?.continue();
495
+ }
496
+ onOnline() {
497
+ this.observers.find((e) => e.shouldFetchOnReconnect())?.refetch({ cancelRefetch: !1 }), this.#i?.continue();
498
+ }
499
+ addObserver(e) {
500
+ this.observers.includes(e) || (this.observers.push(e), this.clearGcTimeout(), this.#n.notify({
501
+ type: "observerAdded",
502
+ query: this,
503
+ observer: e
504
+ }));
505
+ }
506
+ removeObserver(e) {
507
+ this.observers.includes(e) && (this.observers = this.observers.filter((t) => t !== e), this.observers.length || (this.#i && (this.#o || this.#s() ? this.#i.cancel({ revert: !0 }) : this.#i.cancelRetry()), this.scheduleGc()), this.#n.notify({
508
+ type: "observerRemoved",
509
+ query: this,
510
+ observer: e
511
+ }));
512
+ }
513
+ getObserversCount() {
514
+ return this.observers.length;
515
+ }
516
+ #s() {
517
+ return this.state.fetchStatus === "paused" && this.state.status === "pending";
518
+ }
519
+ invalidate() {
520
+ this.state.isInvalidated || this.#c({ type: "invalidate" });
521
+ }
522
+ async fetch(e, t) {
523
+ if (this.state.fetchStatus !== "idle" && this.#i?.status() !== "rejected") {
524
+ if (this.state.data !== void 0 && t?.cancelRefetch) this.cancel({ silent: !0 });
525
+ else if (this.#i) return this.#i.continueRetry(), this.#i.promise;
526
+ }
527
+ if (e && this.setOptions(e), !this.options.queryFn) {
528
+ let e = this.observers.find((e) => e.options.queryFn);
529
+ e && this.setOptions(e.options);
530
+ }
531
+ process.env.NODE_ENV !== "production" && (Array.isArray(this.options.queryKey) || console.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"));
532
+ let n = new AbortController(), r = (e) => {
533
+ Object.defineProperty(e, "signal", {
534
+ enumerable: !0,
535
+ get: () => (this.#o = !0, n.signal)
536
+ });
537
+ }, i = () => {
538
+ let e = oe(this.options, t), n = (() => {
539
+ let e = {
540
+ client: this.#r,
541
+ queryKey: this.queryKey,
542
+ meta: this.meta
543
+ };
544
+ return r(e), e;
545
+ })();
546
+ return this.#o = !1, this.options.persister ? this.options.persister(e, n, this) : e(n);
547
+ }, a = (() => {
548
+ let e = {
549
+ fetchOptions: t,
550
+ options: this.options,
551
+ queryKey: this.queryKey,
552
+ client: this.#r,
553
+ state: this.state,
554
+ fetchFn: i
555
+ };
556
+ return r(e), e;
557
+ })();
558
+ this.options.behavior?.onFetch(a, this), this.#t = this.state, (this.state.fetchStatus === "idle" || this.state.fetchMeta !== a.fetchOptions?.meta) && this.#c({
559
+ type: "fetch",
560
+ meta: a.fetchOptions?.meta
561
+ }), this.#i = H({
562
+ initialPromise: t?.initialPromise,
563
+ fn: a.fetchFn,
564
+ onCancel: (e) => {
565
+ e instanceof V && e.revert && this.setState({
566
+ ...this.#t,
567
+ fetchStatus: "idle"
568
+ }), n.abort();
569
+ },
570
+ onFail: (e, t) => {
571
+ this.#c({
572
+ type: "failed",
573
+ failureCount: e,
574
+ error: t
575
+ });
576
+ },
577
+ onPause: () => {
578
+ this.#c({ type: "pause" });
579
+ },
580
+ onContinue: () => {
581
+ this.#c({ type: "continue" });
582
+ },
583
+ retry: a.options.retry,
584
+ retryDelay: a.options.retryDelay,
585
+ networkMode: a.options.networkMode,
586
+ canRun: () => !0
587
+ });
588
+ try {
589
+ let e = await this.#i.start();
590
+ if (e === void 0) throw process.env.NODE_ENV !== "production" && console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`), Error(`${this.queryHash} data is undefined`);
591
+ return this.setData(e), this.#n.config.onSuccess?.(e, this), this.#n.config.onSettled?.(e, this.state.error, this), e;
592
+ } catch (e) {
593
+ if (e instanceof V) {
594
+ if (e.silent) return this.#i.promise;
595
+ if (e.revert) {
596
+ if (this.state.data === void 0) throw e;
597
+ return this.state.data;
598
+ }
599
+ }
600
+ throw this.#c({
601
+ type: "error",
602
+ error: e
603
+ }), this.#n.config.onError?.(e, this), this.#n.config.onSettled?.(this.state.data, e, this), e;
604
+ } finally {
605
+ this.scheduleGc();
606
+ }
607
+ }
608
+ #c(e) {
609
+ this.state = ((t) => {
610
+ switch (e.type) {
611
+ case "failed": return {
612
+ ...t,
613
+ fetchFailureCount: e.failureCount,
614
+ fetchFailureReason: e.error
615
+ };
616
+ case "pause": return {
617
+ ...t,
618
+ fetchStatus: "paused"
619
+ };
620
+ case "continue": return {
621
+ ...t,
622
+ fetchStatus: "fetching"
623
+ };
624
+ case "fetch": return {
625
+ ...t,
626
+ ...U(t.data, this.options),
627
+ fetchMeta: e.meta ?? null
628
+ };
629
+ case "success":
630
+ let n = {
631
+ ...t,
632
+ ...me(e.data, e.dataUpdatedAt),
633
+ dataUpdateCount: t.dataUpdateCount + 1,
634
+ ...!e.manual && {
635
+ fetchStatus: "idle",
636
+ fetchFailureCount: 0,
637
+ fetchFailureReason: null
638
+ }
639
+ };
640
+ return this.#t = e.manual ? n : void 0, n;
641
+ case "error":
642
+ let r = e.error;
643
+ return {
644
+ ...t,
645
+ error: r,
646
+ errorUpdateCount: t.errorUpdateCount + 1,
647
+ errorUpdatedAt: Date.now(),
648
+ fetchFailureCount: t.fetchFailureCount + 1,
649
+ fetchFailureReason: r,
650
+ fetchStatus: "idle",
651
+ status: "error",
652
+ isInvalidated: !0
653
+ };
654
+ case "invalidate": return {
655
+ ...t,
656
+ isInvalidated: !0
657
+ };
658
+ case "setState": return {
659
+ ...t,
660
+ ...e.state
661
+ };
662
+ }
663
+ })(this.state), R.batch(() => {
664
+ this.observers.forEach((e) => {
665
+ e.onQueryUpdate();
666
+ }), this.#n.notify({
667
+ query: this,
668
+ type: "updated",
669
+ action: e
670
+ });
671
+ });
672
+ }
673
+ };
674
+ function U(e, t) {
675
+ return {
676
+ fetchFailureCount: 0,
677
+ fetchFailureReason: null,
678
+ fetchStatus: B(t.networkMode) ? "fetching" : "paused",
679
+ ...e === void 0 && {
680
+ error: null,
681
+ status: "pending"
682
+ }
683
+ };
684
+ }
685
+ function me(e, t) {
686
+ return {
687
+ data: e,
688
+ dataUpdatedAt: t ?? Date.now(),
689
+ error: null,
690
+ isInvalidated: !1,
691
+ status: "success"
692
+ };
693
+ }
694
+ function he(e) {
695
+ let t = typeof e.initialData == "function" ? e.initialData() : e.initialData, n = t !== void 0, r = n ? typeof e.initialDataUpdatedAt == "function" ? e.initialDataUpdatedAt() : e.initialDataUpdatedAt : 0;
696
+ return {
697
+ data: t,
698
+ dataUpdateCount: 0,
699
+ dataUpdatedAt: n ? r ?? Date.now() : 0,
700
+ error: null,
701
+ errorUpdateCount: 0,
702
+ errorUpdatedAt: 0,
703
+ fetchFailureCount: 0,
704
+ fetchFailureReason: null,
705
+ fetchMeta: null,
706
+ isInvalidated: !1,
707
+ status: n ? "success" : "pending",
708
+ fetchStatus: "idle"
709
+ };
710
+ }
711
+ //#endregion
712
+ //#region node_modules/@tanstack/query-core/build/modern/queryObserver.js
713
+ var ge = class extends m {
714
+ constructor(e, t) {
715
+ super(), this.options = t, this.#e = e, this.#s = null, this.#o = L(), this.bindMethods(), this.setOptions(t);
716
+ }
717
+ #e;
718
+ #t = void 0;
719
+ #n = void 0;
720
+ #r = void 0;
721
+ #i;
722
+ #a;
723
+ #o;
724
+ #s;
725
+ #c;
726
+ #l;
727
+ #u;
728
+ #d;
729
+ #f;
730
+ #p;
731
+ #m = /* @__PURE__ */ new Set();
732
+ bindMethods() {
733
+ this.refetch = this.refetch.bind(this);
734
+ }
735
+ onSubscribe() {
736
+ this.listeners.size === 1 && (this.#t.addObserver(this), ve(this.#t, this.options) ? this.#h() : this.updateResult(), this.#y());
737
+ }
738
+ onUnsubscribe() {
739
+ this.hasListeners() || this.destroy();
740
+ }
741
+ shouldFetchOnReconnect() {
742
+ return W(this.#t, this.options, this.options.refetchOnReconnect);
743
+ }
744
+ shouldFetchOnWindowFocus() {
745
+ return W(this.#t, this.options, this.options.refetchOnWindowFocus);
746
+ }
747
+ destroy() {
748
+ this.listeners = /* @__PURE__ */ new Set(), this.#b(), this.#x(), this.#t.removeObserver(this);
749
+ }
750
+ setOptions(e) {
751
+ let t = this.options, n = this.#t;
752
+ if (this.options = this.#e.defaultQueryOptions(e), this.options.enabled !== void 0 && typeof this.options.enabled != "boolean" && typeof this.options.enabled != "function" && typeof T(this.options.enabled, this.#t) != "boolean") throw Error("Expected enabled to be a boolean or a callback that returns a boolean");
753
+ this.#S(), this.#t.setOptions(this.options), t._defaulted && !M(this.options, t) && this.#e.getQueryCache().notify({
754
+ type: "observerOptionsUpdated",
755
+ query: this.#t,
756
+ observer: this
757
+ });
758
+ let r = this.hasListeners();
759
+ r && ye(this.#t, n, this.options, t) && this.#h(), this.updateResult(), r && (this.#t !== n || T(this.options.enabled, this.#t) !== T(t.enabled, this.#t) || w(this.options.staleTime, this.#t) !== w(t.staleTime, this.#t)) && this.#g();
760
+ let i = this.#_();
761
+ r && (this.#t !== n || T(this.options.enabled, this.#t) !== T(t.enabled, this.#t) || i !== this.#p) && this.#v(i);
762
+ }
763
+ getOptimisticResult(e) {
764
+ let t = this.#e.getQueryCache().build(this.#e, e), n = this.createResult(t, e);
765
+ return be(this, n) && (this.#r = n, this.#a = this.options, this.#i = this.#t.state), n;
766
+ }
767
+ getCurrentResult() {
768
+ return this.#r;
769
+ }
770
+ trackResult(e, t) {
771
+ return new Proxy(e, { get: (e, n) => (this.trackProp(n), t?.(n), n === "promise" && (this.trackProp("data"), !this.options.experimental_prefetchInRender && this.#o.status === "pending" && this.#o.reject(/* @__PURE__ */ Error("experimental_prefetchInRender feature flag is not enabled"))), Reflect.get(e, n)) });
772
+ }
773
+ trackProp(e) {
774
+ this.#m.add(e);
775
+ }
776
+ getCurrentQuery() {
777
+ return this.#t;
778
+ }
779
+ refetch({ ...e } = {}) {
780
+ return this.fetch({ ...e });
781
+ }
782
+ fetchOptimistic(e) {
783
+ let t = this.#e.defaultQueryOptions(e), n = this.#e.getQueryCache().build(this.#e, t);
784
+ return n.fetch().then(() => this.createResult(n, t));
785
+ }
786
+ fetch(e) {
787
+ return this.#h({
788
+ ...e,
789
+ cancelRefetch: e.cancelRefetch ?? !0
790
+ }).then(() => (this.updateResult(), this.#r));
791
+ }
792
+ #h(e) {
793
+ this.#S();
794
+ let t = this.#t.fetch(this.options, e);
795
+ return e?.throwOnError || (t = t.catch(b)), t;
796
+ }
797
+ #g() {
798
+ this.#b();
799
+ let e = w(this.options.staleTime, this.#t);
800
+ if (I.isServer() || this.#r.isStale || !S(e)) return;
801
+ let t = C(this.#r.dataUpdatedAt, e) + 1;
802
+ this.#d = _.setTimeout(() => {
803
+ this.#r.isStale || this.updateResult();
804
+ }, t);
805
+ }
806
+ #_() {
807
+ return (typeof this.options.refetchInterval == "function" ? this.options.refetchInterval(this.#t) : this.options.refetchInterval) ?? !1;
808
+ }
809
+ #v(e) {
810
+ this.#x(), this.#p = e, !(I.isServer() || T(this.options.enabled, this.#t) === !1 || !S(this.#p) || this.#p === 0) && (this.#f = _.setInterval(() => {
811
+ (this.options.refetchIntervalInBackground || h.isFocused()) && this.#h();
812
+ }, this.#p));
813
+ }
814
+ #y() {
815
+ this.#g(), this.#v(this.#_());
816
+ }
817
+ #b() {
818
+ this.#d !== void 0 && (_.clearTimeout(this.#d), this.#d = void 0);
819
+ }
820
+ #x() {
821
+ this.#f !== void 0 && (_.clearInterval(this.#f), this.#f = void 0);
822
+ }
823
+ createResult(e, t) {
824
+ let n = this.#t, r = this.options, i = this.#r, a = this.#i, o = this.#a, s = e === n ? this.#n : e.state, { state: c } = e, l = { ...c }, u = !1, d;
825
+ if (t._optimisticResults) {
826
+ let i = this.hasListeners(), a = !i && ve(e, t), o = i && ye(e, n, t, r);
827
+ (a || o) && (l = {
828
+ ...l,
829
+ ...U(c.data, e.options)
830
+ }), t._optimisticResults === "isRestoring" && (l.fetchStatus = "idle");
831
+ }
832
+ let { error: f, errorUpdatedAt: p, status: m } = l;
833
+ d = l.data;
834
+ let h = !1;
835
+ if (t.placeholderData !== void 0 && d === void 0 && m === "pending") {
836
+ let e;
837
+ i?.isPlaceholderData && t.placeholderData === o?.placeholderData ? (e = i.data, h = !0) : e = typeof t.placeholderData == "function" ? t.placeholderData(this.#u?.state.data, this.#u) : t.placeholderData, e !== void 0 && (m = "success", d = P(i?.data, e, t), u = !0);
838
+ }
839
+ if (t.select && d !== void 0 && !h) if (i && d === a?.data && t.select === this.#c) d = this.#l;
840
+ else try {
841
+ this.#c = t.select, d = t.select(d), d = P(i?.data, d, t), this.#l = d, this.#s = null;
842
+ } catch (e) {
843
+ this.#s = e;
844
+ }
845
+ this.#s && (f = this.#s, d = this.#l, p = Date.now(), m = "error");
846
+ let g = l.fetchStatus === "fetching", _ = m === "pending", v = m === "error", y = _ && g, b = d !== void 0, x = {
847
+ status: m,
848
+ fetchStatus: l.fetchStatus,
849
+ isPending: _,
850
+ isSuccess: m === "success",
851
+ isError: v,
852
+ isInitialLoading: y,
853
+ isLoading: y,
854
+ data: d,
855
+ dataUpdatedAt: l.dataUpdatedAt,
856
+ error: f,
857
+ errorUpdatedAt: p,
858
+ failureCount: l.fetchFailureCount,
859
+ failureReason: l.fetchFailureReason,
860
+ errorUpdateCount: l.errorUpdateCount,
861
+ isFetched: e.isFetched(),
862
+ isFetchedAfterMount: l.dataUpdateCount > s.dataUpdateCount || l.errorUpdateCount > s.errorUpdateCount,
863
+ isFetching: g,
864
+ isRefetching: g && !_,
865
+ isLoadingError: v && !b,
866
+ isPaused: l.fetchStatus === "paused",
867
+ isPlaceholderData: u,
868
+ isRefetchError: v && b,
869
+ isStale: G(e, t),
870
+ refetch: this.refetch,
871
+ promise: this.#o,
872
+ isEnabled: T(t.enabled, e) !== !1
873
+ };
874
+ if (this.options.experimental_prefetchInRender) {
875
+ let t = x.data !== void 0, r = x.status === "error" && !t, i = (e) => {
876
+ r ? e.reject(x.error) : t && e.resolve(x.data);
877
+ }, a = () => {
878
+ i(this.#o = x.promise = L());
879
+ }, o = this.#o;
880
+ switch (o.status) {
881
+ case "pending":
882
+ e.queryHash === n.queryHash && i(o);
883
+ break;
884
+ case "fulfilled":
885
+ (r || x.data !== o.value) && a();
886
+ break;
887
+ case "rejected":
888
+ (!r || x.error !== o.reason) && a();
889
+ break;
890
+ }
891
+ }
892
+ return x;
893
+ }
894
+ updateResult() {
895
+ let e = this.#r, t = this.createResult(this.#t, this.options);
896
+ this.#i = this.#t.state, this.#a = this.options, this.#i.data !== void 0 && (this.#u = this.#t), !M(t, e) && (this.#r = t, this.#C({ listeners: (() => {
897
+ if (!e) return !0;
898
+ let { notifyOnChangeProps: t } = this.options, n = typeof t == "function" ? t() : t;
899
+ if (n === "all" || !n && !this.#m.size) return !0;
900
+ let r = new Set(n ?? this.#m);
901
+ return this.options.throwOnError && r.add("error"), Object.keys(this.#r).some((t) => {
902
+ let n = t;
903
+ return this.#r[n] !== e[n] && r.has(n);
904
+ });
905
+ })() }));
906
+ }
907
+ #S() {
908
+ let e = this.#e.getQueryCache().build(this.#e, this.options);
909
+ if (e === this.#t) return;
910
+ let t = this.#t;
911
+ this.#t = e, this.#n = e.state, this.hasListeners() && (t?.removeObserver(this), e.addObserver(this));
912
+ }
913
+ onQueryUpdate() {
914
+ this.updateResult(), this.hasListeners() && this.#y();
915
+ }
916
+ #C(e) {
917
+ R.batch(() => {
918
+ e.listeners && this.listeners.forEach((e) => {
919
+ e(this.#r);
920
+ }), this.#e.getQueryCache().notify({
921
+ query: this.#t,
922
+ type: "observerResultsUpdated"
923
+ });
924
+ });
925
+ }
926
+ };
927
+ function _e(e, t) {
928
+ return T(t.enabled, e) !== !1 && e.state.data === void 0 && !(e.state.status === "error" && t.retryOnMount === !1);
929
+ }
930
+ function ve(e, t) {
931
+ return _e(e, t) || e.state.data !== void 0 && W(e, t, t.refetchOnMount);
932
+ }
933
+ function W(e, t, n) {
934
+ if (T(t.enabled, e) !== !1 && w(t.staleTime, e) !== "static") {
935
+ let r = typeof n == "function" ? n(e) : n;
936
+ return r === "always" || r !== !1 && G(e, t);
937
+ }
938
+ return !1;
939
+ }
940
+ function ye(e, t, n, r) {
941
+ return (e !== t || T(r.enabled, e) === !1) && (!n.suspense || e.state.status !== "error") && G(e, n);
942
+ }
943
+ function G(e, t) {
944
+ return T(t.enabled, e) !== !1 && e.isStaleByTime(w(t.staleTime, e));
945
+ }
946
+ function be(e, t) {
947
+ return !M(e.getCurrentResult(), t);
948
+ }
949
+ //#endregion
950
+ //#region node_modules/@tanstack/query-core/build/modern/infiniteQueryBehavior.js
951
+ function xe(e) {
952
+ return { onFetch: (t, n) => {
953
+ let r = t.options, i = t.fetchOptions?.meta?.fetchMore?.direction, a = t.state.data?.pages || [], o = t.state.data?.pageParams || [], s = {
954
+ pages: [],
955
+ pageParams: []
956
+ }, c = 0, l = async () => {
957
+ let n = !1, l = (e) => {
958
+ ce(e, () => t.signal, () => n = !0);
959
+ }, u = oe(t.options, t.fetchOptions), d = async (e, r, i) => {
960
+ if (n) return Promise.reject();
961
+ if (r == null && e.pages.length) return Promise.resolve(e);
962
+ let a = await u((() => {
963
+ let e = {
964
+ client: t.client,
965
+ queryKey: t.queryKey,
966
+ pageParam: r,
967
+ direction: i ? "backward" : "forward",
968
+ meta: t.options.meta
969
+ };
970
+ return l(e), e;
971
+ })()), { maxPages: o } = t.options, s = i ? ae : ie;
972
+ return {
973
+ pages: s(e.pages, a, o),
974
+ pageParams: s(e.pageParams, r, o)
975
+ };
976
+ };
977
+ if (i && a.length) {
978
+ let e = i === "backward", t = e ? Ce : Se, n = {
979
+ pages: a,
980
+ pageParams: o
981
+ };
982
+ s = await d(n, t(r, n), e);
983
+ } else {
984
+ let t = e ?? a.length;
985
+ do {
986
+ let e = c === 0 ? o[0] ?? r.initialPageParam : Se(r, s);
987
+ if (c > 0 && e == null) break;
988
+ s = await d(s, e), c++;
989
+ } while (c < t);
990
+ }
991
+ return s;
992
+ };
993
+ t.options.persister ? t.fetchFn = () => t.options.persister?.(l, {
994
+ client: t.client,
995
+ queryKey: t.queryKey,
996
+ meta: t.options.meta,
997
+ signal: t.signal
998
+ }, n) : t.fetchFn = l;
999
+ } };
1000
+ }
1001
+ function Se(e, { pages: t, pageParams: n }) {
1002
+ let r = t.length - 1;
1003
+ return t.length > 0 ? e.getNextPageParam(t[r], t, n[r], n) : void 0;
1004
+ }
1005
+ function Ce(e, { pages: t, pageParams: n }) {
1006
+ return t.length > 0 ? e.getPreviousPageParam?.(t[0], t, n[0], n) : void 0;
1007
+ }
1008
+ //#endregion
1009
+ //#region node_modules/@tanstack/query-core/build/modern/mutation.js
1010
+ var we = class extends fe {
1011
+ #e;
1012
+ #t;
1013
+ #n;
1014
+ #r;
1015
+ constructor(e) {
1016
+ super(), this.#e = e.client, this.mutationId = e.mutationId, this.#n = e.mutationCache, this.#t = [], this.state = e.state || Te(), this.setOptions(e.options), this.scheduleGc();
1017
+ }
1018
+ setOptions(e) {
1019
+ this.options = e, this.updateGcTime(this.options.gcTime);
1020
+ }
1021
+ get meta() {
1022
+ return this.options.meta;
1023
+ }
1024
+ addObserver(e) {
1025
+ this.#t.includes(e) || (this.#t.push(e), this.clearGcTimeout(), this.#n.notify({
1026
+ type: "observerAdded",
1027
+ mutation: this,
1028
+ observer: e
1029
+ }));
1030
+ }
1031
+ removeObserver(e) {
1032
+ this.#t = this.#t.filter((t) => t !== e), this.scheduleGc(), this.#n.notify({
1033
+ type: "observerRemoved",
1034
+ mutation: this,
1035
+ observer: e
1036
+ });
1037
+ }
1038
+ optionalRemove() {
1039
+ this.#t.length || (this.state.status === "pending" ? this.scheduleGc() : this.#n.remove(this));
1040
+ }
1041
+ continue() {
1042
+ return this.#r?.continue() ?? this.execute(this.state.variables);
1043
+ }
1044
+ async execute(e) {
1045
+ let t = () => {
1046
+ this.#i({ type: "continue" });
1047
+ }, n = {
1048
+ client: this.#e,
1049
+ meta: this.options.meta,
1050
+ mutationKey: this.options.mutationKey
1051
+ };
1052
+ this.#r = H({
1053
+ fn: () => this.options.mutationFn ? this.options.mutationFn(e, n) : Promise.reject(/* @__PURE__ */ Error("No mutationFn found")),
1054
+ onFail: (e, t) => {
1055
+ this.#i({
1056
+ type: "failed",
1057
+ failureCount: e,
1058
+ error: t
1059
+ });
1060
+ },
1061
+ onPause: () => {
1062
+ this.#i({ type: "pause" });
1063
+ },
1064
+ onContinue: t,
1065
+ retry: this.options.retry ?? 0,
1066
+ retryDelay: this.options.retryDelay,
1067
+ networkMode: this.options.networkMode,
1068
+ canRun: () => this.#n.canRun(this)
1069
+ });
1070
+ let r = this.state.status === "pending", i = !this.#r.canStart();
1071
+ try {
1072
+ if (r) t();
1073
+ else {
1074
+ this.#i({
1075
+ type: "pending",
1076
+ variables: e,
1077
+ isPaused: i
1078
+ }), this.#n.config.onMutate && await this.#n.config.onMutate(e, this, n);
1079
+ let t = await this.options.onMutate?.(e, n);
1080
+ t !== this.state.context && this.#i({
1081
+ type: "pending",
1082
+ context: t,
1083
+ variables: e,
1084
+ isPaused: i
1085
+ });
1086
+ }
1087
+ let a = await this.#r.start();
1088
+ return await this.#n.config.onSuccess?.(a, e, this.state.context, this, n), await this.options.onSuccess?.(a, e, this.state.context, n), await this.#n.config.onSettled?.(a, null, this.state.variables, this.state.context, this, n), await this.options.onSettled?.(a, null, e, this.state.context, n), this.#i({
1089
+ type: "success",
1090
+ data: a
1091
+ }), a;
1092
+ } catch (t) {
1093
+ try {
1094
+ await this.#n.config.onError?.(t, e, this.state.context, this, n);
1095
+ } catch (e) {
1096
+ Promise.reject(e);
1097
+ }
1098
+ try {
1099
+ await this.options.onError?.(t, e, this.state.context, n);
1100
+ } catch (e) {
1101
+ Promise.reject(e);
1102
+ }
1103
+ try {
1104
+ await this.#n.config.onSettled?.(void 0, t, this.state.variables, this.state.context, this, n);
1105
+ } catch (e) {
1106
+ Promise.reject(e);
1107
+ }
1108
+ try {
1109
+ await this.options.onSettled?.(void 0, t, e, this.state.context, n);
1110
+ } catch (e) {
1111
+ Promise.reject(e);
1112
+ }
1113
+ throw this.#i({
1114
+ type: "error",
1115
+ error: t
1116
+ }), t;
1117
+ } finally {
1118
+ this.#n.runNext(this);
1119
+ }
1120
+ }
1121
+ #i(e) {
1122
+ this.state = ((t) => {
1123
+ switch (e.type) {
1124
+ case "failed": return {
1125
+ ...t,
1126
+ failureCount: e.failureCount,
1127
+ failureReason: e.error
1128
+ };
1129
+ case "pause": return {
1130
+ ...t,
1131
+ isPaused: !0
1132
+ };
1133
+ case "continue": return {
1134
+ ...t,
1135
+ isPaused: !1
1136
+ };
1137
+ case "pending": return {
1138
+ ...t,
1139
+ context: e.context,
1140
+ data: void 0,
1141
+ failureCount: 0,
1142
+ failureReason: null,
1143
+ error: null,
1144
+ isPaused: e.isPaused,
1145
+ status: "pending",
1146
+ variables: e.variables,
1147
+ submittedAt: Date.now()
1148
+ };
1149
+ case "success": return {
1150
+ ...t,
1151
+ data: e.data,
1152
+ failureCount: 0,
1153
+ failureReason: null,
1154
+ error: null,
1155
+ status: "success",
1156
+ isPaused: !1
1157
+ };
1158
+ case "error": return {
1159
+ ...t,
1160
+ data: void 0,
1161
+ error: e.error,
1162
+ failureCount: t.failureCount + 1,
1163
+ failureReason: e.error,
1164
+ isPaused: !1,
1165
+ status: "error"
1166
+ };
1167
+ }
1168
+ })(this.state), R.batch(() => {
1169
+ this.#t.forEach((t) => {
1170
+ t.onMutationUpdate(e);
1171
+ }), this.#n.notify({
1172
+ mutation: this,
1173
+ type: "updated",
1174
+ action: e
1175
+ });
1176
+ });
1177
+ }
1178
+ };
1179
+ function Te() {
1180
+ return {
1181
+ context: void 0,
1182
+ data: void 0,
1183
+ error: null,
1184
+ failureCount: 0,
1185
+ failureReason: null,
1186
+ isPaused: !1,
1187
+ status: "idle",
1188
+ variables: void 0,
1189
+ submittedAt: 0
1190
+ };
1191
+ }
1192
+ //#endregion
1193
+ //#region node_modules/@tanstack/query-core/build/modern/mutationCache.js
1194
+ var Ee = class extends m {
1195
+ constructor(e = {}) {
1196
+ super(), this.config = e, this.#e = /* @__PURE__ */ new Set(), this.#t = /* @__PURE__ */ new Map(), this.#n = 0;
1197
+ }
1198
+ #e;
1199
+ #t;
1200
+ #n;
1201
+ build(e, t, n) {
1202
+ let r = new we({
1203
+ client: e,
1204
+ mutationCache: this,
1205
+ mutationId: ++this.#n,
1206
+ options: e.defaultMutationOptions(t),
1207
+ state: n
1208
+ });
1209
+ return this.add(r), r;
1210
+ }
1211
+ add(e) {
1212
+ this.#e.add(e);
1213
+ let t = K(e);
1214
+ if (typeof t == "string") {
1215
+ let n = this.#t.get(t);
1216
+ n ? n.push(e) : this.#t.set(t, [e]);
1217
+ }
1218
+ this.notify({
1219
+ type: "added",
1220
+ mutation: e
1221
+ });
1222
+ }
1223
+ remove(e) {
1224
+ if (this.#e.delete(e)) {
1225
+ let t = K(e);
1226
+ if (typeof t == "string") {
1227
+ let n = this.#t.get(t);
1228
+ if (n) if (n.length > 1) {
1229
+ let t = n.indexOf(e);
1230
+ t !== -1 && n.splice(t, 1);
1231
+ } else n[0] === e && this.#t.delete(t);
1232
+ }
1233
+ }
1234
+ this.notify({
1235
+ type: "removed",
1236
+ mutation: e
1237
+ });
1238
+ }
1239
+ canRun(e) {
1240
+ let t = K(e);
1241
+ if (typeof t == "string") {
1242
+ let n = this.#t.get(t)?.find((e) => e.state.status === "pending");
1243
+ return !n || n === e;
1244
+ } else return !0;
1245
+ }
1246
+ runNext(e) {
1247
+ let t = K(e);
1248
+ return typeof t == "string" ? (this.#t.get(t)?.find((t) => t !== e && t.state.isPaused))?.continue() ?? Promise.resolve() : Promise.resolve();
1249
+ }
1250
+ clear() {
1251
+ R.batch(() => {
1252
+ this.#e.forEach((e) => {
1253
+ this.notify({
1254
+ type: "removed",
1255
+ mutation: e
1256
+ });
1257
+ }), this.#e.clear(), this.#t.clear();
1258
+ });
1259
+ }
1260
+ getAll() {
1261
+ return Array.from(this.#e);
1262
+ }
1263
+ find(e) {
1264
+ let t = {
1265
+ exact: !0,
1266
+ ...e
1267
+ };
1268
+ return this.getAll().find((e) => D(t, e));
1269
+ }
1270
+ findAll(e = {}) {
1271
+ return this.getAll().filter((t) => D(e, t));
1272
+ }
1273
+ notify(e) {
1274
+ R.batch(() => {
1275
+ this.listeners.forEach((t) => {
1276
+ t(e);
1277
+ });
1278
+ });
1279
+ }
1280
+ resumePausedMutations() {
1281
+ let e = this.getAll().filter((e) => e.state.isPaused);
1282
+ return R.batch(() => Promise.all(e.map((e) => e.continue().catch(b))));
1283
+ }
1284
+ };
1285
+ function K(e) {
1286
+ return e.options.scope?.id;
1287
+ }
1288
+ //#endregion
1289
+ //#region node_modules/@tanstack/query-core/build/modern/queryCache.js
1290
+ var De = class extends m {
1291
+ constructor(e = {}) {
1292
+ super(), this.config = e, this.#e = /* @__PURE__ */ new Map();
1293
+ }
1294
+ #e;
1295
+ build(e, t, n) {
1296
+ let r = t.queryKey, i = t.queryHash ?? O(r, t), a = this.get(i);
1297
+ return a || (a = new pe({
1298
+ client: e,
1299
+ queryKey: r,
1300
+ queryHash: i,
1301
+ options: e.defaultQueryOptions(t),
1302
+ state: n,
1303
+ defaultOptions: e.getQueryDefaults(r)
1304
+ }), this.add(a)), a;
1305
+ }
1306
+ add(e) {
1307
+ this.#e.has(e.queryHash) || (this.#e.set(e.queryHash, e), this.notify({
1308
+ type: "added",
1309
+ query: e
1310
+ }));
1311
+ }
1312
+ remove(e) {
1313
+ let t = this.#e.get(e.queryHash);
1314
+ t && (e.destroy(), t === e && this.#e.delete(e.queryHash), this.notify({
1315
+ type: "removed",
1316
+ query: e
1317
+ }));
1318
+ }
1319
+ clear() {
1320
+ R.batch(() => {
1321
+ this.getAll().forEach((e) => {
1322
+ this.remove(e);
1323
+ });
1324
+ });
1325
+ }
1326
+ get(e) {
1327
+ return this.#e.get(e);
1328
+ }
1329
+ getAll() {
1330
+ return [...this.#e.values()];
1331
+ }
1332
+ find(e) {
1333
+ let t = {
1334
+ exact: !0,
1335
+ ...e
1336
+ };
1337
+ return this.getAll().find((e) => E(t, e));
1338
+ }
1339
+ findAll(e = {}) {
1340
+ let t = this.getAll();
1341
+ return Object.keys(e).length > 0 ? t.filter((t) => E(e, t)) : t;
1342
+ }
1343
+ notify(e) {
1344
+ R.batch(() => {
1345
+ this.listeners.forEach((t) => {
1346
+ t(e);
1347
+ });
1348
+ });
1349
+ }
1350
+ onFocus() {
1351
+ R.batch(() => {
1352
+ this.getAll().forEach((e) => {
1353
+ e.onFocus();
1354
+ });
1355
+ });
1356
+ }
1357
+ onOnline() {
1358
+ R.batch(() => {
1359
+ this.getAll().forEach((e) => {
1360
+ e.onOnline();
1361
+ });
1362
+ });
1363
+ }
1364
+ }, Oe = class {
1365
+ #e;
1366
+ #t;
1367
+ #n;
1368
+ #r;
1369
+ #i;
1370
+ #a;
1371
+ #o;
1372
+ #s;
1373
+ constructor(e = {}) {
1374
+ this.#e = e.queryCache || new De(), this.#t = e.mutationCache || new Ee(), this.#n = e.defaultOptions || {}, this.#r = /* @__PURE__ */ new Map(), this.#i = /* @__PURE__ */ new Map(), this.#a = 0;
1375
+ }
1376
+ mount() {
1377
+ this.#a++, this.#a === 1 && (this.#o = h.subscribe(async (e) => {
1378
+ e && (await this.resumePausedMutations(), this.#e.onFocus());
1379
+ }), this.#s = z.subscribe(async (e) => {
1380
+ e && (await this.resumePausedMutations(), this.#e.onOnline());
1381
+ }));
1382
+ }
1383
+ unmount() {
1384
+ this.#a--, this.#a === 0 && (this.#o?.(), this.#o = void 0, this.#s?.(), this.#s = void 0);
1385
+ }
1386
+ isFetching(e) {
1387
+ return this.#e.findAll({
1388
+ ...e,
1389
+ fetchStatus: "fetching"
1390
+ }).length;
1391
+ }
1392
+ isMutating(e) {
1393
+ return this.#t.findAll({
1394
+ ...e,
1395
+ status: "pending"
1396
+ }).length;
1397
+ }
1398
+ getQueryData(e) {
1399
+ let t = this.defaultQueryOptions({ queryKey: e });
1400
+ return this.#e.get(t.queryHash)?.state.data;
1401
+ }
1402
+ ensureQueryData(e) {
1403
+ let t = this.defaultQueryOptions(e), n = this.#e.build(this, t), r = n.state.data;
1404
+ return r === void 0 ? this.fetchQuery(e) : (e.revalidateIfStale && n.isStaleByTime(w(t.staleTime, n)) && this.prefetchQuery(t), Promise.resolve(r));
1405
+ }
1406
+ getQueriesData(e) {
1407
+ return this.#e.findAll(e).map(({ queryKey: e, state: t }) => [e, t.data]);
1408
+ }
1409
+ setQueryData(e, t, n) {
1410
+ let r = this.defaultQueryOptions({ queryKey: e }), i = this.#e.get(r.queryHash)?.state.data, a = x(t, i);
1411
+ if (a !== void 0) return this.#e.build(this, r).setData(a, {
1412
+ ...n,
1413
+ manual: !0
1414
+ });
1415
+ }
1416
+ setQueriesData(e, t, n) {
1417
+ return R.batch(() => this.#e.findAll(e).map(({ queryKey: e }) => [e, this.setQueryData(e, t, n)]));
1418
+ }
1419
+ getQueryState(e) {
1420
+ let t = this.defaultQueryOptions({ queryKey: e });
1421
+ return this.#e.get(t.queryHash)?.state;
1422
+ }
1423
+ removeQueries(e) {
1424
+ let t = this.#e;
1425
+ R.batch(() => {
1426
+ t.findAll(e).forEach((e) => {
1427
+ t.remove(e);
1428
+ });
1429
+ });
1430
+ }
1431
+ resetQueries(e, t) {
1432
+ let n = this.#e;
1433
+ return R.batch(() => (n.findAll(e).forEach((e) => {
1434
+ e.reset();
1435
+ }), this.refetchQueries({
1436
+ type: "active",
1437
+ ...e
1438
+ }, t)));
1439
+ }
1440
+ cancelQueries(e, t = {}) {
1441
+ let n = {
1442
+ revert: !0,
1443
+ ...t
1444
+ }, r = R.batch(() => this.#e.findAll(e).map((e) => e.cancel(n)));
1445
+ return Promise.all(r).then(b).catch(b);
1446
+ }
1447
+ invalidateQueries(e, t = {}) {
1448
+ return R.batch(() => (this.#e.findAll(e).forEach((e) => {
1449
+ e.invalidate();
1450
+ }), e?.refetchType === "none" ? Promise.resolve() : this.refetchQueries({
1451
+ ...e,
1452
+ type: e?.refetchType ?? e?.type ?? "active"
1453
+ }, t)));
1454
+ }
1455
+ refetchQueries(e, t = {}) {
1456
+ let n = {
1457
+ ...t,
1458
+ cancelRefetch: t.cancelRefetch ?? !0
1459
+ }, r = R.batch(() => this.#e.findAll(e).filter((e) => !e.isDisabled() && !e.isStatic()).map((e) => {
1460
+ let t = e.fetch(void 0, n);
1461
+ return n.throwOnError || (t = t.catch(b)), e.state.fetchStatus === "paused" ? Promise.resolve() : t;
1462
+ }));
1463
+ return Promise.all(r).then(b);
1464
+ }
1465
+ fetchQuery(e) {
1466
+ let t = this.defaultQueryOptions(e);
1467
+ t.retry === void 0 && (t.retry = !1);
1468
+ let n = this.#e.build(this, t);
1469
+ return n.isStaleByTime(w(t.staleTime, n)) ? n.fetch(t) : Promise.resolve(n.state.data);
1470
+ }
1471
+ prefetchQuery(e) {
1472
+ return this.fetchQuery(e).then(b).catch(b);
1473
+ }
1474
+ fetchInfiniteQuery(e) {
1475
+ return e.behavior = xe(e.pages), this.fetchQuery(e);
1476
+ }
1477
+ prefetchInfiniteQuery(e) {
1478
+ return this.fetchInfiniteQuery(e).then(b).catch(b);
1479
+ }
1480
+ ensureInfiniteQueryData(e) {
1481
+ return e.behavior = xe(e.pages), this.ensureQueryData(e);
1482
+ }
1483
+ resumePausedMutations() {
1484
+ return z.isOnline() ? this.#t.resumePausedMutations() : Promise.resolve();
1485
+ }
1486
+ getQueryCache() {
1487
+ return this.#e;
1488
+ }
1489
+ getMutationCache() {
1490
+ return this.#t;
1491
+ }
1492
+ getDefaultOptions() {
1493
+ return this.#n;
1494
+ }
1495
+ setDefaultOptions(e) {
1496
+ this.#n = e;
1497
+ }
1498
+ setQueryDefaults(e, t) {
1499
+ this.#r.set(k(e), {
1500
+ queryKey: e,
1501
+ defaultOptions: t
1502
+ });
1503
+ }
1504
+ getQueryDefaults(e) {
1505
+ let t = [...this.#r.values()], n = {};
1506
+ return t.forEach((t) => {
1507
+ A(e, t.queryKey) && Object.assign(n, t.defaultOptions);
1508
+ }), n;
1509
+ }
1510
+ setMutationDefaults(e, t) {
1511
+ this.#i.set(k(e), {
1512
+ mutationKey: e,
1513
+ defaultOptions: t
1514
+ });
1515
+ }
1516
+ getMutationDefaults(e) {
1517
+ let t = [...this.#i.values()], n = {};
1518
+ return t.forEach((t) => {
1519
+ A(e, t.mutationKey) && Object.assign(n, t.defaultOptions);
1520
+ }), n;
1521
+ }
1522
+ defaultQueryOptions(e) {
1523
+ if (e._defaulted) return e;
1524
+ let t = {
1525
+ ...this.#n.queries,
1526
+ ...this.getQueryDefaults(e.queryKey),
1527
+ ...e,
1528
+ _defaulted: !0
1529
+ };
1530
+ return t.queryHash ||= O(t.queryKey, t), t.refetchOnReconnect === void 0 && (t.refetchOnReconnect = t.networkMode !== "always"), t.throwOnError === void 0 && (t.throwOnError = !!t.suspense), !t.networkMode && t.persister && (t.networkMode = "offlineFirst"), t.queryFn === F && (t.enabled = !1), t;
1531
+ }
1532
+ defaultMutationOptions(e) {
1533
+ return e?._defaulted ? e : {
1534
+ ...this.#n.mutations,
1535
+ ...e?.mutationKey && this.getMutationDefaults(e.mutationKey),
1536
+ ...e,
1537
+ _defaulted: !0
1538
+ };
1539
+ }
1540
+ clear() {
1541
+ this.#e.clear(), this.#t.clear();
1542
+ }
1543
+ }, q = e.createContext(void 0), ke = (t) => {
1544
+ let n = e.useContext(q);
1545
+ if (t) return t;
1546
+ if (!n) throw Error("No QueryClient set, use QueryClientProvider to set one");
1547
+ return n;
1548
+ }, Ae = ({ client: t, children: n }) => (e.useEffect(() => (t.mount(), () => {
1549
+ t.unmount();
1550
+ }), [t]), /* @__PURE__ */ u(q.Provider, {
1551
+ value: t,
1552
+ children: n
1553
+ })), je = e.createContext(!1), Me = () => e.useContext(je);
1554
+ je.Provider;
1555
+ //#endregion
1556
+ //#region node_modules/@tanstack/react-query/build/modern/QueryErrorResetBoundary.js
1557
+ function Ne() {
1558
+ let e = !1;
1559
+ return {
1560
+ clearReset: () => {
1561
+ e = !1;
1562
+ },
1563
+ reset: () => {
1564
+ e = !0;
1565
+ },
1566
+ isReset: () => e
1567
+ };
1568
+ }
1569
+ var Pe = e.createContext(Ne()), Fe = () => e.useContext(Pe), Ie = (e, t, n) => {
1570
+ let r = n?.state.error && typeof e.throwOnError == "function" ? se(e.throwOnError, [n.state.error, n]) : e.throwOnError;
1571
+ (e.suspense || e.experimental_prefetchInRender || r) && (t.isReset() || (e.retryOnMount = !1));
1572
+ }, Le = (t) => {
1573
+ e.useEffect(() => {
1574
+ t.clearReset();
1575
+ }, [t]);
1576
+ }, Re = ({ result: e, errorResetBoundary: t, throwOnError: n, query: r, suspense: i }) => e.isError && !t.isReset() && !e.isFetching && r && (i && e.data === void 0 || se(n, [e.error, r])), ze = (e) => {
1577
+ if (e.suspense) {
1578
+ let t = 1e3, n = (e) => e === "static" ? e : Math.max(e ?? t, t), r = e.staleTime;
1579
+ e.staleTime = typeof r == "function" ? (...e) => n(r(...e)) : n(r), typeof e.gcTime == "number" && (e.gcTime = Math.max(e.gcTime, t));
1580
+ }
1581
+ }, Be = (e, t) => e.isLoading && e.isFetching && !t, Ve = (e, t) => e?.suspense && t.isPending, He = (e, t, n) => t.fetchOptimistic(e).catch(() => {
1582
+ n.clearReset();
1583
+ });
1584
+ //#endregion
1585
+ //#region node_modules/@tanstack/react-query/build/modern/useBaseQuery.js
1586
+ function Ue(t, n, r) {
1587
+ if (process.env.NODE_ENV !== "production" && (typeof t != "object" || Array.isArray(t))) throw Error("Bad argument type. Starting with v5, only the \"Object\" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object");
1588
+ let i = Me(), a = Fe(), o = ke(r), s = o.defaultQueryOptions(t);
1589
+ o.getDefaultOptions().queries?._experimental_beforeQuery?.(s);
1590
+ let c = o.getQueryCache().get(s.queryHash);
1591
+ process.env.NODE_ENV !== "production" && (s.queryFn || console.error(`[${s.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`)), s._optimisticResults = i ? "isRestoring" : "optimistic", ze(s), Ie(s, a, c), Le(a);
1592
+ let l = !o.getQueryCache().get(s.queryHash), [u] = e.useState(() => new n(o, s)), d = u.getOptimisticResult(s), f = !i && t.subscribed !== !1;
1593
+ if (e.useSyncExternalStore(e.useCallback((e) => {
1594
+ let t = f ? u.subscribe(R.batchCalls(e)) : b;
1595
+ return u.updateResult(), t;
1596
+ }, [u, f]), () => u.getCurrentResult(), () => u.getCurrentResult()), e.useEffect(() => {
1597
+ u.setOptions(s);
1598
+ }, [s, u]), Ve(s, d)) throw He(s, u, a);
1599
+ if (Re({
1600
+ result: d,
1601
+ errorResetBoundary: a,
1602
+ throwOnError: s.throwOnError,
1603
+ query: c,
1604
+ suspense: s.suspense
1605
+ })) throw d.error;
1606
+ return o.getDefaultOptions().queries?._experimental_afterQuery?.(s, d), s.experimental_prefetchInRender && !I.isServer() && Be(d, i) && (l ? He(s, u, a) : c?.promise)?.catch(b).finally(() => {
1607
+ u.updateResult();
1608
+ }), s.notifyOnChangeProps ? d : u.trackResult(d);
1609
+ }
1610
+ //#endregion
1611
+ //#region node_modules/@tanstack/react-query/build/modern/useQuery.js
1612
+ function We(e, t) {
1613
+ return Ue(e, ge, t);
1614
+ }
1615
+ //#endregion
1616
+ //#region node_modules/lucide-react/dist/esm/shared/src/utils/mergeClasses.js
1617
+ var Ge = (...e) => e.filter((e, t, n) => !!e && e.trim() !== "" && n.indexOf(e) === t).join(" ").trim(), Ke = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), qe = (e) => e.replace(/^([A-Z])|[\s-_]+(\w)/g, (e, t, n) => n ? n.toUpperCase() : t.toLowerCase()), Je = (e) => {
1618
+ let t = qe(e);
1619
+ return t.charAt(0).toUpperCase() + t.slice(1);
1620
+ }, J = {
1621
+ xmlns: "http://www.w3.org/2000/svg",
1622
+ width: 24,
1623
+ height: 24,
1624
+ viewBox: "0 0 24 24",
1625
+ fill: "none",
1626
+ stroke: "currentColor",
1627
+ strokeWidth: 2,
1628
+ strokeLinecap: "round",
1629
+ strokeLinejoin: "round"
1630
+ }, Ye = (e) => {
1631
+ for (let t in e) if (t.startsWith("aria-") || t === "role" || t === "title") return !0;
1632
+ return !1;
1633
+ }, Xe = t({}), Ze = () => a(Xe), Qe = r(({ color: e, size: t, strokeWidth: r, absoluteStrokeWidth: i, className: a = "", children: o, iconNode: s, ...c }, l) => {
1634
+ let { size: u = 24, strokeWidth: d = 2, absoluteStrokeWidth: f = !1, color: p = "currentColor", className: m = "" } = Ze() ?? {}, h = i ?? f ? Number(r ?? d) * 24 / Number(t ?? u) : r ?? d;
1635
+ return n("svg", {
1636
+ ref: l,
1637
+ ...J,
1638
+ width: t ?? u ?? J.width,
1639
+ height: t ?? u ?? J.height,
1640
+ stroke: e ?? p,
1641
+ strokeWidth: h,
1642
+ className: Ge("lucide", m, a),
1643
+ ...!o && !Ye(c) && { "aria-hidden": "true" },
1644
+ ...c
1645
+ }, [...s.map(([e, t]) => n(e, t)), ...Array.isArray(o) ? o : [o]]);
1646
+ }), Y = (e, t) => {
1647
+ let i = r(({ className: r, ...i }, a) => n(Qe, {
1648
+ ref: a,
1649
+ iconNode: t,
1650
+ className: Ge(`lucide-${Ke(Je(e))}`, `lucide-${e}`, r),
1651
+ ...i
1652
+ }));
1653
+ return i.displayName = Je(e), i;
1654
+ }, $e = Y("chevron-down", [["path", {
1655
+ d: "m6 9 6 6 6-6",
1656
+ key: "qrunsl"
1657
+ }]]), et = Y("download", [
1658
+ ["path", {
1659
+ d: "M12 15V3",
1660
+ key: "m9g1x1"
1661
+ }],
1662
+ ["path", {
1663
+ d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",
1664
+ key: "ih7n3h"
1665
+ }],
1666
+ ["path", {
1667
+ d: "m7 10 5 5 5-5",
1668
+ key: "brsn70"
1669
+ }]
1670
+ ]), X = Y("paperclip", [["path", {
1671
+ d: "m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",
1672
+ key: "1miecu"
1673
+ }]]), tt = Y("square-pen", [["path", {
1674
+ d: "M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",
1675
+ key: "1m0v6g"
1676
+ }], ["path", {
1677
+ d: "M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",
1678
+ key: "ohrbg2"
1679
+ }]]), nt = Y("x", [["path", {
1680
+ d: "M18 6 6 18",
1681
+ key: "1bl5f8"
1682
+ }], ["path", {
1683
+ d: "m6 6 12 12",
1684
+ key: "d8bk6v"
1685
+ }]]), rt = (e, t, n) => {
1686
+ typeof n == "string" || n instanceof Blob ? e.append(t, n) : n instanceof Date ? e.append(t, n.toISOString()) : e.append(t, JSON.stringify(n));
1687
+ }, it = { bodySerializer: (e) => {
1688
+ let t = new FormData();
1689
+ return Object.entries(e).forEach(([e, n]) => {
1690
+ n != null && (Array.isArray(n) ? n.forEach((n) => rt(t, e, n)) : rt(t, e, n));
1691
+ }), t;
1692
+ } }, at = { bodySerializer: (e) => JSON.stringify(e, (e, t) => typeof t == "bigint" ? t.toString() : t) };
1693
+ Object.entries({
1694
+ $body_: "body",
1695
+ $headers_: "headers",
1696
+ $path_: "path",
1697
+ $query_: "query"
1698
+ });
1699
+ //#endregion
1700
+ //#region src/shared/api/v1/core/serverSentEvents.gen.ts
1701
+ function ot({ onRequest: e, onSseError: t, onSseEvent: n, responseTransformer: r, responseValidator: i, sseDefaultRetryDelay: a, sseMaxRetryAttempts: o, sseMaxRetryDelay: s, sseSleepFn: c, url: l, ...u }) {
1702
+ let d, f = c ?? ((e) => new Promise((t) => setTimeout(t, e)));
1703
+ return { stream: async function* () {
1704
+ let c = a ?? 3e3, p = 0, m = u.signal ?? new AbortController().signal;
1705
+ for (; !m.aborted;) {
1706
+ p++;
1707
+ let a = u.headers instanceof Headers ? u.headers : new Headers(u.headers);
1708
+ d !== void 0 && a.set("Last-Event-ID", d);
1709
+ try {
1710
+ let t = {
1711
+ redirect: "follow",
1712
+ ...u,
1713
+ body: u.serializedBody,
1714
+ headers: a,
1715
+ signal: m
1716
+ }, o = new Request(l, t);
1717
+ e && (o = await e(l, t));
1718
+ let s = await (u.fetch ?? globalThis.fetch)(o);
1719
+ if (!s.ok) throw Error(`SSE failed: ${s.status} ${s.statusText}`);
1720
+ if (!s.body) throw Error("No body in SSE response");
1721
+ let f = s.body.pipeThrough(new TextDecoderStream()).getReader(), p = "", h = () => {
1722
+ try {
1723
+ f.cancel();
1724
+ } catch {}
1725
+ };
1726
+ m.addEventListener("abort", h);
1727
+ try {
1728
+ for (;;) {
1729
+ let { done: e, value: t } = await f.read();
1730
+ if (e) break;
1731
+ p += t, p = p.replace(/\r\n?/g, "\n");
1732
+ let a = p.split("\n\n");
1733
+ p = a.pop() ?? "";
1734
+ for (let e of a) {
1735
+ let t = e.split("\n"), a = [], o;
1736
+ for (let e of t) if (e.startsWith("data:")) a.push(e.replace(/^data:\s*/, ""));
1737
+ else if (e.startsWith("event:")) o = e.replace(/^event:\s*/, "");
1738
+ else if (e.startsWith("id:")) d = e.replace(/^id:\s*/, "");
1739
+ else if (e.startsWith("retry:")) {
1740
+ let t = Number.parseInt(e.replace(/^retry:\s*/, ""), 10);
1741
+ Number.isNaN(t) || (c = t);
1742
+ }
1743
+ let s, l = !1;
1744
+ if (a.length) {
1745
+ let e = a.join("\n");
1746
+ try {
1747
+ s = JSON.parse(e), l = !0;
1748
+ } catch {
1749
+ s = e;
1750
+ }
1751
+ }
1752
+ l && (i && await i(s), r && (s = await r(s))), n?.({
1753
+ data: s,
1754
+ event: o,
1755
+ id: d,
1756
+ retry: c
1757
+ }), a.length && (yield s);
1758
+ }
1759
+ }
1760
+ } finally {
1761
+ m.removeEventListener("abort", h), f.releaseLock();
1762
+ }
1763
+ break;
1764
+ } catch (e) {
1765
+ if (t?.(e), o !== void 0 && p >= o) break;
1766
+ await f(Math.min(c * 2 ** (p - 1), s ?? 3e4));
1767
+ }
1768
+ }
1769
+ }() };
1770
+ }
1771
+ //#endregion
1772
+ //#region src/shared/api/v1/core/pathSerializer.gen.ts
1773
+ var st = (e) => {
1774
+ switch (e) {
1775
+ case "label": return ".";
1776
+ case "matrix": return ";";
1777
+ case "simple": return ",";
1778
+ default: return "&";
1779
+ }
1780
+ }, ct = (e) => {
1781
+ switch (e) {
1782
+ case "form": return ",";
1783
+ case "pipeDelimited": return "|";
1784
+ case "spaceDelimited": return "%20";
1785
+ default: return ",";
1786
+ }
1787
+ }, lt = (e) => {
1788
+ switch (e) {
1789
+ case "label": return ".";
1790
+ case "matrix": return ";";
1791
+ case "simple": return ",";
1792
+ default: return "&";
1793
+ }
1794
+ }, ut = ({ allowReserved: e, explode: t, name: n, style: r, value: i }) => {
1795
+ if (!t) {
1796
+ let t = (e ? i : i.map((e) => encodeURIComponent(e))).join(ct(r));
1797
+ switch (r) {
1798
+ case "label": return `.${t}`;
1799
+ case "matrix": return `;${n}=${t}`;
1800
+ case "simple": return t;
1801
+ default: return `${n}=${t}`;
1802
+ }
1803
+ }
1804
+ let a = st(r), o = i.map((t) => r === "label" || r === "simple" ? e ? t : encodeURIComponent(t) : Z({
1805
+ allowReserved: e,
1806
+ name: n,
1807
+ value: t
1808
+ })).join(a);
1809
+ return r === "label" || r === "matrix" ? a + o : o;
1810
+ }, Z = ({ allowReserved: e, name: t, value: n }) => {
1811
+ if (n == null) return "";
1812
+ if (typeof n == "object") throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
1813
+ return `${t}=${e ? n : encodeURIComponent(n)}`;
1814
+ }, dt = ({ allowReserved: e, explode: t, name: n, style: r, value: i, valueOnly: a }) => {
1815
+ if (i instanceof Date) return a ? i.toISOString() : `${n}=${i.toISOString()}`;
1816
+ if (r !== "deepObject" && !t) {
1817
+ let t = [];
1818
+ Object.entries(i).forEach(([n, r]) => {
1819
+ t = [
1820
+ ...t,
1821
+ n,
1822
+ e ? r : encodeURIComponent(r)
1823
+ ];
1824
+ });
1825
+ let a = t.join(",");
1826
+ switch (r) {
1827
+ case "form": return `${n}=${a}`;
1828
+ case "label": return `.${a}`;
1829
+ case "matrix": return `;${n}=${a}`;
1830
+ default: return a;
1831
+ }
1832
+ }
1833
+ let o = lt(r), s = Object.entries(i).map(([t, i]) => Z({
1834
+ allowReserved: e,
1835
+ name: r === "deepObject" ? `${n}[${t}]` : t,
1836
+ value: i
1837
+ })).join(o);
1838
+ return r === "label" || r === "matrix" ? o + s : s;
1839
+ }, ft = /\{[^{}]+\}/g, pt = ({ path: e, url: t }) => {
1840
+ let n = t, r = t.match(ft);
1841
+ if (r) for (let t of r) {
1842
+ let r = !1, i = t.substring(1, t.length - 1), a = "simple";
1843
+ i.endsWith("*") && (r = !0, i = i.substring(0, i.length - 1)), i.startsWith(".") ? (i = i.substring(1), a = "label") : i.startsWith(";") && (i = i.substring(1), a = "matrix");
1844
+ let o = e[i];
1845
+ if (o == null) continue;
1846
+ if (Array.isArray(o)) {
1847
+ n = n.replace(t, ut({
1848
+ explode: r,
1849
+ name: i,
1850
+ style: a,
1851
+ value: o
1852
+ }));
1853
+ continue;
1854
+ }
1855
+ if (typeof o == "object") {
1856
+ n = n.replace(t, dt({
1857
+ explode: r,
1858
+ name: i,
1859
+ style: a,
1860
+ value: o,
1861
+ valueOnly: !0
1862
+ }));
1863
+ continue;
1864
+ }
1865
+ if (a === "matrix") {
1866
+ n = n.replace(t, `;${Z({
1867
+ name: i,
1868
+ value: o
1869
+ })}`);
1870
+ continue;
1871
+ }
1872
+ let s = encodeURIComponent(a === "label" ? `.${o}` : o);
1873
+ n = n.replace(t, s);
1874
+ }
1875
+ return n;
1876
+ }, mt = ({ baseUrl: e, path: t, query: n, querySerializer: r, url: i }) => {
1877
+ let a = i.startsWith("/") ? i : `/${i}`, o = (e ?? "") + a;
1878
+ t && (o = pt({
1879
+ path: t,
1880
+ url: o
1881
+ }));
1882
+ let s = n ? r(n) : "";
1883
+ return s.startsWith("?") && (s = s.substring(1)), s && (o += `?${s}`), o;
1884
+ };
1885
+ function ht(e) {
1886
+ let t = e.body !== void 0;
1887
+ if (t && e.bodySerializer) return "serializedBody" in e ? e.serializedBody !== void 0 && e.serializedBody !== "" ? e.serializedBody : null : e.body === "" ? null : e.body;
1888
+ if (t) return e.body;
1889
+ }
1890
+ //#endregion
1891
+ //#region src/shared/api/v1/core/auth.gen.ts
1892
+ var gt = async (e, t) => {
1893
+ let n = typeof t == "function" ? await t(e) : t;
1894
+ if (n) return e.scheme === "bearer" ? `Bearer ${n}` : e.scheme === "basic" ? `Basic ${btoa(n)}` : n;
1895
+ }, _t = ({ parameters: e = {}, ...t } = {}) => (n) => {
1896
+ let r = [];
1897
+ if (n && typeof n == "object") for (let i in n) {
1898
+ let a = n[i];
1899
+ if (a == null) continue;
1900
+ let o = e[i] || t;
1901
+ if (Array.isArray(a)) {
1902
+ let e = ut({
1903
+ allowReserved: o.allowReserved,
1904
+ explode: !0,
1905
+ name: i,
1906
+ style: "form",
1907
+ value: a,
1908
+ ...o.array
1909
+ });
1910
+ e && r.push(e);
1911
+ } else if (typeof a == "object") {
1912
+ let e = dt({
1913
+ allowReserved: o.allowReserved,
1914
+ explode: !0,
1915
+ name: i,
1916
+ style: "deepObject",
1917
+ value: a,
1918
+ ...o.object
1919
+ });
1920
+ e && r.push(e);
1921
+ } else {
1922
+ let e = Z({
1923
+ allowReserved: o.allowReserved,
1924
+ name: i,
1925
+ value: a
1926
+ });
1927
+ e && r.push(e);
1928
+ }
1929
+ }
1930
+ return r.join("&");
1931
+ }, vt = (e) => {
1932
+ if (!e) return "stream";
1933
+ let t = e.split(";")[0]?.trim();
1934
+ if (t) {
1935
+ if (t.startsWith("application/json") || t.endsWith("+json")) return "json";
1936
+ if (t === "multipart/form-data") return "formData";
1937
+ if ([
1938
+ "application/",
1939
+ "audio/",
1940
+ "image/",
1941
+ "video/"
1942
+ ].some((e) => t.startsWith(e))) return "blob";
1943
+ if (t.startsWith("text/")) return "text";
1944
+ }
1945
+ }, yt = (e, t) => t ? !!(e.headers.has(t) || e.query?.[t] || e.headers.get("Cookie")?.includes(`${t}=`)) : !1, bt = async ({ security: e, ...t }) => {
1946
+ for (let n of e) {
1947
+ if (yt(t, n.name)) continue;
1948
+ let e = await gt(n, t.auth);
1949
+ if (!e) continue;
1950
+ let r = n.name ?? "Authorization";
1951
+ switch (n.in) {
1952
+ case "query":
1953
+ t.query ||= {}, t.query[r] = e;
1954
+ break;
1955
+ case "cookie":
1956
+ t.headers.append("Cookie", `${r}=${e}`);
1957
+ break;
1958
+ default:
1959
+ t.headers.set(r, e);
1960
+ break;
1961
+ }
1962
+ }
1963
+ }, xt = (e) => mt({
1964
+ baseUrl: e.baseUrl,
1965
+ path: e.path,
1966
+ query: e.query,
1967
+ querySerializer: typeof e.querySerializer == "function" ? e.querySerializer : _t(e.querySerializer),
1968
+ url: e.url
1969
+ }), St = (e, t) => {
1970
+ let n = {
1971
+ ...e,
1972
+ ...t
1973
+ };
1974
+ return n.baseUrl?.endsWith("/") && (n.baseUrl = n.baseUrl.substring(0, n.baseUrl.length - 1)), n.headers = wt(e.headers, t.headers), n;
1975
+ }, Ct = (e) => {
1976
+ let t = [];
1977
+ return e.forEach((e, n) => {
1978
+ t.push([n, e]);
1979
+ }), t;
1980
+ }, wt = (...e) => {
1981
+ let t = new Headers();
1982
+ for (let n of e) {
1983
+ if (!n) continue;
1984
+ let e = n instanceof Headers ? Ct(n) : Object.entries(n);
1985
+ for (let [n, r] of e) if (r === null) t.delete(n);
1986
+ else if (Array.isArray(r)) for (let e of r) t.append(n, e);
1987
+ else r !== void 0 && t.set(n, typeof r == "object" ? JSON.stringify(r) : r);
1988
+ }
1989
+ return t;
1990
+ }, Q = class {
1991
+ fns = [];
1992
+ clear() {
1993
+ this.fns = [];
1994
+ }
1995
+ eject(e) {
1996
+ let t = this.getInterceptorIndex(e);
1997
+ this.fns[t] && (this.fns[t] = null);
1998
+ }
1999
+ exists(e) {
2000
+ let t = this.getInterceptorIndex(e);
2001
+ return !!this.fns[t];
2002
+ }
2003
+ getInterceptorIndex(e) {
2004
+ return typeof e == "number" ? this.fns[e] ? e : -1 : this.fns.indexOf(e);
2005
+ }
2006
+ update(e, t) {
2007
+ let n = this.getInterceptorIndex(e);
2008
+ return this.fns[n] ? (this.fns[n] = t, e) : !1;
2009
+ }
2010
+ use(e) {
2011
+ return this.fns.push(e), this.fns.length - 1;
2012
+ }
2013
+ }, Tt = () => ({
2014
+ error: new Q(),
2015
+ request: new Q(),
2016
+ response: new Q()
2017
+ }), Et = _t({
2018
+ allowReserved: !1,
2019
+ array: {
2020
+ explode: !0,
2021
+ style: "form"
2022
+ },
2023
+ object: {
2024
+ explode: !0,
2025
+ style: "deepObject"
2026
+ }
2027
+ }), Dt = { "Content-Type": "application/json" }, Ot = (e = {}) => ({
2028
+ ...at,
2029
+ headers: Dt,
2030
+ parseAs: "auto",
2031
+ querySerializer: Et,
2032
+ ...e
2033
+ }), $ = ((e = {}) => {
2034
+ let t = St(Ot(), e), n = () => ({ ...t }), r = (e) => (t = St(t, e), n()), i = Tt(), a = async (e) => {
2035
+ let n = {
2036
+ ...t,
2037
+ ...e,
2038
+ fetch: e.fetch ?? t.fetch ?? globalThis.fetch,
2039
+ headers: wt(t.headers, e.headers),
2040
+ serializedBody: void 0
2041
+ };
2042
+ n.security && await bt({
2043
+ ...n,
2044
+ security: n.security
2045
+ }), n.requestValidator && await n.requestValidator(n), n.body !== void 0 && n.bodySerializer && (n.serializedBody = n.bodySerializer(n.body)), (n.body === void 0 || n.serializedBody === "") && n.headers.delete("Content-Type");
2046
+ let r = n;
2047
+ return {
2048
+ opts: r,
2049
+ url: xt(r)
2050
+ };
2051
+ }, o = async (e) => {
2052
+ let { opts: t, url: n } = await a(e), r = {
2053
+ redirect: "follow",
2054
+ ...t,
2055
+ body: ht(t)
2056
+ }, o = new Request(n, r);
2057
+ for (let e of i.request.fns) e && (o = await e(o, t));
2058
+ let s = t.fetch, c;
2059
+ try {
2060
+ c = await s(o);
2061
+ } catch (e) {
2062
+ let n = e;
2063
+ for (let r of i.error.fns) r && (n = await r(e, void 0, o, t));
2064
+ if (n ||= {}, t.throwOnError) throw n;
2065
+ return t.responseStyle === "data" ? void 0 : {
2066
+ error: n,
2067
+ request: o,
2068
+ response: void 0
2069
+ };
2070
+ }
2071
+ for (let e of i.response.fns) e && (c = await e(c, o, t));
2072
+ let l = {
2073
+ request: o,
2074
+ response: c
2075
+ };
2076
+ if (c.ok) {
2077
+ let e = (t.parseAs === "auto" ? vt(c.headers.get("Content-Type")) : t.parseAs) ?? "json";
2078
+ if (c.status === 204 || c.headers.get("Content-Length") === "0") {
2079
+ let n;
2080
+ switch (e) {
2081
+ case "arrayBuffer":
2082
+ case "blob":
2083
+ case "text":
2084
+ n = await c[e]();
2085
+ break;
2086
+ case "formData":
2087
+ n = new FormData();
2088
+ break;
2089
+ case "stream":
2090
+ n = c.body;
2091
+ break;
2092
+ default:
2093
+ n = {};
2094
+ break;
2095
+ }
2096
+ return t.responseStyle === "data" ? n : {
2097
+ data: n,
2098
+ ...l
2099
+ };
2100
+ }
2101
+ let n;
2102
+ switch (e) {
2103
+ case "arrayBuffer":
2104
+ case "blob":
2105
+ case "formData":
2106
+ case "text":
2107
+ n = await c[e]();
2108
+ break;
2109
+ case "json": {
2110
+ let e = await c.text();
2111
+ n = e ? JSON.parse(e) : {};
2112
+ break;
2113
+ }
2114
+ case "stream": return t.responseStyle === "data" ? c.body : {
2115
+ data: c.body,
2116
+ ...l
2117
+ };
2118
+ }
2119
+ return e === "json" && (t.responseValidator && await t.responseValidator(n), t.responseTransformer && (n = await t.responseTransformer(n))), t.responseStyle === "data" ? n : {
2120
+ data: n,
2121
+ ...l
2122
+ };
2123
+ }
2124
+ let u = await c.text(), d;
2125
+ try {
2126
+ d = JSON.parse(u);
2127
+ } catch {}
2128
+ let f = d ?? u, p = f;
2129
+ for (let e of i.error.fns) e && (p = await e(f, c, o, t));
2130
+ if (p ||= {}, t.throwOnError) throw p;
2131
+ return t.responseStyle === "data" ? void 0 : {
2132
+ error: p,
2133
+ ...l
2134
+ };
2135
+ }, s = (e) => (t) => o({
2136
+ ...t,
2137
+ method: e
2138
+ }), c = (e) => async (t) => {
2139
+ let { opts: n, url: r } = await a(t);
2140
+ return ot({
2141
+ ...n,
2142
+ body: n.body,
2143
+ headers: n.headers,
2144
+ method: e,
2145
+ onRequest: async (e, t) => {
2146
+ let r = new Request(e, t);
2147
+ for (let e of i.request.fns) e && (r = await e(r, n));
2148
+ return r;
2149
+ },
2150
+ serializedBody: ht(n),
2151
+ url: r
2152
+ });
2153
+ };
2154
+ return {
2155
+ buildUrl: (e) => xt({
2156
+ ...t,
2157
+ ...e
2158
+ }),
2159
+ connect: s("CONNECT"),
2160
+ delete: s("DELETE"),
2161
+ get: s("GET"),
2162
+ getConfig: n,
2163
+ head: s("HEAD"),
2164
+ interceptors: i,
2165
+ options: s("OPTIONS"),
2166
+ patch: s("PATCH"),
2167
+ post: s("POST"),
2168
+ put: s("PUT"),
2169
+ request: o,
2170
+ setConfig: r,
2171
+ sse: {
2172
+ connect: c("CONNECT"),
2173
+ delete: c("DELETE"),
2174
+ get: c("GET"),
2175
+ head: c("HEAD"),
2176
+ options: c("OPTIONS"),
2177
+ patch: c("PATCH"),
2178
+ post: c("POST"),
2179
+ put: c("PUT"),
2180
+ trace: c("TRACE")
2181
+ },
2182
+ trace: s("TRACE")
2183
+ };
2184
+ })(Ot({ baseUrl: "http://localhost:9000/api/widget" }));
2185
+ //#endregion
2186
+ //#region src/shared/api/setup.ts
2187
+ function kt(e, t) {
2188
+ $.setConfig({
2189
+ baseUrl: e,
2190
+ headers: t ? { Authorization: `Bearer ${t}` } : void 0
2191
+ });
2192
+ }
2193
+ //#endregion
2194
+ //#region src/shared/api/v1/sdk.gen.ts
2195
+ var At = (e) => (e?.client ?? $).get({
2196
+ security: [{
2197
+ scheme: "bearer",
2198
+ type: "http"
2199
+ }],
2200
+ url: "/threads",
2201
+ ...e
2202
+ }), jt = (e) => (e.client ?? $).get({
2203
+ security: [{
2204
+ scheme: "bearer",
2205
+ type: "http"
2206
+ }],
2207
+ url: "/threads/{threadUid}",
2208
+ ...e
2209
+ }), Mt = (e) => (e.client ?? $).post({
2210
+ ...it,
2211
+ security: [{
2212
+ scheme: "bearer",
2213
+ type: "http"
2214
+ }],
2215
+ url: "/attachments/upload",
2216
+ ...e,
2217
+ headers: {
2218
+ "Content-Type": null,
2219
+ ...e.headers
2220
+ }
2221
+ }), Nt = (e) => (e.client ?? $).get({
2222
+ security: [{
2223
+ scheme: "bearer",
2224
+ type: "http"
2225
+ }],
2226
+ url: "/attachments/{filename}",
2227
+ ...e
2228
+ }), Pt = {
2229
+ upload: async (e, t, n) => {
2230
+ let { data: r } = await Mt({
2231
+ body: {
2232
+ file: e,
2233
+ prefix: t,
2234
+ ocr: n
2235
+ },
2236
+ throwOnError: !0
2237
+ });
2238
+ return r.data;
2239
+ },
2240
+ download: async (e, t) => {
2241
+ let n = e.split("/"), r = n[n.length - 1], i = n.slice(-3, -1).join("/"), { data: a } = await Nt({
2242
+ path: { filename: r },
2243
+ query: i ? { prefix: i } : {},
2244
+ parseAs: "blob",
2245
+ throwOnError: !0
2246
+ }), o = URL.createObjectURL(a), s = document.createElement("a");
2247
+ s.href = o, s.download = t, document.body.appendChild(s), s.click(), document.body.removeChild(s), URL.revokeObjectURL(o);
2248
+ }
2249
+ };
2250
+ //#endregion
2251
+ //#region src/components/EricaChatInput.tsx
2252
+ function Ft({ onSend: e, inProgress: t, threadId: n }) {
2253
+ let [r, i] = l(""), [a, s] = l([]), [f, p] = l(!1), [m, h] = l(null), g = c(null), _ = c(null), v = c(0);
2254
+ o(() => {
2255
+ let e = g.current;
2256
+ if (e) {
2257
+ e.style.height = "auto";
2258
+ let t = e.scrollHeight;
2259
+ e.style.height = `${t}px`;
2260
+ }
2261
+ }, [r]);
2262
+ async function y(e) {
2263
+ let t = `${e.name}-${Date.now()}`;
2264
+ s((n) => [...n, {
2265
+ id: t,
2266
+ name: e.name,
2267
+ mimeType: e.type || "application/octet-stream",
2268
+ status: "uploading"
2269
+ }]);
2270
+ try {
2271
+ let r = await Pt.upload(e, `thread/${n || crypto.randomUUID()}`, !0);
2272
+ s((e) => e.map((e) => e.id === t ? {
2273
+ ...e,
2274
+ status: "done",
2275
+ response: r
2276
+ } : e));
2277
+ } catch (e) {
2278
+ let n = e instanceof Error ? e.message : "Upload failed";
2279
+ s((e) => e.map((e) => e.id === t ? {
2280
+ ...e,
2281
+ status: "error",
2282
+ errorMessage: n
2283
+ } : e));
2284
+ }
2285
+ }
2286
+ function b(e) {
2287
+ let t = e.target.files;
2288
+ if (!t || t.length === 0) return;
2289
+ let n = new Set(a.map((e) => e.name));
2290
+ Array.from(t).filter((e) => !n.has(e.name)).forEach(y), e.target.value = "";
2291
+ }
2292
+ function x(e) {
2293
+ s((t) => t.filter((t) => t.id !== e));
2294
+ }
2295
+ async function S(e) {
2296
+ if (e.response) {
2297
+ h(e.id);
2298
+ try {
2299
+ await Pt.download(e.response.file_path, e.response.original_name);
2300
+ } catch (t) {
2301
+ console.error("Download failed:", t), alert(`Failed to download ${e.name}`);
2302
+ } finally {
2303
+ h(null);
2304
+ }
2305
+ }
2306
+ }
2307
+ function C(e) {
2308
+ e.preventDefault(), v.current += 1, e.dataTransfer.types.includes("Files") && p(!0);
2309
+ }
2310
+ function w(e) {
2311
+ e.preventDefault(), --v.current, v.current === 0 && p(!1);
2312
+ }
2313
+ function T(e) {
2314
+ e.preventDefault();
2315
+ }
2316
+ function E(e) {
2317
+ e.preventDefault(), v.current = 0, p(!1);
2318
+ let t = Array.from(e.dataTransfer.files);
2319
+ if (t.length === 0) return;
2320
+ let n = new Set(a.map((e) => e.name));
2321
+ t.filter((e) => !n.has(e.name)).forEach(y);
2322
+ }
2323
+ function D() {
2324
+ if (!r.trim() && a.length === 0) return;
2325
+ let t = a.filter((e) => e.status === "done").filter((e) => e.response !== null).map((e) => e.response).map(({ ocr_result: e, ...t }) => ({
2326
+ ...t,
2327
+ ocr_result: e?.markdown_files
2328
+ })), n = r;
2329
+ t.length > 0 && (n += `\n\n\`\`\`attachments\n${JSON.stringify(t, null, 2)}\n\`\`\``), e(n), i(""), s([]);
2330
+ }
2331
+ function O(e) {
2332
+ e.key === "Enter" && !e.shiftKey && (e.preventDefault(), D());
2333
+ }
2334
+ function k() {
2335
+ g.current?.focus();
2336
+ }
2337
+ return /* @__PURE__ */ d("div", {
2338
+ className: "copilotKitInputContainer relative",
2339
+ onDragEnter: C,
2340
+ onDragLeave: w,
2341
+ onDragOver: T,
2342
+ onDrop: E,
2343
+ children: [
2344
+ f && /* @__PURE__ */ u("div", {
2345
+ className: "absolute inset-0 z-50 bg-teal-50/90 rounded-lg flex items-center justify-center pointer-events-none",
2346
+ children: /* @__PURE__ */ u("p", {
2347
+ className: "text-sm font-medium text-teal-600",
2348
+ children: "Drop files to attach"
2349
+ })
2350
+ }),
2351
+ a.length > 0 && /* @__PURE__ */ u("div", {
2352
+ className: "flex flex-col gap-2 mb-2",
2353
+ children: a.map((e) => /* @__PURE__ */ d("div", {
2354
+ className: `
2355
+ px-3 py-2 rounded-lg flex items-center justify-between
2356
+ ${e.status === "error" ? "bg-red-50" : e.status === "done" ? "bg-green-50" : "bg-gray-100"}
2357
+ `,
2358
+ children: [/* @__PURE__ */ d("div", {
2359
+ className: `
2360
+ flex items-center gap-2 flex-1 rounded-lg transition-colors
2361
+ ${e.status === "done" ? "cursor-pointer hover:bg-green-100 -mx-3 -my-2 px-3 py-2" : ""}
2362
+ `,
2363
+ onClick: () => e.status === "done" && S(e),
2364
+ role: e.status === "done" ? "button" : void 0,
2365
+ tabIndex: e.status === "done" ? 0 : void 0,
2366
+ children: [
2367
+ e.status === "uploading" ? /* @__PURE__ */ u("div", { className: "w-4 h-4 border-2 border-gray-500 border-t-transparent rounded-full animate-spin" }) : m === e.id ? /* @__PURE__ */ u("div", { className: "w-4 h-4 border-2 border-green-500 border-t-transparent rounded-full animate-spin" }) : e.status === "done" ? /* @__PURE__ */ u(X, { className: "w-4 h-4 text-green-600" }) : /* @__PURE__ */ u(X, { className: "w-4 h-4 text-red-600" }),
2368
+ /* @__PURE__ */ d("div", {
2369
+ className: "flex-1 min-w-0",
2370
+ children: [/* @__PURE__ */ d("div", {
2371
+ className: `
2372
+ text-sm font-medium truncate
2373
+ ${e.status === "error" ? "text-red-700" : e.status === "done" ? "text-green-700" : "text-gray-700"}
2374
+ `,
2375
+ children: [e.name, m === e.id && /* @__PURE__ */ u("span", {
2376
+ className: "ml-2 text-xs text-green-600",
2377
+ children: "Downloading..."
2378
+ })]
2379
+ }), /* @__PURE__ */ d("div", {
2380
+ className: "text-xs text-gray-500",
2381
+ children: [
2382
+ e.status === "uploading" && "Uploading...",
2383
+ e.status === "done" && "Ready · Click to download",
2384
+ e.status === "error" && (e.errorMessage || "Upload failed")
2385
+ ]
2386
+ })]
2387
+ }),
2388
+ e.status === "done" && !m && /* @__PURE__ */ u(et, { className: "w-4 h-4 text-green-600 opacity-0 group-hover:opacity-100 transition-opacity" })
2389
+ ]
2390
+ }), /* @__PURE__ */ u("button", {
2391
+ onClick: (t) => {
2392
+ t.stopPropagation(), x(e.id);
2393
+ },
2394
+ disabled: e.status === "uploading",
2395
+ className: "ml-2 p-1 hover:bg-black/10 rounded transition-colors disabled:opacity-50 disabled:cursor-not-allowed",
2396
+ "aria-label": `Remove ${e.name}`,
2397
+ children: /* @__PURE__ */ u(nt, { className: "w-4 h-4 text-gray-500" })
2398
+ })]
2399
+ }, e.id))
2400
+ }),
2401
+ /* @__PURE__ */ d("div", {
2402
+ className: "copilotKitInput",
2403
+ onClick: k,
2404
+ children: [/* @__PURE__ */ u("textarea", {
2405
+ ref: g,
2406
+ value: r,
2407
+ onChange: (e) => i(e.target.value),
2408
+ onKeyDown: O,
2409
+ placeholder: a.length > 0 ? `Ask about ${a.length} file${a.length > 1 ? "s" : ""}...` : "Type a message or attach files...",
2410
+ className: "overflow-auto resize-none",
2411
+ rows: 1,
2412
+ disabled: t
2413
+ }), /* @__PURE__ */ d("div", {
2414
+ className: "copilotKitInputControls",
2415
+ children: [
2416
+ /* @__PURE__ */ u("input", {
2417
+ ref: _,
2418
+ type: "file",
2419
+ onChange: b,
2420
+ className: "hidden",
2421
+ disabled: t,
2422
+ multiple: !0
2423
+ }),
2424
+ /* @__PURE__ */ u("button", {
2425
+ onClick: () => _.current?.click(),
2426
+ disabled: t,
2427
+ className: "copilotKitInputControlButton mr-2",
2428
+ "aria-label": "Attach files",
2429
+ title: "Attach files (drag & drop supported)",
2430
+ children: /* @__PURE__ */ u(X, { className: "w-5 h-5" })
2431
+ }),
2432
+ /* @__PURE__ */ u("div", { className: "grow" }),
2433
+ /* @__PURE__ */ u("button", {
2434
+ onClick: D,
2435
+ disabled: t || !r.trim() && a.filter((e) => e.status === "done").length === 0,
2436
+ "data-copilotkit-in-progress": t,
2437
+ className: "copilotKitInputControlButton",
2438
+ children: /* @__PURE__ */ u("svg", {
2439
+ xmlns: "http://www.w3.org/2000/svg",
2440
+ fill: "none",
2441
+ viewBox: "0 0 24 24",
2442
+ strokeWidth: "1.5",
2443
+ stroke: "currentColor",
2444
+ width: "24",
2445
+ height: "24",
2446
+ children: /* @__PURE__ */ u("path", {
2447
+ strokeLinecap: "round",
2448
+ strokeLinejoin: "round",
2449
+ d: "M12 19V5m0 0l-7 7m7-7l7 7"
2450
+ })
2451
+ })
2452
+ })
2453
+ ]
2454
+ })]
2455
+ })
2456
+ ]
2457
+ });
2458
+ }
2459
+ //#endregion
2460
+ //#region src/lib/thread-api.ts
2461
+ var It = {
2462
+ list: async (e = 15) => {
2463
+ let { data: t } = await At({
2464
+ query: {
2465
+ page: 1,
2466
+ page_size: e
2467
+ },
2468
+ throwOnError: !0
2469
+ });
2470
+ return t.data ?? [];
2471
+ },
2472
+ get: async (e) => {
2473
+ let { data: t } = await jt({
2474
+ path: { threadUid: e },
2475
+ throwOnError: !0
2476
+ });
2477
+ return t.data;
2478
+ }
2479
+ }, Lt = {
2480
+ all: () => ["widget-threads"],
2481
+ detail: (e) => ["widget-threads", e]
2482
+ }, Rt = (e = 15) => We({
2483
+ queryKey: Lt.all(),
2484
+ queryFn: () => It.list(e),
2485
+ staleTime: 15e3,
2486
+ refetchOnWindowFocus: !0
2487
+ });
2488
+ //#endregion
2489
+ //#region src/components/EricaChatHeader.tsx
2490
+ function zt(e) {
2491
+ if (!e) return "";
2492
+ let t = e.split(":");
2493
+ return (t.length > 1 ? t.slice(1).join(" ") : e).replace(/[-_]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase());
2494
+ }
2495
+ function Bt(e) {
2496
+ if (!e) return "";
2497
+ let t = Date.now() - new Date(e).getTime(), n = Math.floor(t / 6e4), r = Math.floor(n / 60), i = Math.floor(r / 24);
2498
+ return n < 1 ? "just now" : n < 60 ? `${n}m ago` : r < 24 ? `${r}h ago` : i < 7 ? `${i}d ago` : new Date(e).toLocaleDateString();
2499
+ }
2500
+ function Vt({ onNewChat: e, onThreadSelect: t }) {
2501
+ let [n, r] = l(!1), i = c(null), { data: a = [], isLoading: s } = Rt();
2502
+ o(() => {
2503
+ function e(e) {
2504
+ i.current && !i.current.contains(e.target) && r(!1);
2505
+ }
2506
+ if (n) return document.addEventListener("mousedown", e), () => {
2507
+ document.removeEventListener("mousedown", e);
2508
+ };
2509
+ }, [n]);
2510
+ function f(e) {
2511
+ r(!1), t?.(e);
2512
+ }
2513
+ return /* @__PURE__ */ d("div", {
2514
+ className: "flex items-center justify-between px-4 py-3 border-b border-gray-200",
2515
+ children: [/* @__PURE__ */ u("h2", {
2516
+ className: "text-lg font-semibold text-gray-900",
2517
+ children: "Erica Assistant"
2518
+ }), /* @__PURE__ */ d("div", {
2519
+ className: "flex items-center gap-2 relative",
2520
+ ref: i,
2521
+ children: [
2522
+ /* @__PURE__ */ u("button", {
2523
+ onClick: e,
2524
+ className: "p-2 bg-gray-900 hover:bg-gray-700 text-white rounded-lg transition-colors",
2525
+ title: "Start new chat",
2526
+ children: /* @__PURE__ */ u(tt, { className: "w-4 h-4" })
2527
+ }),
2528
+ /* @__PURE__ */ d("button", {
2529
+ onClick: () => r(!n),
2530
+ className: "flex items-center gap-1.5 px-3 py-2 hover:bg-gray-100 rounded-lg transition-colors",
2531
+ title: "Recent threads",
2532
+ children: [/* @__PURE__ */ d("span", {
2533
+ className: "text-sm font-medium text-gray-700",
2534
+ children: ["Threads ", a.length > 0 && `(${a.length})`]
2535
+ }), /* @__PURE__ */ u($e, { className: `w-4 h-4 text-gray-500 transition-transform ${n ? "rotate-180" : ""}` })]
2536
+ }),
2537
+ n && /* @__PURE__ */ u("div", {
2538
+ className: "absolute top-full right-0 mt-1 w-72 bg-white rounded-lg shadow-lg border border-gray-200 z-50 max-h-80 overflow-y-auto",
2539
+ children: /* @__PURE__ */ d("div", {
2540
+ className: "p-2",
2541
+ children: [
2542
+ /* @__PURE__ */ u("div", {
2543
+ className: "px-3 py-2 text-xs font-semibold text-gray-500 uppercase",
2544
+ children: "Recent Threads"
2545
+ }),
2546
+ s && /* @__PURE__ */ u("div", {
2547
+ className: "px-3 py-4 text-center text-sm text-gray-500",
2548
+ children: "Loading threads..."
2549
+ }),
2550
+ !s && a.length === 0 && /* @__PURE__ */ u("div", {
2551
+ className: "px-3 py-4 text-center text-sm text-gray-500",
2552
+ children: "No conversations yet"
2553
+ }),
2554
+ !s && a.map((e) => {
2555
+ let t = zt(e.agent), n = Bt(e.last_run_at ?? e.created_at);
2556
+ return /* @__PURE__ */ u("button", {
2557
+ onClick: () => f(e.uid),
2558
+ className: "w-full text-left px-3 py-2 hover:bg-gray-100 rounded-lg transition-colors",
2559
+ children: /* @__PURE__ */ d("div", {
2560
+ className: "flex flex-col gap-1",
2561
+ children: [/* @__PURE__ */ u("span", {
2562
+ className: "text-sm font-medium text-gray-900 truncate",
2563
+ children: typeof e.thread_metadata?.title == "string" ? e.thread_metadata.title : e.last_message ?? "New conversation"
2564
+ }), /* @__PURE__ */ d("div", {
2565
+ className: "flex items-center justify-between gap-2",
2566
+ children: [t && /* @__PURE__ */ u("span", {
2567
+ className: "text-xs text-gray-500 truncate flex-1",
2568
+ children: t
2569
+ }), n && /* @__PURE__ */ u("span", {
2570
+ className: "text-xs text-gray-400 shrink-0",
2571
+ children: n
2572
+ })]
2573
+ })]
2574
+ })
2575
+ }, e.uid);
2576
+ })
2577
+ ]
2578
+ })
2579
+ })
2580
+ ]
2581
+ })]
2582
+ });
2583
+ }
2584
+ //#endregion
2585
+ //#region src/components/EricaChat.tsx
2586
+ var Ht = new Oe({ defaultOptions: { queries: {
2587
+ refetchOnWindowFocus: !1,
2588
+ retry: 1,
2589
+ staleTime: 3e4
2590
+ } } });
2591
+ function Ut({ runtimeUrl: e, widgetToken: t }) {
2592
+ let [n, r] = l(void 0), a = s(() => {
2593
+ let t = new URL(e), n = t.pathname.split("/").filter(Boolean);
2594
+ return n.length > 2 && n.pop(), t.pathname = "/" + n.join("/"), t.toString();
2595
+ }, [e]);
2596
+ s(() => {
2597
+ kt(a, t);
2598
+ }, [a, t]);
2599
+ let o = i(() => {
2600
+ r(void 0), console.log("New chat started");
2601
+ }, []), c = i((e) => {
2602
+ r(e), console.log("Thread selected:", e);
2603
+ }, []), d = i((e) => /* @__PURE__ */ u(Ft, {
2604
+ ...e,
2605
+ threadId: n
2606
+ }), [n]), m = i(() => /* @__PURE__ */ u(Vt, {
2607
+ onNewChat: o,
2608
+ onThreadSelect: c
2609
+ }), [o, c]);
2610
+ return /* @__PURE__ */ u(Ae, {
2611
+ client: Ht,
2612
+ children: /* @__PURE__ */ u("div", {
2613
+ className: "h-full w-full",
2614
+ children: /* @__PURE__ */ u(f, {
2615
+ runtimeUrl: e,
2616
+ headers: { Authorization: `Bearer ${t}` },
2617
+ properties: { agent: "platform:ultimate" },
2618
+ threadId: n,
2619
+ children: /* @__PURE__ */ u(p, {
2620
+ labels: { initial: "Hi! How can I help you today?\n\nYou can:\n- Ask me questions\n- Upload files using the attachment icon\n- Drag & drop files to attach" },
2621
+ defaultOpen: !0,
2622
+ clickOutsideToClose: !0,
2623
+ Input: d,
2624
+ Header: m
2625
+ })
2626
+ })
2627
+ })
2628
+ });
2629
+ }
2630
+ //#endregion
2631
+ export { Ut as EricaChat };
2632
+
2633
+ //# sourceMappingURL=index.mjs.map