@versini/sassysaint 4.0.5 → 4.2.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.
@@ -0,0 +1,570 @@
1
+ import { jsxs as S, jsx as t, Fragment as K } from "react/jsx-runtime";
2
+ import { O as le, s as ce, S as ie, isLastMessageFromRole as Z, x as ee, CANCEL as de, CLEAR as ue, ACTION_RESET as se, ROLE_ASSISTANT as N, ROLE_INTERNAL as B, ROLE_USER as H, qr as z, ROLE_SYSTEM as me, ROLE_HIDDEN as pe, MODEL_GPT4 as re, STATS_SEPARATOR as P, ACTION_MODEL as te, ACTION_MESSAGE as v, TYPE_QUESTION as ge, SEND as ye, ACTION_STREAMING as oe, ERROR_MESSAGE as fe, getMessageContaintWrapperClass as he, MessagesContainerHeader as Ce, ACTION_SEARCH as Te, ACTION_SORT as Se, ACTION_RESTORE as Ee, ACTION_LOCATION as b, getCurrentGeoLocation as xe, c as Ae, AppFooter as Ne, LOCAL_STORAGE_PREFIX as M, LOCAL_STORAGE_SEARCH as Oe, LOCAL_STORAGE_SORT as Re, LOCAL_STORAGE_LOCATION as be } from "./index.BvXbpfqe.js";
3
+ import { g as ne, AppContext as _, restCall as ve, kt as ke, E as D, serviceCall as j, SERVICE_TYPES as q, HistoryContext as Le, k as Ie } from "./useLocalStorage.DJIqD2i3.js";
4
+ import { useState as U, useEffect as T, useContext as $, useRef as E, lazy as _e, Suspense as Y, useReducer as J, useCallback as we } from "react";
5
+ import O from "clsx";
6
+ const Me = ({
7
+ className: e,
8
+ viewBox: s,
9
+ spacing: n,
10
+ title: r,
11
+ monotone: a,
12
+ ...o
13
+ }) => /* @__PURE__ */ S(
14
+ ne,
15
+ {
16
+ defaultViewBox: "0 0 448 512",
17
+ defaultClassName: "size-5",
18
+ viewBox: s,
19
+ className: e,
20
+ spacing: n,
21
+ title: r || "Copied",
22
+ ...o,
23
+ children: [
24
+ /* @__PURE__ */ t(
25
+ "path",
26
+ {
27
+ opacity: "0.4",
28
+ d: "M64 32C28.7 32 0 60.7 0 96V416c0 35.3 28.7 64 64 64H384c35.3 0 64-28.7 64-64V96c0-35.3-28.7-64-64-64H64zM337 209L209 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L303 175c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9z"
29
+ }
30
+ ),
31
+ /* @__PURE__ */ t("path", { d: "M337 175c9.4 9.4 9.4 24.6 0 33.9L209 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L303 175c9.4-9.4 24.6-9.4 33.9 0z" })
32
+ ]
33
+ }
34
+ ), De = ({
35
+ className: e,
36
+ viewBox: s,
37
+ spacing: n,
38
+ title: r,
39
+ monotone: a,
40
+ ...o
41
+ }) => /* @__PURE__ */ t(
42
+ ne,
43
+ {
44
+ defaultViewBox: "0 0 512 512",
45
+ defaultClassName: "size-5",
46
+ viewBox: s,
47
+ className: e,
48
+ spacing: n,
49
+ title: r || "Copy",
50
+ ...o,
51
+ children: /* @__PURE__ */ t("path", { d: "M64 464H288c8.8 0 16-7.2 16-16V384h48v64c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V224c0-35.3 28.7-64 64-64h64v48H64c-8.8 0-16 7.2-16 16V448c0 8.8 7.2 16 16 16zM224 304H448c8.8 0 16-7.2 16-16V64c0-8.8-7.2-16-16-16H224c-8.8 0-16 7.2-16 16V288c0 8.8 7.2 16 16 16zm-64-16V64c0-35.3 28.7-64 64-64H448c35.3 0 64 28.7 64 64V288c0 35.3-28.7 64-64 64H224c-35.3 0-64-28.7-64-64z" })
52
+ }
53
+ ), Ve = () => "p-4 sm:max-w-md md:max-w-2xl", He = ({ kind: e }) => O({
54
+ "bg-surface-lighter dark:bg-surface-dark": e === "left",
55
+ "bg-surface-accent": e === "right"
56
+ }), Be = ({ kind: e }) => O(
57
+ "prose prose-dark dark:prose-lighter prose-p:my-3 prose-blockquote:my-3 prose-ol:my-3 prose-ul:my-3 prose-ul:prose-li:marker:text-black",
58
+ {
59
+ "text-copy-lighter": e === "right"
60
+ }
61
+ ), ze = ({ kind: e }) => O("rounded-b-xl", {
62
+ "rounded-tr-xl": e === "left",
63
+ "rounded-tl-xl": e === "right"
64
+ }), Ue = ({
65
+ kind: e,
66
+ className: s,
67
+ spacing: n
68
+ }) => {
69
+ const r = O(
70
+ s,
71
+ ce,
72
+ "flex items-start",
73
+ ie(n),
74
+ {
75
+ "flex-row-reverse": e === "right"
76
+ }
77
+ ), a = O(
78
+ "flex flex-col empty:hidden",
79
+ Ve(),
80
+ Be({ kind: e }),
81
+ He({ kind: e }),
82
+ ze({ kind: e })
83
+ ), o = "pr-2 pt-1 text-end text-xs text-copy-light", i = O("flex flex-col-reverse gap-2 sm:flex-row", {
84
+ "ml-2": e === "left",
85
+ "mr-2": e === "right"
86
+ });
87
+ return {
88
+ wrapper: r,
89
+ main: a,
90
+ footer: o,
91
+ copyButton: i
92
+ };
93
+ }, $e = ({
94
+ children: e,
95
+ kind: s = "left",
96
+ className: n,
97
+ footer: r,
98
+ rawFooter: a,
99
+ copyToClipboard: o,
100
+ copyToClipboardFocusMode: i = "system",
101
+ copyToClipboardMode: f = "system",
102
+ spacing: c
103
+ }) => {
104
+ const [g, l] = U(!1), p = Ue({ kind: s, className: n, spacing: c }), h = !!o && (typeof o == "function" || typeof o == "string" || typeof e == "string"), A = () => {
105
+ l(!0), typeof o == "function" ? o(e) : typeof o == "string" ? navigator.clipboard.writeText(o) : typeof e == "string" && navigator.clipboard.writeText(e);
106
+ };
107
+ return T(() => {
108
+ let y;
109
+ return g && (y = window.setTimeout(() => {
110
+ l(!1);
111
+ }, 3e3)), () => {
112
+ clearTimeout(y);
113
+ };
114
+ }, [g]), /* @__PURE__ */ S("div", { className: p.wrapper, children: [
115
+ /* @__PURE__ */ S("div", { children: [
116
+ /* @__PURE__ */ t("div", { className: p.main, children: e }),
117
+ r && Object.keys(r).map((y) => r[y] ? /* @__PURE__ */ t("div", { className: "prose-p:m-0", children: /* @__PURE__ */ S("p", { className: p.footer, children: [
118
+ y,
119
+ ": ",
120
+ r[y]
121
+ ] }) }, `-${y}`) : null),
122
+ a && a
123
+ ] }),
124
+ h && /* @__PURE__ */ t("div", { className: p.copyButton, children: /* @__PURE__ */ t(
125
+ le,
126
+ {
127
+ noBorder: !0,
128
+ noBackground: !0,
129
+ size: "small",
130
+ mode: f,
131
+ focusMode: i,
132
+ label: g ? "Copied to clipboard" : "Copy to clipboard",
133
+ onClick: A,
134
+ disabled: g,
135
+ children: g ? /* @__PURE__ */ t(Me, { className: "size-3" }) : /* @__PURE__ */ t(De, { className: "size-3" })
136
+ }
137
+ ) })
138
+ ] });
139
+ };
140
+ var m = [];
141
+ for (var V = 0; V < 256; ++V)
142
+ m.push((V + 256).toString(16).slice(1));
143
+ function Fe(e, s = 0) {
144
+ return (m[e[s + 0]] + m[e[s + 1]] + m[e[s + 2]] + m[e[s + 3]] + "-" + m[e[s + 4]] + m[e[s + 5]] + "-" + m[e[s + 6]] + m[e[s + 7]] + "-" + m[e[s + 8]] + m[e[s + 9]] + "-" + m[e[s + 10]] + m[e[s + 11]] + m[e[s + 12]] + m[e[s + 13]] + m[e[s + 14]] + m[e[s + 15]]).toLowerCase();
145
+ }
146
+ var L, Ge = new Uint8Array(16);
147
+ function Pe() {
148
+ if (!L && (L = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !L))
149
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
150
+ return L(Ge);
151
+ }
152
+ var je = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
153
+ const Q = {
154
+ randomUUID: je
155
+ };
156
+ function F(e, s, n) {
157
+ if (Q.randomUUID && !s && !e)
158
+ return Q.randomUUID();
159
+ e = e || {};
160
+ var r = e.random || (e.rng || Pe)();
161
+ return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, Fe(r);
162
+ }
163
+ const qe = () => {
164
+ const { dispatch: e, state: s } = $(_), n = "mt-2 flex justify-center rounded-md", r = E(null), a = E(!1), o = (i) => {
165
+ i.preventDefault(), e({
166
+ type: se
167
+ });
168
+ };
169
+ return T(() => {
170
+ (s == null ? void 0 : s.streaming) === !0 && !a.current && r.current && (a.current = !0, r.current.focus()), (s == null ? void 0 : s.streaming) === !1 && (a.current = !1);
171
+ }, [s]), Z(N, s) ? /* @__PURE__ */ t("div", { className: n, children: /* @__PURE__ */ t(
172
+ ee,
173
+ {
174
+ ref: r,
175
+ noBorder: !0,
176
+ onClick: o,
177
+ mode: "dark",
178
+ focusMode: "light",
179
+ children: s != null && s.streaming ? de : ue
180
+ }
181
+ ) }) : null;
182
+ }, W = _e(() => import("./LazyMessageAssistant.Brog9qTL.js").then((e) => e.LazyMessageAssistant)), Ye = () => {
183
+ const { state: e } = $(_);
184
+ return /* @__PURE__ */ S(K, { children: [
185
+ e && e.messages.length > 0 && e.messages.map((s, n) => {
186
+ const { role: r, content: a, name: o, processingTime: i } = s.message;
187
+ return (r === N || r === B) && a ? /* @__PURE__ */ t(Y, { fallback: /* @__PURE__ */ t("span", {}), children: /* @__PURE__ */ t(
188
+ W,
189
+ {
190
+ name: o,
191
+ processingTime: i,
192
+ children: a
193
+ }
194
+ ) }, `${n}-${r}`) : r === H && a ? /* @__PURE__ */ t(
195
+ $e,
196
+ {
197
+ kind: "right",
198
+ copyToClipboard: a,
199
+ copyToClipboardFocusMode: "light",
200
+ children: a
201
+ },
202
+ `${n}-${r}`
203
+ ) : null;
204
+ }),
205
+ Z(H, e) && /* @__PURE__ */ t(Y, { fallback: /* @__PURE__ */ t("span", {}), children: /* @__PURE__ */ t(W, { loading: !0 }) })
206
+ ] });
207
+ }, I = (e, s) => {
208
+ e({
209
+ type: oe,
210
+ payload: {
211
+ streaming: s
212
+ }
213
+ });
214
+ }, X = (e) => {
215
+ I(e, !1), e({
216
+ type: v,
217
+ payload: {
218
+ message: {
219
+ role: B,
220
+ content: fe
221
+ }
222
+ }
223
+ });
224
+ }, Je = () => {
225
+ const { state: e, dispatch: s } = $(_), [n, r] = U(""), { getAccessToken: a, user: o } = z(), i = E(!1), f = E(null), c = E(
226
+ null
227
+ );
228
+ T(() => {
229
+ (async () => {
230
+ var p;
231
+ if (!e || e.messages.length === 0) {
232
+ (p = c == null ? void 0 : c.current) == null || p.cancel();
233
+ return;
234
+ }
235
+ const l = e.messages[e.messages.length - 1];
236
+ if (!(e.messages.length === 0 || l.message.role === N || l.message.role === me || l.message.role === B || l.message.role === pe))
237
+ try {
238
+ const h = await ve({
239
+ accessToken: await a(),
240
+ name: "generate",
241
+ data: {
242
+ messages: e.messages,
243
+ model: re,
244
+ user: (o == null ? void 0 : o.username) || "",
245
+ id: e.id,
246
+ location: e.location,
247
+ usage: e.usage
248
+ }
249
+ });
250
+ if (h && h.ok) {
251
+ const A = F();
252
+ c.current = h.body.getReader();
253
+ const y = new TextDecoder();
254
+ for (; ; ) {
255
+ I(s, !0);
256
+ const { done: w, value: R } = await c.current.read();
257
+ if (w) {
258
+ I(s, !1);
259
+ break;
260
+ }
261
+ const d = y.decode(R, { stream: !0 }), C = d.indexOf(P);
262
+ if (C !== -1) {
263
+ const k = d.substring(0, C), x = JSON.parse(
264
+ d.substring(C + P.length)
265
+ );
266
+ s({
267
+ type: te,
268
+ payload: {
269
+ model: x.model,
270
+ usage: x.usage
271
+ }
272
+ }), s({
273
+ type: v,
274
+ payload: {
275
+ message: {
276
+ content: k,
277
+ role: N,
278
+ messageId: A,
279
+ processingTime: x.processingTime,
280
+ name: x.name
281
+ }
282
+ }
283
+ }), I(s, !1);
284
+ break;
285
+ } else
286
+ s({
287
+ type: v,
288
+ payload: {
289
+ message: {
290
+ content: d,
291
+ role: N,
292
+ messageId: A
293
+ }
294
+ }
295
+ });
296
+ }
297
+ } else
298
+ X(s);
299
+ } catch (h) {
300
+ console.error(h), X(s);
301
+ }
302
+ })();
303
+ }, [e == null ? void 0 : e.messages]);
304
+ const g = async (l) => {
305
+ l.preventDefault(), s({
306
+ type: v,
307
+ payload: {
308
+ message: {
309
+ role: H,
310
+ content: n
311
+ }
312
+ }
313
+ }), r("");
314
+ };
315
+ return T(() => {
316
+ (e == null ? void 0 : e.streaming) === !1 && !i.current && f.current && (i.current = !0, f.current.focus()), (e == null ? void 0 : e.streaming) === !0 && i.current === !0 && (i.current = !1);
317
+ }, [e]), /* @__PURE__ */ t("form", { className: "mt-2", onSubmit: g, children: /* @__PURE__ */ t(
318
+ ke,
319
+ {
320
+ mode: "dark",
321
+ focusMode: "light",
322
+ ref: f,
323
+ name: "chat-input",
324
+ label: ge,
325
+ helperText: "Press ENTER to add a new line",
326
+ helperTextOnFocus: !0,
327
+ required: !0,
328
+ value: n,
329
+ onChange: (l) => r(l.target.value),
330
+ rightElement: /* @__PURE__ */ t(
331
+ ee,
332
+ {
333
+ disabled: e == null ? void 0 : e.streaming,
334
+ noBorder: !0,
335
+ type: "submit",
336
+ mode: "light",
337
+ focusMode: "light",
338
+ children: ye
339
+ }
340
+ )
341
+ }
342
+ ) });
343
+ }, Qe = () => {
344
+ const { isAuthenticated: e } = z(), s = he(e);
345
+ return /* @__PURE__ */ S(K, { children: [
346
+ /* @__PURE__ */ S("div", { className: s, children: [
347
+ /* @__PURE__ */ t(Ce, {}),
348
+ /* @__PURE__ */ t(Ye, {})
349
+ ] }),
350
+ /* @__PURE__ */ t(qe, {}),
351
+ /* @__PURE__ */ t(Je, {})
352
+ ] });
353
+ }, We = (e, s) => (s == null ? void 0 : s.type) === Te ? {
354
+ searchString: s.payload.searchString,
355
+ sortedCell: e.sortedCell,
356
+ sortDirection: e.sortDirection
357
+ } : (s == null ? void 0 : s.type) === Se ? {
358
+ searchString: e.searchString,
359
+ sortedCell: s.payload.sortedCell,
360
+ sortDirection: s.payload.sortDirection
361
+ } : e, Xe = (e, s) => {
362
+ if ((s == null ? void 0 : s.type) === Ee) {
363
+ const n = s.payload.messages.map((r) => ({
364
+ message: {
365
+ role: r.role,
366
+ content: r.content,
367
+ name: r.name,
368
+ processingTime: r.processingTime
369
+ }
370
+ }));
371
+ return {
372
+ id: s.payload.id,
373
+ model: s.payload.model,
374
+ usage: s.payload.usage,
375
+ location: e.location,
376
+ isComponent: e.isComponent,
377
+ messages: n
378
+ };
379
+ }
380
+ if ((s == null ? void 0 : s.type) === v) {
381
+ const n = s.payload.message.role, r = s.payload.message.content, a = s.payload.message.name, o = s.payload.message.processingTime, i = s.payload.message.messageId;
382
+ if (n !== "") {
383
+ const f = {
384
+ role: n,
385
+ content: r,
386
+ name: a,
387
+ processingTime: o,
388
+ messageId: i
389
+ };
390
+ if (n === N) {
391
+ const c = e.messages.findIndex(
392
+ (g) => g.message.messageId === i
393
+ );
394
+ if (c !== -1) {
395
+ const g = e.messages.map((l, p) => p === c ? {
396
+ message: {
397
+ ...l.message,
398
+ content: `${l.message.content}${r}`,
399
+ processingTime: o,
400
+ name: a
401
+ }
402
+ } : l);
403
+ return {
404
+ id: e.id,
405
+ model: e.model,
406
+ usage: e.usage,
407
+ location: e.location,
408
+ isComponent: e.isComponent,
409
+ messages: g
410
+ };
411
+ }
412
+ }
413
+ return {
414
+ id: e.id,
415
+ model: e.model,
416
+ usage: e.usage,
417
+ location: e.location,
418
+ isComponent: e.isComponent,
419
+ messages: [
420
+ ...e.messages,
421
+ {
422
+ message: f
423
+ }
424
+ ]
425
+ };
426
+ }
427
+ }
428
+ return (s == null ? void 0 : s.type) === se ? {
429
+ id: F(),
430
+ model: e.model,
431
+ usage: 0,
432
+ messages: [],
433
+ location: e.location,
434
+ isComponent: e.isComponent
435
+ } : (s == null ? void 0 : s.type) === te ? {
436
+ id: e.id,
437
+ model: s.payload.model,
438
+ usage: s.payload.usage,
439
+ messages: e.messages,
440
+ location: e.location,
441
+ isComponent: e.isComponent
442
+ } : (s == null ? void 0 : s.type) === b ? {
443
+ id: e.id,
444
+ model: e.model,
445
+ usage: e.usage,
446
+ messages: e.messages,
447
+ location: s.payload.location,
448
+ isComponent: e.isComponent
449
+ } : (s == null ? void 0 : s.type) === oe ? {
450
+ ...e,
451
+ streaming: s.payload.streaming
452
+ } : e;
453
+ };
454
+ function ae({ isComponent: e = !1 }) {
455
+ const s = E(!1), n = E(!1), r = E(!1), { isAuthenticated: a, getAccessToken: o } = z(), [i] = D({
456
+ key: M + Oe,
457
+ initialValue: ""
458
+ }), [f] = D({
459
+ key: M + Re,
460
+ initialValue: Ie.ASC
461
+ }), [c, g] = D({
462
+ key: M + be,
463
+ initialValue: { latitude: 0, longitude: 0, accuracy: 0 }
464
+ }), [l, p] = J(Xe, {
465
+ id: F(),
466
+ model: re,
467
+ usage: 0,
468
+ messages: [],
469
+ isComponent: e
470
+ }), [h, A] = J(We, {
471
+ searchString: i,
472
+ sortedCell: "timestamp",
473
+ sortDirection: f
474
+ }), [y, w] = U({
475
+ version: "",
476
+ models: [],
477
+ plugins: []
478
+ }), R = we(() => {
479
+ p({
480
+ type: b,
481
+ payload: {
482
+ location: {
483
+ ...c,
484
+ city: "N/A"
485
+ }
486
+ }
487
+ });
488
+ }, [c]);
489
+ return T(() => {
490
+ y.version !== "" || r.current || (async () => {
491
+ try {
492
+ r.current = !0;
493
+ const d = await j({
494
+ accessToken: await o(),
495
+ type: q.ABOUT
496
+ });
497
+ r.current = !1, d.status === 200 && w(d.data);
498
+ } catch {
499
+ }
500
+ })();
501
+ }, [y, o]), T(() => {
502
+ a && (s.current || ((!c || c.accuracy === 0) && (s.current = !0, (async () => {
503
+ const d = await xe();
504
+ g(d), p({
505
+ type: b,
506
+ payload: {
507
+ location: d
508
+ }
509
+ });
510
+ })()), c && c.accuracy !== 0 && !l.location && p({
511
+ type: b,
512
+ payload: {
513
+ location: c
514
+ }
515
+ })));
516
+ }, [a, c, g, l.location]), T(() => {
517
+ !l.location || l.location.accuracy === 0 || l.location.city || l.location.displayName || n.current || (async () => {
518
+ var d, C, k, x, G;
519
+ n.current = !0;
520
+ try {
521
+ const u = await j({
522
+ accessToken: await o(),
523
+ type: q.GET_LOCATION,
524
+ params: {
525
+ latitude: c.latitude,
526
+ longitude: c.longitude
527
+ }
528
+ });
529
+ n.current = !1, u.status !== 200 || ((d = u == null ? void 0 : u.errors) == null ? void 0 : d.length) > 0 ? R() : p({
530
+ type: b,
531
+ payload: {
532
+ location: {
533
+ ...c,
534
+ country: (C = u == null ? void 0 : u.data) == null ? void 0 : C.country,
535
+ state: (k = u == null ? void 0 : u.data) == null ? void 0 : k.state,
536
+ city: ((x = u == null ? void 0 : u.data) == null ? void 0 : x.city) || "N/A",
537
+ displayName: (G = u == null ? void 0 : u.data) == null ? void 0 : G.displayName
538
+ }
539
+ }
540
+ });
541
+ } catch {
542
+ R();
543
+ }
544
+ })();
545
+ }, [l, c, o, R]), T(() => {
546
+ var d;
547
+ (d = document.getElementById("logo")) == null || d.classList.add("fadeOut"), setTimeout(() => {
548
+ var C;
549
+ (C = document.getElementById("root")) == null || C.classList.replace("app-hidden", "fadeIn");
550
+ }, 500);
551
+ }), /* @__PURE__ */ t(_.Provider, { value: { state: l, dispatch: p, serverStats: y }, children: /* @__PURE__ */ S(
552
+ Le.Provider,
553
+ {
554
+ value: {
555
+ state: h,
556
+ dispatch: A
557
+ },
558
+ children: [
559
+ /* @__PURE__ */ t(Ae, { children: /* @__PURE__ */ t(Qe, {}) }),
560
+ /* @__PURE__ */ t(Ne, { serverStats: y })
561
+ ]
562
+ }
563
+ ) });
564
+ }
565
+ ae.displayName = "App";
566
+ const ts = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, default: ae }, Symbol.toStringTag, { value: "Module" }));
567
+ export {
568
+ ts as App,
569
+ $e as T
570
+ };