@versini/sassysaint 4.2.0 → 4.3.1

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