@sveda-ai/svelte 0.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.
- package/LICENSE +557 -0
- package/README.md +18 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +1138 -0
- package/dist/styles.css +3 -0
- package/package.json +73 -0
- package/src/app.d.ts +7 -0
- package/src/appearance.ts +66 -0
- package/src/components/ChatHistoryList.svelte +134 -0
- package/src/components/SvedaChat.svelte +689 -0
- package/src/components/SvedaProvider.svelte +29 -0
- package/src/context.ts +50 -0
- package/src/hooks/useSvedaChat.svelte.ts +120 -0
- package/src/hooks/useSvedaChatLayout.svelte.ts +308 -0
- package/src/hooks/useSvedaStreaming.svelte.ts +117 -0
- package/src/i18n.ts +51 -0
- package/src/index.ts +106 -0
- package/src/lib/utils.ts +6 -0
- package/src/markdown.css +96 -0
- package/src/provider.ts +173 -0
- package/src/styles.css +6 -0
- package/src/theme.css +137 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1138 @@
|
|
|
1
|
+
import { SvedaClient as wt } from "@sveda-ai/core";
|
|
2
|
+
export * from "@sveda-ai/core";
|
|
3
|
+
import { sanitizeSvedaLauncher as rt, sanitizeSvedaChrome as at, resolveSvedaAppearance as yt, applySvedaAppearance as Ct, ruMessages as St, enMessages as Mt, chatComponentI18nKeys as Tt, mergeSvedaAppearance as kt, getUserMessageText as it, SVEDA_CHAT_LAYOUT_MIN_HEIGHT as Et, SVEDA_CHAT_LAYOUT_MAX_HEIGHT as At, SVEDA_CHAT_LAYOUT_MIN_WIDTH as st, SVEDA_CHAT_LAYOUT_MAX_WIDTH as It, pointerScreenDelta as Ht, applyFixedLeftResize as zt, applyFloatingResize as Dt, getSvedaChatStore as Lt, createSvedaStreaming as Pt, userMessageHasVisibleContent as Je, buildChatTabTitleMap as Nt, renderMarkdown as Rt } from "@sveda-ai/chat";
|
|
4
|
+
import { SVEDA_APPEARANCE_PRESETS as Sa, SVEDA_APPEARANCE_PRESET_IDS as Ma, SVEDA_APPEARANCE_STYLE_ID as Ta, SVEDA_CHAT_MINIMIZED_STORAGE_KEY as ka, SVEDA_DEFAULT_LAUNCHER_ICON as Ea, SVEDA_LAUNCHER_ICON_IDS as Aa, SVEDA_LAUNCHER_IMAGE_MAX_BYTES as Ia, SVEDA_LAUNCHER_IMAGE_MAX_CHARS as Ha, SVEDA_TOKEN_KEYS as za, buildAppearanceCss as Da, buildChatTabTitleMap as La, deriveProvisionalChatTitle as Pa, finalizeMessagesForDisplay as Na, formatRadiusPx as Ra, getSvedaModelDisplayName as Oa, getUserMessageAttachmentNames as Fa, getUserMessageText as Ua, hexToHsl as Va, hslToHex as ja, humanizeModelId as Ba, isChatTitlePlaceholder as Ya, isNewChatPlaceholder as Wa, isPersistedSessionChatOpen as Xa, isSvedaAppearanceProvided as Ga, isSvedaHsl as qa, mergeSvedaAppearance as Ka, parseRadiusPx as Ja, readPersistedMinimized as Qa, readPersistedMinimizedPreference as Za, resolveSvedaAppearance as $a, sanitizeSvedaChrome as ei, sanitizeSvedaLauncher as ti, sanitizeSvedaLauncherImage as ri, sanitizeSvedaRadius as ai, sanitizeSvedaTheme as ii, userMessageHasVisibleContent as si, writePersistedMinimized as ni } from "@sveda-ai/chat";
|
|
5
|
+
import { getContext as Ot, setContext as Ft, untrack as Ut, onDestroy as Vt, onMount as jt, tick as Re } from "svelte";
|
|
6
|
+
import "svelte/internal/disclose-version";
|
|
7
|
+
import * as e from "svelte/internal/client";
|
|
8
|
+
import { Search as Bt, SquarePen as Yt, Trash2 as Wt, Plus as Qe, MessageCircle as Xt, X as Ze, History as Gt, Minimize2 as qt, Maximize2 as Kt, Square as Jt, Send as Qt, Sparkles as Zt, PanelRight as $t, MessageSquare as er } from "lucide-svelte";
|
|
9
|
+
import { clsx as tr } from "clsx";
|
|
10
|
+
import { twMerge as rr } from "tailwind-merge";
|
|
11
|
+
const Ee = rt(null), ar = () => Ee, Be = at(null), ga = () => Be, Ye = (t) => {
|
|
12
|
+
const i = yt(t), s = rt(i == null ? void 0 : i.launcher);
|
|
13
|
+
Ee.label = s.label, Ee.icon = s.icon, Ee.image = s.image;
|
|
14
|
+
const g = at(i == null ? void 0 : i.chrome);
|
|
15
|
+
Be.modelSelect = g.modelSelect, Be.thinking = g.thinking, Ct(t);
|
|
16
|
+
};
|
|
17
|
+
function ir(t = {}) {
|
|
18
|
+
let i = t.locale ?? "en";
|
|
19
|
+
const s = t.fallbackLocale ?? "en", g = { ...t.messages ?? {} }, m = (M, S) => S ? M.replace(
|
|
20
|
+
/\{(\w+)\}/g,
|
|
21
|
+
(I, y) => S[y] === void 0 || S[y] === null ? I : String(S[y])
|
|
22
|
+
) : M;
|
|
23
|
+
return {
|
|
24
|
+
get locale() {
|
|
25
|
+
return i;
|
|
26
|
+
},
|
|
27
|
+
t(M, S) {
|
|
28
|
+
var y, o;
|
|
29
|
+
const I = ((y = g[i]) == null ? void 0 : y[M]) ?? ((o = g[s]) == null ? void 0 : o[M]);
|
|
30
|
+
return I === void 0 ? M : m(I, S);
|
|
31
|
+
},
|
|
32
|
+
setLocale(M) {
|
|
33
|
+
i = M;
|
|
34
|
+
},
|
|
35
|
+
extend(M, S) {
|
|
36
|
+
g[M] = { ...g[M] ?? {}, ...S };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const nt = "sveda", sr = "sveda-embed-auth", nr = {
|
|
41
|
+
brand: { name: "Sveda", logoUrl: null },
|
|
42
|
+
models: [],
|
|
43
|
+
quickPrompts: []
|
|
44
|
+
}, or = (t) => {
|
|
45
|
+
if (typeof fetch > "u")
|
|
46
|
+
return;
|
|
47
|
+
let i = "";
|
|
48
|
+
try {
|
|
49
|
+
const s = new URL(t);
|
|
50
|
+
if (s.protocol !== "http:" && s.protocol !== "https:")
|
|
51
|
+
return;
|
|
52
|
+
i = s.origin;
|
|
53
|
+
} catch {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
fetch(`${i}/sveda/embed/config`).then((s) => s.ok ? s.json() : null).then((s) => {
|
|
57
|
+
!s || typeof s != "object" || Ye(
|
|
58
|
+
kt(s.appearance, void 0)
|
|
59
|
+
);
|
|
60
|
+
}).catch(() => {
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
function ot(t) {
|
|
64
|
+
var S, I;
|
|
65
|
+
const i = new wt({
|
|
66
|
+
endpoints: t.endpoints,
|
|
67
|
+
protocolMode: t.protocolMode,
|
|
68
|
+
headers: t.headers,
|
|
69
|
+
credentials: t.credentials
|
|
70
|
+
}), s = {}, g = (y, o) => {
|
|
71
|
+
s[y] = { ...s[y] ?? {}, ...o };
|
|
72
|
+
};
|
|
73
|
+
for (const [y, o] of Object.entries({ en: Mt, ru: St }))
|
|
74
|
+
g(y, o);
|
|
75
|
+
for (const [y, o] of Object.entries(Tt))
|
|
76
|
+
g(y, o);
|
|
77
|
+
for (const [y, o] of Object.entries(t.messages ?? {}))
|
|
78
|
+
g(y, o);
|
|
79
|
+
const m = ir({
|
|
80
|
+
locale: t.locale ?? "en",
|
|
81
|
+
messages: s
|
|
82
|
+
}), M = {
|
|
83
|
+
brand: {
|
|
84
|
+
name: ((S = t.brand) == null ? void 0 : S.name) ?? "Sveda",
|
|
85
|
+
logoUrl: ((I = t.brand) == null ? void 0 : I.logoUrl) ?? null
|
|
86
|
+
},
|
|
87
|
+
models: t.models ?? [],
|
|
88
|
+
quickPrompts: t.quickPrompts ?? []
|
|
89
|
+
};
|
|
90
|
+
return t.appearance !== void 0 || t.theme !== void 0 ? t.appearance === null && t.theme === void 0 ? Ye(null) : Ye({
|
|
91
|
+
...t.appearance && typeof t.appearance == "object" ? t.appearance : {},
|
|
92
|
+
...t.theme ? { theme: t.theme } : {}
|
|
93
|
+
}) : or(t.endpoints.stream), {
|
|
94
|
+
client: i,
|
|
95
|
+
i18n: m,
|
|
96
|
+
config: M,
|
|
97
|
+
hostEmbed: !!t.hostEmbed,
|
|
98
|
+
fillHost: !!(t.fillHost ?? t.hostEmbed),
|
|
99
|
+
hideLauncher: !!t.hideLauncher,
|
|
100
|
+
beforeSend: t.beforeSend ?? null
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function lr() {
|
|
104
|
+
return nr;
|
|
105
|
+
}
|
|
106
|
+
function lt(t) {
|
|
107
|
+
return Ft(nt, t), t;
|
|
108
|
+
}
|
|
109
|
+
function ma(t) {
|
|
110
|
+
return lt(ot(t));
|
|
111
|
+
}
|
|
112
|
+
function ge() {
|
|
113
|
+
const t = Ot(nt);
|
|
114
|
+
if (!t)
|
|
115
|
+
throw new Error(
|
|
116
|
+
"[sveda] Sveda context is missing. Wrap your tree in <SvedaProvider> or call setSvedaContext(createSveda(...))."
|
|
117
|
+
);
|
|
118
|
+
return t;
|
|
119
|
+
}
|
|
120
|
+
function pa() {
|
|
121
|
+
return ge().client;
|
|
122
|
+
}
|
|
123
|
+
function dr() {
|
|
124
|
+
try {
|
|
125
|
+
return ge().config;
|
|
126
|
+
} catch {
|
|
127
|
+
return lr();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function Ae() {
|
|
131
|
+
try {
|
|
132
|
+
const { i18n: t } = ge();
|
|
133
|
+
return (i, s) => t.t(i, s);
|
|
134
|
+
} catch {
|
|
135
|
+
return (t) => t;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function _a(t, i) {
|
|
139
|
+
e.push(i, !0);
|
|
140
|
+
const s = Ut(() => i.sveda ?? (i.options ? ot(i.options) : null));
|
|
141
|
+
if (!s)
|
|
142
|
+
throw new Error("[sveda] SvedaProvider requires either `sveda` or `options`.");
|
|
143
|
+
lt(s);
|
|
144
|
+
var g = e.comment(), m = e.first_child(g);
|
|
145
|
+
{
|
|
146
|
+
var M = (S) => {
|
|
147
|
+
var I = e.comment(), y = e.first_child(I);
|
|
148
|
+
e.snippet(y, () => i.children), e.append(S, I);
|
|
149
|
+
};
|
|
150
|
+
e.if(m, (S) => {
|
|
151
|
+
i.children && S(M);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
e.append(t, g), e.pop();
|
|
155
|
+
}
|
|
156
|
+
var cr = e.from_html('<div class="px-2 py-6 text-center text-sm text-muted-foreground"> </div>'), vr = e.from_html('<div role="button" tabindex="0"><div class="flex items-start justify-between gap-2"><div class="min-w-0 flex-1"><p class="truncate text-sm font-medium"> </p> <p class="truncate text-xs text-muted-foreground"> </p></div> <div class="flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100"><button type="button" class="inline-flex h-6 w-6 items-center justify-center"><!></button> <button type="button" class="inline-flex h-6 w-6 items-center justify-center"><!></button></div></div></div>'), hr = e.from_html('<div class="mb-3 last:mb-1"><p class="px-2 pb-1 text-xs font-medium uppercase tracking-wide text-muted-foreground"> </p> <!></div>'), fr = e.from_html('<div class="flex h-full min-h-0 w-full flex-col bg-background"><div class="shrink-0 border-b border-border p-3"><div class="mb-3 flex items-center justify-between"><p class="text-sm font-semibold"> </p></div> <div class="flex h-10 items-center gap-2 rounded-[var(--sveda-radius)] border border-border bg-input px-3"><!> <input type="text" autocomplete="off" class="h-full min-w-0 flex-1 border-0 bg-transparent p-0 text-sm text-card-foreground outline-none placeholder:text-muted-foreground"/></div></div> <div class="min-h-0 flex-1 overflow-y-auto p-2"><!></div></div>');
|
|
157
|
+
function ur(t, i) {
|
|
158
|
+
e.push(i, !0);
|
|
159
|
+
let s = e.prop(i, "currentChatId", 3, null);
|
|
160
|
+
const g = Ae();
|
|
161
|
+
let m = e.state("");
|
|
162
|
+
const M = (T) => {
|
|
163
|
+
var R;
|
|
164
|
+
if (typeof T.preview == "string" && T.preview.trim())
|
|
165
|
+
return T.preview.trim();
|
|
166
|
+
const V = (R = T.messages) == null ? void 0 : R.find((j) => j.role === "user");
|
|
167
|
+
return V ? it(V) : "";
|
|
168
|
+
}, S = (T) => {
|
|
169
|
+
const V = new Date(Number(T) || Date.now()), R = /* @__PURE__ */ new Date(), j = new Date(V.getFullYear(), V.getMonth(), V.getDate()).getTime(), Y = new Date(R.getFullYear(), R.getMonth(), R.getDate()).getTime();
|
|
170
|
+
return Math.max(0, Math.floor((Y - j) / 864e5));
|
|
171
|
+
}, I = e.derived(() => {
|
|
172
|
+
const T = e.get(m).trim().toLowerCase(), V = T ? i.histories.filter((Y) => {
|
|
173
|
+
const J = M(Y);
|
|
174
|
+
return Y.title.toLowerCase().includes(T) || J.toLowerCase().includes(T);
|
|
175
|
+
}) : i.histories, R = [], j = /* @__PURE__ */ new Map();
|
|
176
|
+
for (const Y of V) {
|
|
177
|
+
const J = S(Y.updatedAt), Q = J === 0 ? g("today") : J === 1 ? g("yesterday") : J === 2 ? g("dayBeforeYesterday") : g("daysAgo", { count: J }), se = j.get(Q);
|
|
178
|
+
se === void 0 ? (j.set(Q, R.length), R.push({ label: Q, chats: [Y] })) : R[se].chats.push(Y);
|
|
179
|
+
}
|
|
180
|
+
return R;
|
|
181
|
+
});
|
|
182
|
+
var y = fr(), o = e.child(y), v = e.child(o), le = e.child(v), l = e.only_child(le, !0);
|
|
183
|
+
e.reset(v);
|
|
184
|
+
var r = e.sibling(v, 2), h = e.child(r);
|
|
185
|
+
Bt(h, {
|
|
186
|
+
class: "h-4 w-4 shrink-0 text-muted-foreground",
|
|
187
|
+
"aria-hidden": "true"
|
|
188
|
+
});
|
|
189
|
+
var K = e.sibling(h, 2);
|
|
190
|
+
e.remove_input_defaults(K), e.reset(r), e.reset(o);
|
|
191
|
+
var ee = e.sibling(o, 2), re = e.child(ee);
|
|
192
|
+
{
|
|
193
|
+
var ie = (T) => {
|
|
194
|
+
var V = cr(), R = e.only_child(V, !0);
|
|
195
|
+
e.template_effect((j) => e.set_text(R, j), [() => g("noChatsFound")]), e.append(T, V);
|
|
196
|
+
}, N = (T) => {
|
|
197
|
+
var V = e.comment(), R = e.first_child(V);
|
|
198
|
+
e.each(R, 17, () => e.get(I), (j) => j.label, (j, Y) => {
|
|
199
|
+
var J = hr(), Q = e.child(J), se = e.only_child(Q, !0), de = e.sibling(Q, 2);
|
|
200
|
+
e.each(de, 17, () => e.get(Y).chats, (X) => X.id, (X, ae) => {
|
|
201
|
+
var Z = vr(), ne = e.child(Z), me = e.child(ne), be = e.child(me), Ie = e.only_child(be, !0), xe = e.sibling(be, 2), He = e.only_child(xe, !0);
|
|
202
|
+
e.reset(me);
|
|
203
|
+
var we = e.sibling(me, 2), ve = e.child(we), pe = e.child(ve);
|
|
204
|
+
Yt(pe, { class: "h-3 w-3" }), e.reset(ve);
|
|
205
|
+
var fe = e.sibling(ve, 2), ye = e.child(fe);
|
|
206
|
+
Wt(ye, { class: "h-3 w-3" }), e.reset(fe), e.reset(we), e.reset(ne), e.reset(Z), e.template_effect(
|
|
207
|
+
(te, ze, Ce) => {
|
|
208
|
+
e.set_class(Z, 1, `group relative cursor-pointer px-2 py-2 transition-colors hover:bg-muted ${s() === e.get(ae).id ? "bg-primary/10" : ""}`), e.set_text(Ie, e.get(ae).title), e.set_text(He, te), e.set_attribute(ve, "aria-label", ze), e.set_attribute(fe, "aria-label", Ce);
|
|
209
|
+
},
|
|
210
|
+
[
|
|
211
|
+
() => M(e.get(ae)),
|
|
212
|
+
() => g("renameChat"),
|
|
213
|
+
() => g("delete")
|
|
214
|
+
]
|
|
215
|
+
), e.delegated("click", Z, () => i.onSelectChat(e.get(ae).id)), e.delegated("keydown", Z, (te) => {
|
|
216
|
+
(te.key === "Enter" || te.key === " ") && (te.preventDefault(), i.onSelectChat(e.get(ae).id));
|
|
217
|
+
}), e.delegated("click", ve, (te) => {
|
|
218
|
+
te.stopPropagation(), i.onRenameChat(e.get(ae).id);
|
|
219
|
+
}), e.delegated("click", fe, (te) => {
|
|
220
|
+
te.stopPropagation(), i.onDeleteChat(e.get(ae).id);
|
|
221
|
+
}), e.append(X, Z);
|
|
222
|
+
}), e.reset(J), e.template_effect(() => e.set_text(se, e.get(Y).label)), e.append(j, J);
|
|
223
|
+
}), e.append(T, V);
|
|
224
|
+
};
|
|
225
|
+
e.if(re, (T) => {
|
|
226
|
+
e.get(I).length === 0 ? T(ie) : T(N, -1);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
e.reset(ee), e.reset(y), e.template_effect(
|
|
230
|
+
(T, V) => {
|
|
231
|
+
e.set_text(l, T), e.set_attribute(K, "placeholder", V);
|
|
232
|
+
},
|
|
233
|
+
[() => g("chatHistory"), () => g("searchChats")]
|
|
234
|
+
), e.bind_value(K, () => e.get(m), (T) => e.set(m, T)), e.append(t, y), e.pop();
|
|
235
|
+
}
|
|
236
|
+
e.delegate(["click", "keydown"]);
|
|
237
|
+
const We = "sveda.chat-view-mode", Oe = "sveda.chat-fixed-width", dt = "sveda.chat-dimensions", Fe = "sveda-chat-fixed-mode", Ue = "sveda-chat-immersive-mode", Me = "--sveda-chat-width", Ve = "sveda-chat-fixed-resizing", Te = 384, ke = 600, gr = 400, mr = 768, $e = (t, i, s) => Math.max(i, Math.min(s, t)), pr = () => {
|
|
238
|
+
if (typeof localStorage > "u")
|
|
239
|
+
return { width: Te, height: ke };
|
|
240
|
+
try {
|
|
241
|
+
const t = localStorage.getItem(dt);
|
|
242
|
+
if (!t)
|
|
243
|
+
return { width: Te, height: ke };
|
|
244
|
+
const i = JSON.parse(t);
|
|
245
|
+
return {
|
|
246
|
+
width: $e(Number(i.width) || Te, st, It),
|
|
247
|
+
height: $e(Number(i.height) || ke, Et, At)
|
|
248
|
+
};
|
|
249
|
+
} catch {
|
|
250
|
+
return { width: Te, height: ke };
|
|
251
|
+
}
|
|
252
|
+
}, _r = (t) => {
|
|
253
|
+
if (typeof localStorage > "u")
|
|
254
|
+
return t ? "floating" : "fixed";
|
|
255
|
+
const i = localStorage.getItem(We);
|
|
256
|
+
return i === "floating" || i === "fixed" || i === "immersive" ? i : t ? "floating" : "fixed";
|
|
257
|
+
}, br = (t, i) => {
|
|
258
|
+
if (typeof localStorage > "u")
|
|
259
|
+
return i;
|
|
260
|
+
const s = Number(localStorage.getItem(t));
|
|
261
|
+
return Number.isFinite(s) && s > 0 ? s : i;
|
|
262
|
+
};
|
|
263
|
+
function xr(t) {
|
|
264
|
+
const i = pr();
|
|
265
|
+
let s = e.state(e.proxy(_r(t.hostEmbed))), g = e.state(e.proxy(t.hostEmbed ? "floating" : "fixed")), m = e.state(!1), M = e.state(e.proxy(i.width)), S = e.state(e.proxy(i.height)), I = e.state(e.proxy(br(Oe, gr)));
|
|
266
|
+
e.user_effect(() => {
|
|
267
|
+
if (typeof window > "u" || typeof window.matchMedia != "function")
|
|
268
|
+
return;
|
|
269
|
+
const r = window.matchMedia("(max-width: 768px)"), h = () => {
|
|
270
|
+
e.set(m, t.hostEmbed ? !1 : r.matches, !0);
|
|
271
|
+
};
|
|
272
|
+
return h(), r.addEventListener("change", h), () => r.removeEventListener("change", h);
|
|
273
|
+
}), e.user_effect(() => {
|
|
274
|
+
if (typeof document > "u")
|
|
275
|
+
return;
|
|
276
|
+
const r = t.getIsMinimized(), h = document.body;
|
|
277
|
+
return h.classList.remove(Fe, Ue), document.documentElement.style.removeProperty(Me), h.style.removeProperty(Me), !r && !e.get(m) && e.get(s) === "fixed" && (h.classList.add(Fe), h.style.setProperty(Me, `${e.get(I)}px`)), !r && !e.get(m) && e.get(s) === "immersive" && h.classList.add(Ue), () => {
|
|
278
|
+
h.classList.remove(Fe, Ue), h.style.removeProperty(Me);
|
|
279
|
+
};
|
|
280
|
+
});
|
|
281
|
+
const y = (r) => {
|
|
282
|
+
localStorage.setItem(We, r);
|
|
283
|
+
};
|
|
284
|
+
return {
|
|
285
|
+
get isMobile() {
|
|
286
|
+
return e.get(m);
|
|
287
|
+
},
|
|
288
|
+
get viewMode() {
|
|
289
|
+
return e.get(s);
|
|
290
|
+
},
|
|
291
|
+
get chatWidth() {
|
|
292
|
+
return e.get(M);
|
|
293
|
+
},
|
|
294
|
+
get chatHeight() {
|
|
295
|
+
return e.get(S);
|
|
296
|
+
},
|
|
297
|
+
get isImmersiveDesktop() {
|
|
298
|
+
return !e.get(m) && !t.getIsMinimized() && e.get(s) === "immersive";
|
|
299
|
+
},
|
|
300
|
+
get chatShellClass() {
|
|
301
|
+
const r = t.getIsMinimized();
|
|
302
|
+
return [
|
|
303
|
+
"sveda-chat flex flex-col",
|
|
304
|
+
t.fillHost && !r ? "relative h-full min-h-0 w-full overflow-hidden" : "",
|
|
305
|
+
!t.fillHost && r ? "fixed bottom-0 right-0 z-50 min-[1872px]:bottom-4 min-[1872px]:right-4" : "",
|
|
306
|
+
!t.fillHost && !r && e.get(m) ? "sveda-chat-surface fixed inset-0 z-50 pb-[env(safe-area-inset-bottom)] pt-[env(safe-area-inset-top)]" : "",
|
|
307
|
+
!t.fillHost && !r && !e.get(m) && e.get(s) === "immersive" ? "sveda-chat-surface fixed right-0 top-0 z-50 h-[100dvh] pb-[env(safe-area-inset-bottom)] pt-[env(safe-area-inset-top)]" : "",
|
|
308
|
+
!t.fillHost && !r && !e.get(m) && e.get(s) === "fixed" ? "sveda-chat-surface fixed right-0 top-0 z-50 h-screen pt-[env(safe-area-inset-top)]" : "",
|
|
309
|
+
!t.fillHost && !r && !e.get(m) && e.get(s) === "floating" ? "fixed bottom-4 right-4 z-50" : "",
|
|
310
|
+
t.fillHost || e.get(m) || e.get(s) === "fixed" || e.get(s) === "immersive" ? "items-stretch" : "items-end gap-2"
|
|
311
|
+
].filter(Boolean).join(" ");
|
|
312
|
+
},
|
|
313
|
+
get chatShellStyle() {
|
|
314
|
+
const r = t.getIsMinimized();
|
|
315
|
+
if (t.fillHost && !r)
|
|
316
|
+
return "width: 100%; height: 100%;";
|
|
317
|
+
if (!e.get(m) && !r && e.get(s) === "immersive")
|
|
318
|
+
return "width: 100vw; height: 100dvh;";
|
|
319
|
+
if (!e.get(m) && !r && e.get(s) === "fixed")
|
|
320
|
+
return "width: var(--sveda-chat-width); height: 100dvh;";
|
|
321
|
+
},
|
|
322
|
+
get chatCardStyle() {
|
|
323
|
+
return e.get(m) || t.fillHost ? "width: 100%; height: 100%;" : e.get(s) === "fixed" ? "width: var(--sveda-chat-width); height: 100%;" : e.get(s) === "floating" ? `width: ${e.get(M)}px; height: ${e.get(S)}px;` : "width: 100%; height: 100%;";
|
|
324
|
+
},
|
|
325
|
+
get floatShellStyle() {
|
|
326
|
+
if (t.fillHost)
|
|
327
|
+
return "height: 100%; min-height: 0;";
|
|
328
|
+
if (!(e.get(m) || e.get(s) !== "floating"))
|
|
329
|
+
return `height: ${e.get(S)}px; min-height: 0;`;
|
|
330
|
+
},
|
|
331
|
+
toggleViewMode: () => {
|
|
332
|
+
if (e.get(s) === "immersive")
|
|
333
|
+
return;
|
|
334
|
+
const r = e.get(s) === "floating" ? "fixed" : "floating";
|
|
335
|
+
e.set(s, r, !0), e.set(g, r, !0), y(r);
|
|
336
|
+
},
|
|
337
|
+
enterImmersiveMode: () => {
|
|
338
|
+
e.get(m) || e.get(s) === "immersive" || (e.set(g, e.get(s), !0), e.set(s, "immersive"), y("immersive"));
|
|
339
|
+
},
|
|
340
|
+
exitImmersiveMode: () => {
|
|
341
|
+
if (e.get(s) !== "immersive")
|
|
342
|
+
return;
|
|
343
|
+
const r = e.get(g) === "immersive" ? "fixed" : e.get(g);
|
|
344
|
+
e.set(s, r, !0), y(r);
|
|
345
|
+
},
|
|
346
|
+
startResize: (r, h) => {
|
|
347
|
+
h.preventDefault(), h.stopPropagation();
|
|
348
|
+
const K = h.currentTarget;
|
|
349
|
+
if (!(K instanceof HTMLElement))
|
|
350
|
+
return;
|
|
351
|
+
const ee = h.pointerId;
|
|
352
|
+
try {
|
|
353
|
+
K.setPointerCapture(ee);
|
|
354
|
+
} catch {
|
|
355
|
+
}
|
|
356
|
+
const re = h.screenX, ie = h.screenY, N = e.get(s), T = N === "fixed" ? e.get(I) : e.get(M), V = e.get(S);
|
|
357
|
+
let R = T, j = V, Y = !1;
|
|
358
|
+
const J = () => {
|
|
359
|
+
window.removeEventListener("pointermove", se), window.removeEventListener("pointerup", Q), window.removeEventListener("pointercancel", Q);
|
|
360
|
+
try {
|
|
361
|
+
K.releasePointerCapture(ee);
|
|
362
|
+
} catch {
|
|
363
|
+
}
|
|
364
|
+
}, Q = () => {
|
|
365
|
+
Y || (Y = !0, document.body.classList.remove(Ve), N === "floating" && localStorage.setItem(dt, JSON.stringify({ width: R, height: j })), N === "fixed" && localStorage.setItem(Oe, String(R)), J());
|
|
366
|
+
}, se = (de) => {
|
|
367
|
+
if (Y || de.pointerId !== ee)
|
|
368
|
+
return;
|
|
369
|
+
const { deltaX: X, deltaY: ae } = Ht(de, re, ie);
|
|
370
|
+
if (N === "fixed" && r === "fixed-left") {
|
|
371
|
+
document.body.classList.add(Ve);
|
|
372
|
+
const Z = Math.max(st, window.innerWidth - mr), ne = zt(T, X, Z);
|
|
373
|
+
R = ne.width, e.set(I, ne.width, !0), ne.enterImmersive && (e.set(g, "fixed"), e.set(s, "immersive"), localStorage.setItem(We, "immersive"), localStorage.setItem(Oe, String(ne.width)), Y = !0, document.body.classList.remove(Ve), J());
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (N === "floating") {
|
|
377
|
+
const Z = Dt(r, T, V, X, ae);
|
|
378
|
+
R = Z.width, j = Z.height, e.set(M, Z.width, !0), e.set(S, Z.height, !0);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
window.addEventListener("pointermove", se), window.addEventListener("pointerup", Q), window.addEventListener("pointercancel", Q);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
let et = !1, tt = !1;
|
|
386
|
+
const C = Lt({ embedAuthEvent: sr });
|
|
387
|
+
function wr(t) {
|
|
388
|
+
let i = t ?? null;
|
|
389
|
+
try {
|
|
390
|
+
i = t ?? ge();
|
|
391
|
+
} catch {
|
|
392
|
+
i = t ?? null;
|
|
393
|
+
}
|
|
394
|
+
const s = (() => {
|
|
395
|
+
try {
|
|
396
|
+
return Ae();
|
|
397
|
+
} catch {
|
|
398
|
+
return (o) => o;
|
|
399
|
+
}
|
|
400
|
+
})();
|
|
401
|
+
i != null && i.client && C.setClient(i.client), C.setTranslate(s);
|
|
402
|
+
const g = C.getState();
|
|
403
|
+
let m = e.state(e.proxy({ ...g.chatState })), M = e.state(e.proxy(g.currentChat)), S = e.state(e.proxy(g.chatHistories)), I = e.state(0);
|
|
404
|
+
const y = () => {
|
|
405
|
+
const o = C.getState();
|
|
406
|
+
e.set(m, { ...o.chatState }, !0), e.set(M, o.currentChat, !0), e.set(S, o.chatHistories, !0), e.set(I, e.get(I) + 1);
|
|
407
|
+
};
|
|
408
|
+
return tt || (tt = !0, C.subscribe(y)), et || (et = !0, C.initAuthListener(), C.loadHistories()), {
|
|
409
|
+
get chatState() {
|
|
410
|
+
return e.get(m);
|
|
411
|
+
},
|
|
412
|
+
get currentChat() {
|
|
413
|
+
return e.get(M);
|
|
414
|
+
},
|
|
415
|
+
get chatHistories() {
|
|
416
|
+
return e.get(S);
|
|
417
|
+
},
|
|
418
|
+
get sortedHistories() {
|
|
419
|
+
return e.get(I), C.sortedHistories();
|
|
420
|
+
},
|
|
421
|
+
get openChatTabs() {
|
|
422
|
+
return e.get(I), C.openChatTabs();
|
|
423
|
+
},
|
|
424
|
+
get isOpen() {
|
|
425
|
+
return e.get(m).isOpen;
|
|
426
|
+
},
|
|
427
|
+
get isMinimized() {
|
|
428
|
+
return e.get(m).isMinimized;
|
|
429
|
+
},
|
|
430
|
+
get isLoading() {
|
|
431
|
+
return e.get(m).isLoading;
|
|
432
|
+
},
|
|
433
|
+
get isLoadingChatHistory() {
|
|
434
|
+
return e.get(m).isLoadingChatHistory;
|
|
435
|
+
},
|
|
436
|
+
get hasCurrentChat() {
|
|
437
|
+
return !!e.get(M);
|
|
438
|
+
},
|
|
439
|
+
loadHistories: () => C.loadHistories(),
|
|
440
|
+
createNewChat: () => C.createNewChat(s),
|
|
441
|
+
setCurrentChat: (o) => C.setCurrentChat(o, s),
|
|
442
|
+
addMessage: C.addMessage.bind(C),
|
|
443
|
+
setChatTitle: C.setChatTitle.bind(C),
|
|
444
|
+
refreshChatTitleFromServer: C.refreshChatTitleFromServer.bind(C),
|
|
445
|
+
updateMessage: C.updateMessage.bind(C),
|
|
446
|
+
setChatMessages: C.setChatMessages.bind(C),
|
|
447
|
+
incrementChatTokens: C.incrementChatTokens.bind(C),
|
|
448
|
+
setChatContextWindowTokens: C.setChatContextWindowTokens.bind(C),
|
|
449
|
+
deleteChat: (o) => C.deleteChat(o, s),
|
|
450
|
+
renameChat: (o, v) => C.renameChat(o, v),
|
|
451
|
+
closeChatTab: (o) => C.closeChatTab(o, s),
|
|
452
|
+
openChat: () => C.openChat(s),
|
|
453
|
+
closeChat: () => C.closeChat(),
|
|
454
|
+
minimizeChat: () => C.minimizeChat(),
|
|
455
|
+
maximizeChat: () => C.maximizeChat(),
|
|
456
|
+
setLoading: (o) => C.setLoading(o)
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
function yr(t, i, s = {}) {
|
|
460
|
+
const g = Ae(), m = ge(), M = m.client, S = m.beforeSend;
|
|
461
|
+
let I = e.state(!1), y = e.state(""), o = e.state(e.proxy(/* @__PURE__ */ new Set())), v = e.state(e.proxy(/* @__PURE__ */ new Set())), le = e.state(!1);
|
|
462
|
+
const l = {
|
|
463
|
+
getCurrentChat: () => t.getCurrentChat(),
|
|
464
|
+
setChatMessages: t.setChatMessages,
|
|
465
|
+
setChatTitle: t.setChatTitle,
|
|
466
|
+
refreshChatTitleFromServer: t.refreshChatTitleFromServer,
|
|
467
|
+
incrementChatTokens: t.incrementChatTokens,
|
|
468
|
+
setChatContextWindowTokens: t.setChatContextWindowTokens
|
|
469
|
+
}, r = { ...s, translate: g, beforeSend: S }, h = Pt(M, l, i, r), K = () => {
|
|
470
|
+
var T;
|
|
471
|
+
const N = h.getState();
|
|
472
|
+
e.set(I, N.isThinking, !0), e.set(y, N.thinkingMessage, !0), e.set(o, N.streamingChatIds, !0), e.set(v, N.unreadChatIds, !0), e.set(le, h.isStreamingFor((T = t.getCurrentChat()) == null ? void 0 : T.id), !0);
|
|
473
|
+
}, ee = h.subscribe(K);
|
|
474
|
+
K();
|
|
475
|
+
const re = h.watchCurrentChatId(() => {
|
|
476
|
+
var N;
|
|
477
|
+
return (N = t.getCurrentChat()) == null ? void 0 : N.id;
|
|
478
|
+
}), ie = setInterval(
|
|
479
|
+
() => {
|
|
480
|
+
var N;
|
|
481
|
+
re(), e.set(le, h.isStreamingFor((N = t.getCurrentChat()) == null ? void 0 : N.id), !0);
|
|
482
|
+
},
|
|
483
|
+
250
|
|
484
|
+
);
|
|
485
|
+
return Vt(() => {
|
|
486
|
+
clearInterval(ie), ee(), h.dispose();
|
|
487
|
+
}), {
|
|
488
|
+
sendMessage: h.sendMessage,
|
|
489
|
+
continueAfterMaxSteps: h.continueAfterMaxSteps,
|
|
490
|
+
resolveToolConfirmation: h.resolveToolConfirmation,
|
|
491
|
+
get isStreaming() {
|
|
492
|
+
return e.get(le);
|
|
493
|
+
},
|
|
494
|
+
get isThinking() {
|
|
495
|
+
return e.get(I);
|
|
496
|
+
},
|
|
497
|
+
get thinkingMessage() {
|
|
498
|
+
return e.get(y);
|
|
499
|
+
},
|
|
500
|
+
stopStreaming: h.stopStreaming,
|
|
501
|
+
get streamingChatIds() {
|
|
502
|
+
return e.get(o);
|
|
503
|
+
},
|
|
504
|
+
get unreadChatIds() {
|
|
505
|
+
return e.get(v);
|
|
506
|
+
},
|
|
507
|
+
clearChatUnread: h.clearChatUnread
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
function je(...t) {
|
|
511
|
+
return rr(tr(t));
|
|
512
|
+
}
|
|
513
|
+
var Cr = e.from_html('<div class="flex min-w-0 flex-1 items-center gap-2"><button type="button"><!></button> <h2 class="min-w-0 flex-1 truncate text-left font-mono text-[11px] font-normal uppercase tracking-[0.14em] text-foreground"> </h2></div>'), Sr = e.from_html('<img class="size-7 shrink-0 rounded"/>'), Mr = e.from_html('<div class="flex min-w-0 flex-1 items-center gap-4"><div class="w-[min(20rem,33vw)] min-w-0"><div class="flex items-center gap-2"><!> <span class="truncate text-lg font-bold leading-none text-foreground"> </span></div></div> <h2 class="min-w-0 flex-1 truncate text-left font-mono text-[11px] font-normal uppercase tracking-[0.14em] text-foreground"> </h2></div>'), Tr = e.from_html('<button type="button"><!></button>'), kr = e.from_html('<button type="button"><!></button> <button type="button"><!></button>', 1), Er = e.from_html('<header><!> <div class="flex shrink-0 items-center gap-0.5"><!> <!> <button type="button"><!></button></div></header>'), Ar = e.from_html('<span class="h-1.5 w-1.5 shrink-0 rounded-full bg-foreground"></span>'), Ir = e.from_html('<span class="h-1.5 w-1.5 shrink-0 rounded-full bg-primary"></span>'), Hr = e.from_html('<div role="button" tabindex="0"><span class="min-w-0 truncate"> </span> <!> <button type="button" class="ml-0.5 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground"><!></button></div>'), zr = e.from_html('<div><div class="min-w-0 flex-1 overflow-x-auto"><div class="flex h-12 min-w-max items-end gap-px px-1"><!> <button type="button" class="inline-flex h-10 shrink-0 items-center px-2 text-muted-foreground hover:text-foreground"><!></button></div></div></div>'), Dr = e.from_html('<button type="button" class="border border-border bg-secondary px-3 py-1.5 font-mono text-[11px] tracking-[0.08em] text-secondary-foreground transition-opacity hover:opacity-90 disabled:opacity-50"> </button>'), Lr = e.from_html('<div class="flex flex-col gap-2"><p class="font-mono text-[11px] tracking-[0.08em] text-muted-foreground"> </p> <div class="flex flex-wrap gap-2"></div></div>'), Pr = e.from_html('<div class="mt-auto flex flex-col gap-3"><p class="font-sans text-sm text-foreground"> </p> <!></div>'), Nr = e.from_html('<div class="ml-8 max-w-[90%] border border-border bg-muted px-3 py-2 font-sans text-sm text-foreground"> </div>'), Rr = e.from_html('<div class="prose mr-4 max-w-none font-sans text-sm text-foreground"></div>'), Or = e.from_html('<p class="font-mono text-[11px] tracking-[0.08em] text-muted-foreground"> </p>'), Fr = e.from_html('<div class="mt-auto flex flex-col gap-4"><!> <!></div>'), Ur = e.from_html('<div class="mx-3 mb-2 border border-dashed border-destructive px-3 py-2 font-mono text-[11px] tracking-[0.08em] text-destructive"> </div>'), Vr = e.from_html("<option> </option>"), jr = e.from_html('<select class="max-w-full border-0 bg-transparent font-mono text-[11px] tracking-[0.08em] text-muted-foreground outline-none"></select>'), Br = e.from_html('<button type="button" class="inline-flex h-9 w-9 items-center justify-center text-muted-foreground hover:text-foreground" aria-label="Stop"><!></button>'), Yr = e.from_html('<button type="button" class="inline-flex h-9 w-9 items-center justify-center text-muted-foreground hover:text-foreground disabled:opacity-40" aria-label="Send"><!></button>'), Wr = e.from_html('<div class="flex min-h-0 flex-1 flex-col overflow-y-auto px-4 py-4"><!></div> <!> <div class="flex flex-shrink-0 flex-col bg-background p-3"><div class="relative flex flex-col border border-dashed border-foreground bg-background"><textarea class="sveda-chat-input-textarea max-h-[250px] min-h-[60px] w-full resize-none border-0 bg-transparent p-3 font-sans text-sm text-foreground shadow-none outline-none ring-0 placeholder:font-mono placeholder:text-[11px] placeholder:tracking-[0.08em] placeholder:text-muted-foreground" style="height: 60px; outline: none; box-shadow: none"></textarea> <div class="flex items-center justify-between gap-2 border-t border-border/40 px-2 py-1.5"><div class="min-w-0 flex-1"><!></div> <!></div></div></div>', 1), Xr = e.from_html('<button type="button" class="inline-flex h-10 w-full items-center justify-center gap-2 bg-primary px-3 font-mono text-[11px] tracking-[0.14em] text-primary-foreground"><!> </button>'), Gr = e.from_html('<div class="border-b border-border/50 p-3"><!></div> <div class="min-h-0 flex-1"><!></div>', 1), qr = e.from_html('<div class="sveda-chat-surface flex h-full min-h-0 w-full flex-1 flex-col"><!> <div class="flex min-h-0 flex-1 flex-row"><aside class="sveda-chat-surface flex w-[min(20rem,33vw)] shrink-0 flex-col border-r border-border"><!></aside> <div class="sveda-chat-surface flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden"><!> <div class="mx-auto flex min-h-0 w-full max-w-7xl flex-1 flex-col overflow-hidden px-4"><!></div></div></div></div>'), Kr = e.from_html("<aside><!></aside>"), Jr = e.from_html('<span class="pointer-events-none absolute -left-px -top-px z-10 h-2.5 w-2.5 border-l border-t border-foreground" aria-hidden="true"></span> <span class="pointer-events-none absolute -right-px -top-px z-10 h-2.5 w-2.5 border-r border-t border-foreground" aria-hidden="true"></span> <span class="pointer-events-none absolute -bottom-px -left-px z-10 h-2.5 w-2.5 border-b border-l border-foreground" aria-hidden="true"></span> <span class="pointer-events-none absolute -bottom-px -right-px z-10 h-2.5 w-2.5 border-b border-r border-foreground" aria-hidden="true"></span>', 1), Qr = e.from_html('<div class="absolute bottom-3 left-0 top-3 z-10 w-1 touch-none cursor-ew-resize hover:bg-primary/30" role="separator" aria-orientation="vertical" aria-label="Resize chat"></div>'), Zr = e.from_html('<div class="absolute left-0 top-0 z-10 h-3 w-3 touch-none cursor-nw-resize hover:bg-primary/20" role="separator" aria-label="Resize chat"></div> <div class="absolute left-3 right-3 top-0 z-10 h-1 touch-none cursor-n-resize hover:bg-primary/30" role="separator" aria-orientation="horizontal" aria-label="Resize chat height"></div> <div class="absolute bottom-3 left-0 top-3 z-10 w-1 touch-none cursor-w-resize hover:bg-primary/30" role="separator" aria-orientation="vertical" aria-label="Resize chat width"></div>', 1), $r = e.from_html('<div><!> <div><div class="sveda-chat-surface relative flex min-h-0 flex-1 flex-col overflow-hidden p-0"><div class="flex min-h-0 flex-1 flex-col"><!> <!> <!></div></div> <!> <!> <!></div></div>'), ea = e.from_html("<div><!></div>"), ta = e.from_html('<div class="fixed inset-0 z-[60] flex bg-black/40" role="presentation"><aside class="sveda-chat-surface flex h-full w-80 max-w-[88vw] flex-col bg-background" role="presentation"><!></aside></div>'), ra = e.from_html('<img class="h-6 w-6 flex-shrink-0 object-cover min-[1872px]:h-10 min-[1872px]:w-10"/>'), aa = e.from_html('<span class="font-mono text-[11px] font-normal tracking-[0.14em]"> </span>'), ia = e.from_html('<button type="button" class="inline-flex h-auto min-w-0 items-center justify-center gap-2 rounded-none border border-primary bg-primary px-3.5 py-2 font-mono text-[11px] tracking-[0.14em] text-primary-foreground shadow-none transition-opacity hover:opacity-90"><!> <!></button>'), sa = e.from_html('<div class="fixed inset-0 z-[70] flex items-center justify-center bg-black/40 p-4" role="dialog" aria-modal="true"><div class="w-full max-w-sm border border-border bg-card p-4 text-card-foreground shadow-lg"><h3 class="text-base font-semibold"> </h3> <p class="mt-2 text-sm text-muted-foreground"> </p> <div class="mt-4 flex justify-end gap-2"><button type="button" class="border border-border px-3 py-2 text-sm"> </button> <button type="button" class="bg-primary px-3 py-2 text-sm text-primary-foreground"> </button></div></div></div>'), na = e.from_html('<div class="fixed inset-0 z-[70] flex items-center justify-center bg-black/40 p-4" role="dialog" aria-modal="true"><div class="w-full max-w-sm border border-border bg-card p-4 text-card-foreground shadow-lg"><h3 class="text-base font-semibold"> </h3> <input type="text" class="mt-3 h-10 w-full border border-input bg-input px-3 text-sm outline-none"/> <div class="mt-4 flex justify-end gap-2"><button type="button" class="border border-border px-3 py-2 text-sm"> </button> <button type="button" class="bg-primary px-3 py-2 text-sm text-primary-foreground"> </button></div></div></div>'), oa = e.from_html('<div data-testid="sveda-chat"><!> <!> <!> <!> <!></div>');
|
|
514
|
+
function ba(t, i) {
|
|
515
|
+
e.push(i, !0);
|
|
516
|
+
const s = (a, n = e.noop) => {
|
|
517
|
+
var c = Er(), L = e.child(c);
|
|
518
|
+
{
|
|
519
|
+
var G = (_) => {
|
|
520
|
+
var b = Cr(), k = e.child(b), $ = e.child(k);
|
|
521
|
+
Gt($, { class: "h-4 w-4" }), e.reset(k);
|
|
522
|
+
var F = e.sibling(k, 2), x = e.only_child(F, !0);
|
|
523
|
+
e.reset(b), e.template_effect(
|
|
524
|
+
(p, D) => {
|
|
525
|
+
e.set_class(k, 1, `inline-flex h-9 w-9 items-center justify-center bg-transparent text-muted-foreground hover:text-foreground ${e.get(h) ? "bg-muted/60 text-foreground" : ""}`), e.set_attribute(k, "aria-label", p), e.set_attribute(k, "title", D), e.set_text(x, e.get(xe));
|
|
526
|
+
},
|
|
527
|
+
[() => v("chatHistory"), () => v("chatHistory")]
|
|
528
|
+
), e.delegated("click", k, () => e.set(h, !e.get(h))), e.append(_, b);
|
|
529
|
+
}, z = (_) => {
|
|
530
|
+
var b = Mr(), k = e.child(b), $ = e.child(k), F = e.child($);
|
|
531
|
+
{
|
|
532
|
+
var x = (d) => {
|
|
533
|
+
var B = Sr();
|
|
534
|
+
e.template_effect(() => {
|
|
535
|
+
e.set_attribute(B, "src", e.get(R)), e.set_attribute(B, "alt", e.get(V));
|
|
536
|
+
}), e.append(d, B);
|
|
537
|
+
}, p = (d) => {
|
|
538
|
+
Zt(d, { class: "size-5 shrink-0 text-primary" });
|
|
539
|
+
};
|
|
540
|
+
e.if(F, (d) => {
|
|
541
|
+
e.get(R) ? d(x) : d(p, -1);
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
var D = e.sibling(F, 2), u = e.only_child(D, !0);
|
|
545
|
+
e.reset($), e.reset(k);
|
|
546
|
+
var w = e.sibling(k, 2), U = e.only_child(w, !0);
|
|
547
|
+
e.reset(b), e.template_effect(() => {
|
|
548
|
+
e.set_text(u, e.get(V)), e.set_text(U, e.get(xe));
|
|
549
|
+
}), e.append(_, b);
|
|
550
|
+
};
|
|
551
|
+
e.if(L, (_) => {
|
|
552
|
+
n() ? _(z, -1) : _(G);
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
var E = e.sibling(L, 2), f = e.child(E);
|
|
556
|
+
{
|
|
557
|
+
var A = (_) => {
|
|
558
|
+
var b = Tr();
|
|
559
|
+
e.set_class(b, 1, e.clsx(ie));
|
|
560
|
+
var k = e.child(b);
|
|
561
|
+
qt(k, { class: "h-4 w-4" }), e.reset(b), e.template_effect(
|
|
562
|
+
($, F) => {
|
|
563
|
+
e.set_attribute(b, "aria-label", $), e.set_attribute(b, "title", F);
|
|
564
|
+
},
|
|
565
|
+
[() => v("immersiveModeExit"), () => v("immersiveModeExit")]
|
|
566
|
+
), e.delegated("click", b, function(...$) {
|
|
567
|
+
var F;
|
|
568
|
+
(F = r.exitImmersiveMode) == null || F.apply(this, $);
|
|
569
|
+
}), e.append(_, b);
|
|
570
|
+
};
|
|
571
|
+
e.if(f, (_) => {
|
|
572
|
+
!r.isMobile && r.viewMode === "immersive" && _(A);
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
var H = e.sibling(f, 2);
|
|
576
|
+
{
|
|
577
|
+
var O = (_) => {
|
|
578
|
+
var b = kr(), k = e.first_child(b);
|
|
579
|
+
e.set_class(k, 1, e.clsx(ie));
|
|
580
|
+
var $ = e.child(k);
|
|
581
|
+
Kt($, { class: "h-4 w-4" }), e.reset(k);
|
|
582
|
+
var F = e.sibling(k, 2);
|
|
583
|
+
e.set_class(F, 1, e.clsx(ie));
|
|
584
|
+
var x = e.child(F);
|
|
585
|
+
{
|
|
586
|
+
var p = (u) => {
|
|
587
|
+
$t(u, { class: "h-4 w-4" });
|
|
588
|
+
}, D = (u) => {
|
|
589
|
+
er(u, { class: "h-4 w-4" });
|
|
590
|
+
};
|
|
591
|
+
e.if(x, (u) => {
|
|
592
|
+
r.viewMode === "floating" ? u(p) : u(D, -1);
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
e.reset(F), e.template_effect(
|
|
596
|
+
(u, w, U, d) => {
|
|
597
|
+
e.set_attribute(k, "aria-label", u), e.set_attribute(k, "title", w), e.set_attribute(F, "aria-label", U), e.set_attribute(F, "title", d);
|
|
598
|
+
},
|
|
599
|
+
[
|
|
600
|
+
() => v("immersiveModeEnter"),
|
|
601
|
+
() => v("immersiveModeEnter"),
|
|
602
|
+
() => r.viewMode === "floating" ? v("viewModeFixed") : v("viewModeFloating"),
|
|
603
|
+
() => r.viewMode === "floating" ? v("viewModeFixed") : v("viewModeFloating")
|
|
604
|
+
]
|
|
605
|
+
), e.delegated("click", k, function(...u) {
|
|
606
|
+
var w;
|
|
607
|
+
(w = r.enterImmersiveMode) == null || w.apply(this, u);
|
|
608
|
+
}), e.delegated("click", F, function(...u) {
|
|
609
|
+
var w;
|
|
610
|
+
(w = r.toggleViewMode) == null || w.apply(this, u);
|
|
611
|
+
}), e.append(_, b);
|
|
612
|
+
};
|
|
613
|
+
e.if(H, (_) => {
|
|
614
|
+
!r.isMobile && r.viewMode !== "immersive" && _(O);
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
var P = e.sibling(H, 2);
|
|
618
|
+
e.set_class(P, 1, e.clsx(ie));
|
|
619
|
+
var W = e.child(P);
|
|
620
|
+
Ze(W, { class: "h-4 w-4" }), e.reset(P), e.reset(E), e.reset(c), e.template_effect(
|
|
621
|
+
(_, b) => {
|
|
622
|
+
e.set_class(c, 1, `flex h-12 shrink-0 flex-row items-center justify-between border-b border-border bg-card px-3 ${r.viewMode === "floating" && !r.isMobile ? "rounded-t-[var(--sveda-radius)]" : "rounded-none"}`), e.set_attribute(P, "aria-label", _), e.set_attribute(P, "title", b);
|
|
623
|
+
},
|
|
624
|
+
[() => v("toolbarMinimize"), () => v("toolbarMinimize")]
|
|
625
|
+
), e.delegated("click", P, () => l.minimizeChat()), e.append(a, c);
|
|
626
|
+
}, g = (a, n = e.noop) => {
|
|
627
|
+
var c = e.comment(), L = e.first_child(c);
|
|
628
|
+
{
|
|
629
|
+
var G = (z) => {
|
|
630
|
+
var E = zr(), f = e.child(E), A = e.child(f), H = e.child(A);
|
|
631
|
+
e.each(H, 17, () => l.openChatTabs, (W) => W.id, (W, _) => {
|
|
632
|
+
var b = Hr(), k = e.child(b), $ = e.only_child(k, !0), F = e.sibling(k, 2);
|
|
633
|
+
{
|
|
634
|
+
var x = (d) => {
|
|
635
|
+
var B = Ar();
|
|
636
|
+
e.template_effect((q) => e.set_attribute(B, "aria-label", q), [() => v("chatTabRunning")]), e.append(d, B);
|
|
637
|
+
}, p = e.derived(() => X.streamingChatIds.has(e.get(_).id)), D = (d) => {
|
|
638
|
+
var B = Ir();
|
|
639
|
+
e.template_effect((q) => e.set_attribute(B, "aria-label", q), [() => v("chatTabUnread")]), e.append(d, B);
|
|
640
|
+
}, u = e.derived(() => X.unreadChatIds.has(e.get(_).id));
|
|
641
|
+
e.if(F, (d) => {
|
|
642
|
+
e.get(p) ? d(x) : e.get(u) && d(D, 1);
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
var w = e.sibling(F, 2), U = e.child(w);
|
|
646
|
+
Ze(U, { class: "h-3 w-3" }), e.reset(w), e.reset(b), e.template_effect(
|
|
647
|
+
(d, B, q) => {
|
|
648
|
+
e.set_class(b, 1, d), e.set_text($, B), e.set_attribute(w, "aria-label", q);
|
|
649
|
+
},
|
|
650
|
+
[
|
|
651
|
+
() => {
|
|
652
|
+
var d;
|
|
653
|
+
return e.clsx(je("inline-flex h-10 max-w-56 shrink-0 items-center gap-1.5 whitespace-nowrap border-b border-transparent px-3 py-2 font-mono text-[11px] tracking-[0.12em] text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none", ((d = l.currentChat) == null ? void 0 : d.id) === e.get(_).id ? "border-foreground bg-transparent text-foreground" : ""));
|
|
654
|
+
},
|
|
655
|
+
() => e.get(be).get(e.get(_).id) ?? e.get(_).title,
|
|
656
|
+
() => v("closeChatTab")
|
|
657
|
+
]
|
|
658
|
+
), e.delegated("click", b, () => void te(e.get(_).id)), e.delegated("keydown", b, (d) => {
|
|
659
|
+
(d.key === "Enter" || d.key === " ") && (d.preventDefault(), te(e.get(_).id));
|
|
660
|
+
}), e.delegated("click", w, (d) => {
|
|
661
|
+
d.stopPropagation(), l.closeChatTab(e.get(_).id);
|
|
662
|
+
}), e.append(W, b);
|
|
663
|
+
});
|
|
664
|
+
var O = e.sibling(H, 2), P = e.child(O);
|
|
665
|
+
Qe(P, { class: "h-4 w-4" }), e.reset(O), e.reset(A), e.reset(f), e.reset(E), e.template_effect(
|
|
666
|
+
(W) => {
|
|
667
|
+
e.set_class(E, 1, `flex shrink-0 items-stretch border-b border-border bg-card ${n() ? "px-3" : "px-4"}`), e.set_attribute(O, "aria-label", W);
|
|
668
|
+
},
|
|
669
|
+
[() => v("newChat")]
|
|
670
|
+
), e.delegated("click", O, ye), e.append(z, E);
|
|
671
|
+
};
|
|
672
|
+
e.if(L, (z) => {
|
|
673
|
+
l.openChatTabs.length > 0 && z(G);
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
e.append(a, c);
|
|
677
|
+
}, m = (a) => {
|
|
678
|
+
var n = Wr(), c = e.first_child(n), L = e.child(c);
|
|
679
|
+
{
|
|
680
|
+
var G = (x) => {
|
|
681
|
+
var p = Pr(), D = e.child(p), u = e.only_child(D, !0), w = e.sibling(D, 2);
|
|
682
|
+
{
|
|
683
|
+
var U = (d) => {
|
|
684
|
+
var B = Lr(), q = e.child(B), De = e.only_child(q, !0), Se = e.sibling(q, 2);
|
|
685
|
+
e.each(Se, 21, () => e.get(T), (he) => he.label, (he, ce) => {
|
|
686
|
+
var oe = Dr(), ue = e.only_child(oe, !0);
|
|
687
|
+
e.template_effect(() => {
|
|
688
|
+
oe.disabled = l.isLoading || X.isStreaming, e.set_text(ue, e.get(ce).label);
|
|
689
|
+
}), e.delegated("click", oe, () => ft(e.get(ce))), e.append(he, oe);
|
|
690
|
+
}), e.reset(Se), e.reset(B), e.template_effect((he) => e.set_text(De, he), [() => v("quickPromptsTitle")]), e.append(d, B);
|
|
691
|
+
};
|
|
692
|
+
e.if(w, (d) => {
|
|
693
|
+
e.get(T).length > 0 && d(U);
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
e.reset(p), e.template_effect(() => e.set_text(u, e.get(Ie))), e.append(x, p);
|
|
697
|
+
}, z = (x) => {
|
|
698
|
+
var p = Fr(), D = e.child(p);
|
|
699
|
+
e.each(D, 17, () => e.get(ne), (U) => U.id, (U, d) => {
|
|
700
|
+
var B = e.comment(), q = e.first_child(B);
|
|
701
|
+
{
|
|
702
|
+
var De = (ce) => {
|
|
703
|
+
var oe = Nr(), ue = e.only_child(oe, !0);
|
|
704
|
+
e.template_effect((Le) => e.set_text(ue, Le), [() => it(e.get(d))]), e.append(ce, oe);
|
|
705
|
+
}, Se = e.derived(() => e.get(d).role === "user" && Je(e.get(d))), he = (ce) => {
|
|
706
|
+
const oe = e.derived(() => ve(e.get(d)));
|
|
707
|
+
var ue = e.comment(), Le = e.first_child(ue);
|
|
708
|
+
{
|
|
709
|
+
var xt = (Pe) => {
|
|
710
|
+
var Ne = Rr();
|
|
711
|
+
e.html(Ne, () => e.get(oe), !0), e.reset(Ne), e.append(Pe, Ne);
|
|
712
|
+
};
|
|
713
|
+
e.if(Le, (Pe) => {
|
|
714
|
+
e.get(oe) && Pe(xt);
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
e.append(ce, ue);
|
|
718
|
+
};
|
|
719
|
+
e.if(q, (ce) => {
|
|
720
|
+
e.get(Se) ? ce(De) : e.get(d).role === "assistant" && ce(he, 1);
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
e.append(U, B);
|
|
724
|
+
});
|
|
725
|
+
var u = e.sibling(D, 2);
|
|
726
|
+
{
|
|
727
|
+
var w = (U) => {
|
|
728
|
+
var d = Or(), B = e.only_child(d, !0);
|
|
729
|
+
e.template_effect((q) => e.set_text(B, q), [() => X.thinkingMessage || v("preparingReply")]), e.append(U, d);
|
|
730
|
+
};
|
|
731
|
+
e.if(u, (U) => {
|
|
732
|
+
(X.isThinking || X.isStreaming) && U(w);
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
e.reset(p), e.append(x, p);
|
|
736
|
+
};
|
|
737
|
+
e.if(L, (x) => {
|
|
738
|
+
e.get(me) ? x(z, -1) : x(G);
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
e.reset(c), e.bind_this(c, (x) => e.set(J, x), () => e.get(J));
|
|
742
|
+
var E = e.sibling(c, 2);
|
|
743
|
+
{
|
|
744
|
+
var f = (x) => {
|
|
745
|
+
var p = Ur(), D = e.only_child(p, !0);
|
|
746
|
+
e.template_effect(() => e.set_text(D, e.get(Q))), e.append(x, p);
|
|
747
|
+
};
|
|
748
|
+
e.if(E, (x) => {
|
|
749
|
+
e.get(Q) && x(f);
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
var A = e.sibling(E, 2), H = e.child(A), O = e.child(H);
|
|
753
|
+
e.remove_textarea_child(O);
|
|
754
|
+
var P = e.sibling(O, 2), W = e.child(P), _ = e.child(W);
|
|
755
|
+
{
|
|
756
|
+
var b = (x) => {
|
|
757
|
+
var p = jr();
|
|
758
|
+
e.each(p, 21, () => e.get(N), (D) => D.id, (D, u) => {
|
|
759
|
+
var w = Vr(), U = e.only_child(w, !0), d = {};
|
|
760
|
+
e.template_effect(() => {
|
|
761
|
+
e.set_text(U, e.get(u).label || e.get(u).id), d !== (d = e.get(u).id) && (w.value = (w.__value = d) ?? "");
|
|
762
|
+
}), e.append(D, w);
|
|
763
|
+
}), e.reset(p), e.init_select(p), e.template_effect(() => p.disabled = l.isLoading || X.isStreaming), e.bind_select_value(p, () => e.get(Y), (D) => e.set(Y, D)), e.append(x, p);
|
|
764
|
+
};
|
|
765
|
+
e.if(_, (x) => {
|
|
766
|
+
e.get(N).length > 0 && x(b);
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
e.reset(W);
|
|
770
|
+
var k = e.sibling(W, 2);
|
|
771
|
+
{
|
|
772
|
+
var $ = (x) => {
|
|
773
|
+
var p = Br(), D = e.child(p);
|
|
774
|
+
Jt(D, { class: "h-4 w-4" }), e.reset(p), e.delegated("click", p, () => X.stopStreaming()), e.append(x, p);
|
|
775
|
+
}, F = (x) => {
|
|
776
|
+
var p = Yr(), D = e.child(p);
|
|
777
|
+
Qt(D, { class: "h-4 w-4" }), e.reset(p), e.template_effect(() => p.disabled = !e.get(He)), e.delegated("click", p, () => void pe()), e.append(x, p);
|
|
778
|
+
};
|
|
779
|
+
e.if(k, (x) => {
|
|
780
|
+
X.isStreaming ? x($) : x(F, -1);
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
e.reset(P), e.reset(H), e.reset(A), e.template_effect(
|
|
784
|
+
(x) => {
|
|
785
|
+
e.set_attribute(O, "placeholder", x), O.disabled = l.isLoading;
|
|
786
|
+
},
|
|
787
|
+
[() => v("typeMessage")]
|
|
788
|
+
), e.delegated("keydown", O, fe), e.bind_value(O, () => e.get(j), (x) => e.set(j, x)), e.append(a, n);
|
|
789
|
+
}, M = (a) => {
|
|
790
|
+
var n = Xr(), c = e.child(n);
|
|
791
|
+
Qe(c, { class: "h-4 w-4" });
|
|
792
|
+
var L = e.sibling(c);
|
|
793
|
+
e.reset(n), e.template_effect((G) => e.set_text(L, ` ${G ?? ""}`), [() => v("newChat")]), e.delegated("click", n, ye), e.append(a, n);
|
|
794
|
+
}, S = (a) => {
|
|
795
|
+
var n = Gr(), c = e.first_child(n), L = e.child(c);
|
|
796
|
+
M(L), e.reset(c);
|
|
797
|
+
var G = e.sibling(c, 2), z = e.child(G);
|
|
798
|
+
{
|
|
799
|
+
let E = e.derived(() => {
|
|
800
|
+
var f;
|
|
801
|
+
return (f = l.currentChat) == null ? void 0 : f.id;
|
|
802
|
+
});
|
|
803
|
+
ur(z, {
|
|
804
|
+
get histories() {
|
|
805
|
+
return l.sortedHistories;
|
|
806
|
+
},
|
|
807
|
+
get currentChatId() {
|
|
808
|
+
return e.get(E);
|
|
809
|
+
},
|
|
810
|
+
onSelectChat: (f) => void te(f),
|
|
811
|
+
onDeleteChat: (f) => e.set(K, f, !0),
|
|
812
|
+
onRenameChat: (f) => {
|
|
813
|
+
const A = l.sortedHistories.find((H) => H.id === f);
|
|
814
|
+
e.set(ee, f, !0), e.set(re, (A == null ? void 0 : A.title) ?? "", !0);
|
|
815
|
+
}
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
e.reset(G), e.append(a, n);
|
|
819
|
+
};
|
|
820
|
+
let I = e.prop(i, "pageUrl", 3, "");
|
|
821
|
+
const y = dr(), o = ge(), v = Ae(), le = ar(), l = wr(), r = xr({
|
|
822
|
+
getIsMinimized: () => l.isMinimized,
|
|
823
|
+
hostEmbed: o.hostEmbed,
|
|
824
|
+
fillHost: o.fillHost
|
|
825
|
+
});
|
|
826
|
+
let h = e.state(!1), K = e.state(null), ee = e.state(null), re = e.state("");
|
|
827
|
+
const ie = "inline-flex h-9 w-9 items-center justify-center bg-transparent text-muted-foreground hover:text-foreground", N = e.derived(() => i.models ?? y.models), T = e.derived(() => i.quickPrompts ?? y.quickPrompts), V = e.derived(() => i.brandName ?? y.brand.name), R = e.derived(() => i.brandLogo ?? y.brand.logoUrl ?? "");
|
|
828
|
+
let j = e.state(""), Y = e.state(""), J = e.state(null), Q = e.state("");
|
|
829
|
+
const se = "__SVEDA_CHAT_PAGE_BOOTED__", de = (a) => {
|
|
830
|
+
const n = e.get(J);
|
|
831
|
+
n && (a != null && a.onlyIfNearBottom && n.scrollHeight - n.scrollTop - n.clientHeight > 120 || n.scrollTo({
|
|
832
|
+
top: n.scrollHeight,
|
|
833
|
+
behavior: (a == null ? void 0 : a.behavior) ?? "smooth"
|
|
834
|
+
}));
|
|
835
|
+
}, X = yr(
|
|
836
|
+
{
|
|
837
|
+
getCurrentChat: () => l.currentChat,
|
|
838
|
+
setChatMessages: l.setChatMessages,
|
|
839
|
+
setChatTitle: l.setChatTitle,
|
|
840
|
+
refreshChatTitleFromServer: l.refreshChatTitleFromServer,
|
|
841
|
+
incrementChatTokens: l.incrementChatTokens,
|
|
842
|
+
setChatContextWindowTokens: l.setChatContextWindowTokens
|
|
843
|
+
},
|
|
844
|
+
de,
|
|
845
|
+
{
|
|
846
|
+
newChatLabel: () => v("newChat"),
|
|
847
|
+
resolveSendOptions: () => {
|
|
848
|
+
var n;
|
|
849
|
+
const a = e.get(Y) || ((n = e.get(N)[0]) == null ? void 0 : n.id);
|
|
850
|
+
return a ? { model: a } : {};
|
|
851
|
+
},
|
|
852
|
+
onError: (a, n) => {
|
|
853
|
+
var L;
|
|
854
|
+
const c = n instanceof Error && n.message.trim() ? n.message : v("errorSendingMessage");
|
|
855
|
+
e.set(Q, c, !0), (L = i.notify) == null || L.call(i, "error", c);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
), ae = e.derived(() => {
|
|
859
|
+
const a = le.label.trim();
|
|
860
|
+
return a !== "" ? a : e.get(V);
|
|
861
|
+
}), Z = e.derived(() => {
|
|
862
|
+
const a = le.image.trim();
|
|
863
|
+
return a !== "" ? a : e.get(R);
|
|
864
|
+
}), ne = e.derived(() => {
|
|
865
|
+
var a;
|
|
866
|
+
return ((a = l.currentChat) == null ? void 0 : a.messages) ?? [];
|
|
867
|
+
}), me = e.derived(() => e.get(ne).some((a) => a.role === "user" && Je(a))), be = e.derived(() => Nt(l.openChatTabs, v)), Ie = e.derived(() => v("welcomeMessage")), xe = e.derived(() => {
|
|
868
|
+
var a;
|
|
869
|
+
return ((a = l.currentChat) == null ? void 0 : a.title) || v("chatTitle");
|
|
870
|
+
}), He = e.derived(() => e.get(j).trim().length > 0 && !l.isLoading && !X.isStreaming), we = (a) => {
|
|
871
|
+
const n = a.content;
|
|
872
|
+
return typeof n == "string" ? n : Array.isArray(a.parts) ? a.parts.filter((c) => c && typeof c == "object" && c.type === "text").map((c) => String(c.text ?? "")).join("") : "";
|
|
873
|
+
}, ve = (a) => a.role === "user" ? "" : Rt(we(a)), pe = async () => {
|
|
874
|
+
const a = e.get(j).trim();
|
|
875
|
+
if (!(!a || l.isLoading || X.isStreaming)) {
|
|
876
|
+
e.set(Q, ""), e.set(j, ""), l.maximizeChat(), l.setLoading(!0);
|
|
877
|
+
try {
|
|
878
|
+
await X.sendMessage(a, I() ? { pageUrl: I() } : void 0);
|
|
879
|
+
} finally {
|
|
880
|
+
l.setLoading(!1), await Re(), de({ behavior: "smooth", onlyIfNearBottom: !1 });
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
}, fe = (a) => {
|
|
884
|
+
a.key === "Enter" && !a.shiftKey && (a.preventDefault(), pe());
|
|
885
|
+
}, ye = () => {
|
|
886
|
+
l.createNewChat(), e.set(j, ""), e.set(Q, ""), r.isMobile && e.set(h, !1);
|
|
887
|
+
}, te = async (a) => {
|
|
888
|
+
X.clearChatUnread(a), await l.setCurrentChat(a), r.isMobile && e.set(h, !1), await Re(), de({ behavior: "auto", onlyIfNearBottom: !1 });
|
|
889
|
+
}, ze = () => {
|
|
890
|
+
e.get(K) && l.deleteChat(e.get(K)), e.set(K, null);
|
|
891
|
+
}, Ce = () => {
|
|
892
|
+
const a = e.get(re).trim();
|
|
893
|
+
e.get(ee) && a && l.renameChat(e.get(ee), a), e.set(ee, null), e.set(re, "");
|
|
894
|
+
}, ct = e.derived(() => je("sveda-chat-surface flex min-h-0 w-80 shrink-0 flex-col overflow-hidden bg-background", r.isMobile ? "h-full max-w-[88vw] border-r border-border" : o.fillHost ? "h-full border-r border-border" : r.viewMode === "fixed" ? "absolute right-full top-0 z-10 h-full border-r border-border" : "h-full rounded-[var(--sveda-radius)] border border-border")), vt = e.derived(() => r.isMobile || r.viewMode === "fixed" ? "relative flex h-full min-h-0 min-w-0 flex-1 flex-row" : o.fillHost ? "relative flex h-full min-h-0 min-w-0 w-full flex-row items-stretch overflow-hidden" : "relative flex min-h-0 flex-row items-stretch gap-2"), ht = e.derived(() => je("sveda-chat-surface relative flex min-h-0 flex-col overflow-visible", r.viewMode === "floating" && !r.isMobile && !o.fillHost && "sveda-chat-frame", (o.fillHost || r.isMobile) && "border-0", r.isMobile && "h-full min-w-0 flex-1 rounded-none", r.viewMode === "fixed" && !r.isMobile && "h-full min-w-0 flex-1 rounded-none border-b-0 border-l border-r-0 border-t-0 border-border", r.viewMode === "floating" && "rounded-[var(--sveda-radius)]", (r.isMobile || r.viewMode === "fixed") && "rounded-none", r.viewMode === "floating" && !r.isMobile && !o.fillHost && "min-w-0 shrink-0", r.viewMode === "floating" && !r.isMobile && o.fillHost && "h-full min-w-0 flex-1")), ft = (a) => {
|
|
895
|
+
e.set(j, a.prompt, !0), pe();
|
|
896
|
+
};
|
|
897
|
+
jt(() => {
|
|
898
|
+
var a;
|
|
899
|
+
(a = e.get(N)[0]) != null && a.id && e.set(Y, e.get(N)[0].id, !0), typeof i.agentTasksSubscribe == "function" && i.agentTasksSubscribe(() => {
|
|
900
|
+
}), (async () => {
|
|
901
|
+
await l.loadHistories();
|
|
902
|
+
const n = window;
|
|
903
|
+
!!n[se] ? l.currentChat || (l.sortedHistories.length > 0 ? await l.setCurrentChat(l.sortedHistories[0].id) : l.createNewChat()) : (n[se] = !0, l.createNewChat()), await Re(), de({ behavior: "auto", onlyIfNearBottom: !1 });
|
|
904
|
+
})();
|
|
905
|
+
});
|
|
906
|
+
var _e = oa(), Xe = e.child(_e);
|
|
907
|
+
{
|
|
908
|
+
var ut = (a) => {
|
|
909
|
+
var n = ea(), c = e.child(n);
|
|
910
|
+
{
|
|
911
|
+
var L = (z) => {
|
|
912
|
+
var E = qr(), f = e.child(E);
|
|
913
|
+
s(f, () => !0);
|
|
914
|
+
var A = e.sibling(f, 2), H = e.child(A), O = e.child(H);
|
|
915
|
+
S(O), e.reset(H);
|
|
916
|
+
var P = e.sibling(H, 2), W = e.child(P);
|
|
917
|
+
g(W, () => !1);
|
|
918
|
+
var _ = e.sibling(W, 2), b = e.child(_);
|
|
919
|
+
m(b), e.reset(_), e.reset(P), e.reset(A), e.reset(E), e.append(z, E);
|
|
920
|
+
}, G = (z) => {
|
|
921
|
+
var E = $r(), f = e.child(E);
|
|
922
|
+
{
|
|
923
|
+
var A = (u) => {
|
|
924
|
+
var w = Kr(), U = e.child(w);
|
|
925
|
+
S(U), e.reset(w), e.template_effect(() => e.set_class(w, 1, e.clsx(e.get(ct)))), e.append(u, w);
|
|
926
|
+
};
|
|
927
|
+
e.if(f, (u) => {
|
|
928
|
+
e.get(h) && !r.isMobile && u(A);
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
var H = e.sibling(f, 2), O = e.child(H), P = e.child(O), W = e.child(P);
|
|
932
|
+
s(W, () => !1);
|
|
933
|
+
var _ = e.sibling(W, 2);
|
|
934
|
+
g(_, () => !0);
|
|
935
|
+
var b = e.sibling(_, 2);
|
|
936
|
+
m(b), e.reset(P), e.reset(O);
|
|
937
|
+
var k = e.sibling(O, 2);
|
|
938
|
+
{
|
|
939
|
+
var $ = (u) => {
|
|
940
|
+
var w = Jr();
|
|
941
|
+
e.next(6), e.append(u, w);
|
|
942
|
+
};
|
|
943
|
+
e.if(k, (u) => {
|
|
944
|
+
r.viewMode === "floating" && !r.isMobile && !o.fillHost && u($);
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
var F = e.sibling(k, 2);
|
|
948
|
+
{
|
|
949
|
+
var x = (u) => {
|
|
950
|
+
var w = Qr();
|
|
951
|
+
e.delegated("pointerdown", w, (U) => r.startResize("fixed-left", U)), e.append(u, w);
|
|
952
|
+
};
|
|
953
|
+
e.if(F, (u) => {
|
|
954
|
+
!r.isMobile && r.viewMode === "fixed" && u(x);
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
var p = e.sibling(F, 2);
|
|
958
|
+
{
|
|
959
|
+
var D = (u) => {
|
|
960
|
+
var w = Zr(), U = e.first_child(w), d = e.sibling(U, 2), B = e.sibling(d, 2);
|
|
961
|
+
e.delegated("pointerdown", U, (q) => r.startResize("top-left", q)), e.delegated("pointerdown", d, (q) => r.startResize("top", q)), e.delegated("pointerdown", B, (q) => r.startResize("left", q)), e.append(u, w);
|
|
962
|
+
};
|
|
963
|
+
e.if(p, (u) => {
|
|
964
|
+
!r.isMobile && r.viewMode === "floating" && u(D);
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
e.reset(H), e.reset(E), e.template_effect(() => {
|
|
968
|
+
e.set_class(E, 1, e.clsx(e.get(vt))), e.set_style(E, r.floatShellStyle), e.set_class(H, 1, e.clsx(e.get(ht))), e.set_style(H, r.chatCardStyle);
|
|
969
|
+
}), e.append(z, E);
|
|
970
|
+
};
|
|
971
|
+
e.if(c, (z) => {
|
|
972
|
+
r.isImmersiveDesktop ? z(L) : z(G, -1);
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
e.reset(n), e.template_effect(() => e.set_class(n, 1, e.clsx(r.isMobile || r.viewMode === "fixed" || o.fillHost ? "flex h-full min-h-0 w-full min-w-0 flex-1" : r.viewMode === "immersive" ? "flex h-full min-h-0 w-full min-w-0 flex-1 flex-col" : "flex gap-2"))), e.append(a, n);
|
|
976
|
+
};
|
|
977
|
+
e.if(Xe, (a) => {
|
|
978
|
+
l.isMinimized || a(ut);
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
var Ge = e.sibling(Xe, 2);
|
|
982
|
+
{
|
|
983
|
+
var gt = (a) => {
|
|
984
|
+
var n = ta(), c = e.child(n), L = e.child(c);
|
|
985
|
+
S(L), e.reset(c), e.reset(n), e.delegated("click", n, () => e.set(h, !1)), e.delegated("click", c, (G) => G.stopPropagation()), e.append(a, n);
|
|
986
|
+
};
|
|
987
|
+
e.if(Ge, (a) => {
|
|
988
|
+
r.isMobile && e.get(h) && !l.isMinimized && a(gt);
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
var qe = e.sibling(Ge, 2);
|
|
992
|
+
{
|
|
993
|
+
var mt = (a) => {
|
|
994
|
+
var n = ia(), c = e.child(n);
|
|
995
|
+
{
|
|
996
|
+
var L = (f) => {
|
|
997
|
+
var A = ra();
|
|
998
|
+
e.template_effect(
|
|
999
|
+
(H) => {
|
|
1000
|
+
e.set_attribute(A, "src", e.get(Z)), e.set_attribute(A, "alt", H);
|
|
1001
|
+
},
|
|
1002
|
+
[() => v("assistantLogoAlt")]
|
|
1003
|
+
), e.append(f, A);
|
|
1004
|
+
}, G = (f) => {
|
|
1005
|
+
Xt(f, { class: "h-6 w-6 flex-shrink-0" });
|
|
1006
|
+
};
|
|
1007
|
+
e.if(c, (f) => {
|
|
1008
|
+
e.get(Z) ? f(L) : f(G, -1);
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
var z = e.sibling(c, 2);
|
|
1012
|
+
{
|
|
1013
|
+
var E = (f) => {
|
|
1014
|
+
var A = aa(), H = e.only_child(A, !0);
|
|
1015
|
+
e.template_effect(() => e.set_text(H, e.get(ae))), e.append(f, A);
|
|
1016
|
+
};
|
|
1017
|
+
e.if(z, (f) => {
|
|
1018
|
+
e.get(ae) && f(E);
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
e.reset(n), e.delegated("click", n, () => void l.openChat()), e.append(a, n);
|
|
1022
|
+
};
|
|
1023
|
+
e.if(qe, (a) => {
|
|
1024
|
+
l.isMinimized && !r.isMobile && !o.hideLauncher && a(mt);
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
var Ke = e.sibling(qe, 2);
|
|
1028
|
+
{
|
|
1029
|
+
var pt = (a) => {
|
|
1030
|
+
var n = sa(), c = e.child(n), L = e.child(c), G = e.only_child(L, !0), z = e.sibling(L, 2), E = e.only_child(z, !0), f = e.sibling(z, 2), A = e.child(f), H = e.only_child(A, !0), O = e.sibling(A, 2), P = e.only_child(O, !0);
|
|
1031
|
+
e.reset(f), e.reset(c), e.reset(n), e.template_effect(
|
|
1032
|
+
(W, _, b, k) => {
|
|
1033
|
+
e.set_text(G, W), e.set_text(E, _), e.set_text(H, b), e.set_text(P, k);
|
|
1034
|
+
},
|
|
1035
|
+
[
|
|
1036
|
+
() => v("commonDelete"),
|
|
1037
|
+
() => v("confirmDeleteChat"),
|
|
1038
|
+
() => v("commonCancel"),
|
|
1039
|
+
() => v("commonDelete")
|
|
1040
|
+
]
|
|
1041
|
+
), e.delegated("click", A, () => e.set(K, null)), e.delegated("click", O, ze), e.append(a, n);
|
|
1042
|
+
};
|
|
1043
|
+
e.if(Ke, (a) => {
|
|
1044
|
+
e.get(K) && a(pt);
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
var _t = e.sibling(Ke, 2);
|
|
1048
|
+
{
|
|
1049
|
+
var bt = (a) => {
|
|
1050
|
+
var n = na(), c = e.child(n), L = e.child(c), G = e.only_child(L, !0), z = e.sibling(L, 2);
|
|
1051
|
+
e.remove_input_defaults(z);
|
|
1052
|
+
var E = e.sibling(z, 2), f = e.child(E), A = e.only_child(f, !0), H = e.sibling(f, 2), O = e.only_child(H, !0);
|
|
1053
|
+
e.reset(E), e.reset(c), e.reset(n), e.template_effect(
|
|
1054
|
+
(P, W, _, b) => {
|
|
1055
|
+
e.set_text(G, P), e.set_attribute(z, "placeholder", W), e.set_text(A, _), e.set_text(O, b);
|
|
1056
|
+
},
|
|
1057
|
+
[
|
|
1058
|
+
() => v("renameChat"),
|
|
1059
|
+
() => v("renameChatPlaceholder"),
|
|
1060
|
+
() => v("commonCancel"),
|
|
1061
|
+
() => v("commonSave")
|
|
1062
|
+
]
|
|
1063
|
+
), e.delegated("keydown", z, (P) => {
|
|
1064
|
+
P.key === "Enter" && Ce();
|
|
1065
|
+
}), e.bind_value(z, () => e.get(re), (P) => e.set(re, P)), e.delegated("click", f, () => {
|
|
1066
|
+
e.set(ee, null), e.set(re, "");
|
|
1067
|
+
}), e.delegated("click", H, Ce), e.append(a, n);
|
|
1068
|
+
};
|
|
1069
|
+
e.if(_t, (a) => {
|
|
1070
|
+
e.get(ee) && a(bt);
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
e.reset(_e), e.template_effect(() => {
|
|
1074
|
+
e.set_class(_e, 1, e.clsx(r.chatShellClass)), e.set_style(_e, r.chatShellStyle);
|
|
1075
|
+
}), e.append(t, _e), e.pop();
|
|
1076
|
+
}
|
|
1077
|
+
e.delegate(["click", "keydown", "pointerdown"]);
|
|
1078
|
+
const xa = "0.3.1";
|
|
1079
|
+
export {
|
|
1080
|
+
Sa as SVEDA_APPEARANCE_PRESETS,
|
|
1081
|
+
Ma as SVEDA_APPEARANCE_PRESET_IDS,
|
|
1082
|
+
Ta as SVEDA_APPEARANCE_STYLE_ID,
|
|
1083
|
+
ka as SVEDA_CHAT_MINIMIZED_STORAGE_KEY,
|
|
1084
|
+
nt as SVEDA_CONTEXT_KEY,
|
|
1085
|
+
Ea as SVEDA_DEFAULT_LAUNCHER_ICON,
|
|
1086
|
+
sr as SVEDA_EMBED_AUTH_EVENT,
|
|
1087
|
+
Aa as SVEDA_LAUNCHER_ICON_IDS,
|
|
1088
|
+
Ia as SVEDA_LAUNCHER_IMAGE_MAX_BYTES,
|
|
1089
|
+
Ha as SVEDA_LAUNCHER_IMAGE_MAX_CHARS,
|
|
1090
|
+
xa as SVEDA_SVELTE_VERSION,
|
|
1091
|
+
za as SVEDA_TOKEN_KEYS,
|
|
1092
|
+
ba as SvedaChat,
|
|
1093
|
+
_a as SvedaProvider,
|
|
1094
|
+
Ye as applySvedaAppearance,
|
|
1095
|
+
Da as buildAppearanceCss,
|
|
1096
|
+
La as buildChatTabTitleMap,
|
|
1097
|
+
ot as createSveda,
|
|
1098
|
+
ma as createSvedaContext,
|
|
1099
|
+
ir as createSvedaI18n,
|
|
1100
|
+
Pa as deriveProvisionalChatTitle,
|
|
1101
|
+
Na as finalizeMessagesForDisplay,
|
|
1102
|
+
Ra as formatRadiusPx,
|
|
1103
|
+
lr as getDefaultSvedaConfig,
|
|
1104
|
+
Oa as getSvedaModelDisplayName,
|
|
1105
|
+
Fa as getUserMessageAttachmentNames,
|
|
1106
|
+
Ua as getUserMessageText,
|
|
1107
|
+
Va as hexToHsl,
|
|
1108
|
+
ja as hslToHex,
|
|
1109
|
+
Ba as humanizeModelId,
|
|
1110
|
+
Ya as isChatTitlePlaceholder,
|
|
1111
|
+
Wa as isNewChatPlaceholder,
|
|
1112
|
+
Xa as isPersistedSessionChatOpen,
|
|
1113
|
+
Ga as isSvedaAppearanceProvided,
|
|
1114
|
+
qa as isSvedaHsl,
|
|
1115
|
+
Ka as mergeSvedaAppearance,
|
|
1116
|
+
Ja as parseRadiusPx,
|
|
1117
|
+
Qa as readPersistedMinimized,
|
|
1118
|
+
Za as readPersistedMinimizedPreference,
|
|
1119
|
+
$a as resolveSvedaAppearance,
|
|
1120
|
+
ei as sanitizeSvedaChrome,
|
|
1121
|
+
ti as sanitizeSvedaLauncher,
|
|
1122
|
+
ri as sanitizeSvedaLauncherImage,
|
|
1123
|
+
ai as sanitizeSvedaRadius,
|
|
1124
|
+
ii as sanitizeSvedaTheme,
|
|
1125
|
+
lt as setSvedaContext,
|
|
1126
|
+
Be as svedaChrome,
|
|
1127
|
+
Ee as svedaLauncher,
|
|
1128
|
+
wr as useSvedaChat,
|
|
1129
|
+
ga as useSvedaChrome,
|
|
1130
|
+
pa as useSvedaClient,
|
|
1131
|
+
dr as useSvedaConfig,
|
|
1132
|
+
ge as useSvedaContext,
|
|
1133
|
+
ar as useSvedaLauncher,
|
|
1134
|
+
yr as useSvedaStreaming,
|
|
1135
|
+
Ae as useSvedaT,
|
|
1136
|
+
si as userMessageHasVisibleContent,
|
|
1137
|
+
ni as writePersistedMinimized
|
|
1138
|
+
};
|