@gauravrathod674/super-customizable-chatbot 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -1
- package/dist/style.css +1 -1
- package/dist/super-customizable-chatbot.es.js +623 -421
- package/dist/super-customizable-chatbot.umd.js +18 -12
- package/package.json +1 -1
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { AnimatePresence as
|
|
4
|
-
import { FontAwesomeIcon as
|
|
5
|
-
import { faCommentDots as Ie } from "@fortawesome/free-solid-svg-icons";
|
|
6
|
-
import { GoogleGenerativeAI as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
const
|
|
1
|
+
import { jsx as t, jsxs as u, Fragment as He } from "react/jsx-runtime";
|
|
2
|
+
import { useState as R, useRef as j, useMemo as S, useEffect as $, useCallback as Te } from "react";
|
|
3
|
+
import { AnimatePresence as V, motion as x } from "framer-motion";
|
|
4
|
+
import { FontAwesomeIcon as B } from "@fortawesome/react-fontawesome";
|
|
5
|
+
import { faCommentDots as Ge, faFileAlt as Ie, faPaperclip as qe, faMicrophoneSlash as Ve, faMicrophone as _e, faTimes as Ye } from "@fortawesome/free-solid-svg-icons";
|
|
6
|
+
import { GoogleGenerativeAI as Ze } from "@google/generative-ai";
|
|
7
|
+
import Xe from "openai";
|
|
8
|
+
import Je from "@anthropic-ai/sdk";
|
|
9
|
+
import Ke from "groq-sdk";
|
|
10
|
+
import F from "react-markdown";
|
|
11
|
+
const se = (n) => new Promise((c, h) => {
|
|
12
|
+
const a = new FileReader();
|
|
13
|
+
a.readAsDataURL(n), a.onload = () => c(a.result.split(",")[1]), a.onerror = (g) => h(g);
|
|
14
|
+
}), Qe = () => /* @__PURE__ */ u(
|
|
12
15
|
"svg",
|
|
13
16
|
{
|
|
14
17
|
viewBox: "0 0 24 24",
|
|
@@ -17,19 +20,19 @@ const Le = () => /* @__PURE__ */ u(
|
|
|
17
20
|
strokeWidth: "1.5",
|
|
18
21
|
className: "w-full h-full",
|
|
19
22
|
children: [
|
|
20
|
-
/* @__PURE__ */
|
|
21
|
-
/* @__PURE__ */
|
|
23
|
+
/* @__PURE__ */ t("path", { d: "M12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4Z" }),
|
|
24
|
+
/* @__PURE__ */ t(
|
|
22
25
|
"path",
|
|
23
26
|
{
|
|
24
27
|
d: "M16.5 14C16.5 14 15 15.5 12 15.5C9 15.5 7.5 14 7.5 14",
|
|
25
28
|
strokeLinecap: "round"
|
|
26
29
|
}
|
|
27
30
|
),
|
|
28
|
-
/* @__PURE__ */
|
|
29
|
-
/* @__PURE__ */
|
|
31
|
+
/* @__PURE__ */ t("circle", { cx: "9", cy: "10", r: "1", fill: "currentColor" }),
|
|
32
|
+
/* @__PURE__ */ t("circle", { cx: "15", cy: "10", r: "1", fill: "currentColor" })
|
|
30
33
|
]
|
|
31
34
|
}
|
|
32
|
-
),
|
|
35
|
+
), et = () => /* @__PURE__ */ u(
|
|
33
36
|
"svg",
|
|
34
37
|
{
|
|
35
38
|
viewBox: "0 0 24 24",
|
|
@@ -38,14 +41,14 @@ const Le = () => /* @__PURE__ */ u(
|
|
|
38
41
|
strokeWidth: "1.5",
|
|
39
42
|
className: "w-full h-full",
|
|
40
43
|
children: [
|
|
41
|
-
/* @__PURE__ */
|
|
44
|
+
/* @__PURE__ */ t(
|
|
42
45
|
"path",
|
|
43
46
|
{
|
|
44
47
|
d: "M12 12C14.2091 12 16 10.2091 16 8C16 5.79086 14.2091 4 12 4C9.79086 4 8 5.79086 8 8C8 10.2091 9.79086 12 12 12Z",
|
|
45
48
|
strokeLinecap: "round"
|
|
46
49
|
}
|
|
47
50
|
),
|
|
48
|
-
/* @__PURE__ */
|
|
51
|
+
/* @__PURE__ */ t(
|
|
49
52
|
"path",
|
|
50
53
|
{
|
|
51
54
|
d: "M19.21 17.14C19.21 17.14 19 19 12 19C5 19 4.79 17.14 4.79 17.14C4.79 17.14 6.33 15 12 15C17.67 15 19.21 17.14 19.21 17.14Z",
|
|
@@ -54,7 +57,7 @@ const Le = () => /* @__PURE__ */ u(
|
|
|
54
57
|
)
|
|
55
58
|
]
|
|
56
59
|
}
|
|
57
|
-
),
|
|
60
|
+
), tt = () => /* @__PURE__ */ u(
|
|
58
61
|
"svg",
|
|
59
62
|
{
|
|
60
63
|
fill: "none",
|
|
@@ -63,7 +66,7 @@ const Le = () => /* @__PURE__ */ u(
|
|
|
63
66
|
stroke: "currentColor",
|
|
64
67
|
className: "w-5 h-5",
|
|
65
68
|
children: [
|
|
66
|
-
/* @__PURE__ */
|
|
69
|
+
/* @__PURE__ */ t(
|
|
67
70
|
"path",
|
|
68
71
|
{
|
|
69
72
|
strokeLinecap: "round",
|
|
@@ -71,155 +74,195 @@ const Le = () => /* @__PURE__ */ u(
|
|
|
71
74
|
d: "M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.875L6 12z"
|
|
72
75
|
}
|
|
73
76
|
),
|
|
74
|
-
/* @__PURE__ */
|
|
77
|
+
/* @__PURE__ */ t("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 12h9" })
|
|
75
78
|
]
|
|
76
79
|
}
|
|
77
|
-
),
|
|
78
|
-
/* @__PURE__ */
|
|
79
|
-
/* @__PURE__ */
|
|
80
|
-
/* @__PURE__ */
|
|
81
|
-
] }),
|
|
82
|
-
const
|
|
83
|
-
return
|
|
80
|
+
), ot = () => /* @__PURE__ */ u("div", { className: "flex items-center space-x-1 p-3", children: [
|
|
81
|
+
/* @__PURE__ */ t("div", { className: "w-2 h-2 bg-gray-400 rounded-full animate-pulse [animation-delay:-0.3s]" }),
|
|
82
|
+
/* @__PURE__ */ t("div", { className: "w-2 h-2 bg-gray-400 rounded-full animate-pulse [animation-delay:-0.15s]" }),
|
|
83
|
+
/* @__PURE__ */ t("div", { className: "w-2 h-2 bg-gray-400 rounded-full animate-pulse" })
|
|
84
|
+
] }), rt = ({ file: n, onRemove: c }) => {
|
|
85
|
+
const [h, a] = R(null);
|
|
86
|
+
return $(() => {
|
|
87
|
+
if (n && n.type.startsWith("image/")) {
|
|
88
|
+
const g = URL.createObjectURL(n);
|
|
89
|
+
return a(g), () => URL.revokeObjectURL(g);
|
|
90
|
+
}
|
|
91
|
+
a(null);
|
|
92
|
+
}, [n]), n ? /* @__PURE__ */ u("div", { className: "relative inline-flex items-center gap-2 p-2 mb-2 bg-[--chatbot-bot-msg-bg] rounded-lg border border-[--chatbot-input-border-color] max-w-xs", children: [
|
|
93
|
+
/* @__PURE__ */ t("div", { className: "flex-shrink-0 w-10 h-10 flex items-center justify-center bg-black/20 rounded-md", children: h ? /* @__PURE__ */ t(
|
|
94
|
+
"img",
|
|
95
|
+
{
|
|
96
|
+
src: h,
|
|
97
|
+
alt: n.name,
|
|
98
|
+
className: "w-full h-full object-cover rounded-md"
|
|
99
|
+
}
|
|
100
|
+
) : /* @__PURE__ */ t(B, { icon: Ie, className: "w-5 h-5 text-white/70" }) }),
|
|
101
|
+
/* @__PURE__ */ t("div", { className: "flex-1 min-w-0 pr-6", children: /* @__PURE__ */ t(
|
|
102
|
+
"p",
|
|
103
|
+
{
|
|
104
|
+
className: "text-sm font-medium text-[--chatbot-input-text-color] truncate",
|
|
105
|
+
title: n.name,
|
|
106
|
+
children: n.name
|
|
107
|
+
}
|
|
108
|
+
) }),
|
|
109
|
+
/* @__PURE__ */ t(
|
|
110
|
+
"button",
|
|
111
|
+
{
|
|
112
|
+
onClick: c,
|
|
113
|
+
"aria-label": "Remove file",
|
|
114
|
+
className: "absolute top-1 right-1 w-2 h-2 flex items-center justify-center rounded-full bg-black/50 text-white hover:bg-black/70 transition-colors",
|
|
115
|
+
children: /* @__PURE__ */ t(B, { icon: Ye, className: "w-3 h-3" })
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
] }) : null;
|
|
119
|
+
}, nt = ({ fullText: n, onComplete: c, components: h }) => {
|
|
120
|
+
const a = typeof n == "string" ? n : "", [g, l] = R("");
|
|
121
|
+
return $(() => {
|
|
84
122
|
if (a.length === 0) {
|
|
85
|
-
|
|
123
|
+
c == null || c();
|
|
86
124
|
return;
|
|
87
125
|
}
|
|
88
|
-
let
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
if (
|
|
92
|
-
const
|
|
93
|
-
|
|
126
|
+
let C = 0;
|
|
127
|
+
l("");
|
|
128
|
+
const m = setInterval(() => {
|
|
129
|
+
if (C < a.length) {
|
|
130
|
+
const v = a.charAt(C);
|
|
131
|
+
l((O) => O + v), C++;
|
|
94
132
|
} else
|
|
95
|
-
clearInterval(
|
|
133
|
+
clearInterval(m), c == null || c();
|
|
96
134
|
}, 25);
|
|
97
|
-
return () => clearInterval(
|
|
98
|
-
}, [a,
|
|
135
|
+
return () => clearInterval(m);
|
|
136
|
+
}, [a, c]), /* @__PURE__ */ t(
|
|
99
137
|
"div",
|
|
100
138
|
{
|
|
101
139
|
className: "prose prose-sm max-w-none text-inherit prose-p:my-0 prose-headings:my-2 prose-ul:my-1 prose-li:my-0.5",
|
|
102
140
|
style: { color: "inherit" },
|
|
103
|
-
children: /* @__PURE__ */
|
|
141
|
+
children: /* @__PURE__ */ t(F, { components: h, children: g || "" })
|
|
104
142
|
}
|
|
105
143
|
);
|
|
106
|
-
},
|
|
144
|
+
}, at = ({ text: n, animationType: c, components: h }) => {
|
|
107
145
|
const a = "prose prose-sm max-w-none text-inherit prose-p:my-0 prose-headings:my-2 prose-ul:my-1 prose-li:my-0.5";
|
|
108
|
-
switch (
|
|
146
|
+
switch (c) {
|
|
109
147
|
case "typing":
|
|
110
|
-
return /* @__PURE__ */
|
|
148
|
+
return /* @__PURE__ */ t(nt, { fullText: n, components: h });
|
|
111
149
|
case "fade-in":
|
|
112
|
-
return /* @__PURE__ */
|
|
113
|
-
|
|
150
|
+
return /* @__PURE__ */ t(
|
|
151
|
+
x.div,
|
|
114
152
|
{
|
|
115
153
|
initial: { opacity: 0, y: 10 },
|
|
116
154
|
animate: { opacity: 1, y: 0 },
|
|
117
155
|
transition: { duration: 1.5, ease: "easeOut" },
|
|
118
|
-
children: /* @__PURE__ */
|
|
156
|
+
children: /* @__PURE__ */ t("div", { className: a, children: /* @__PURE__ */ t(F, { components: h, children: n }) })
|
|
119
157
|
}
|
|
120
158
|
);
|
|
121
159
|
case "slide-up":
|
|
122
|
-
return /* @__PURE__ */
|
|
123
|
-
|
|
160
|
+
return /* @__PURE__ */ t(
|
|
161
|
+
x.div,
|
|
124
162
|
{
|
|
125
163
|
initial: { y: 50, opacity: 0 },
|
|
126
164
|
animate: { y: 0, opacity: 1 },
|
|
127
165
|
transition: { duration: 0.7, ease: "anticipate" },
|
|
128
|
-
children: /* @__PURE__ */
|
|
166
|
+
children: /* @__PURE__ */ t("div", { className: a, children: /* @__PURE__ */ t(F, { components: h, children: n }) })
|
|
129
167
|
}
|
|
130
168
|
);
|
|
131
169
|
case "zoom-in":
|
|
132
|
-
return /* @__PURE__ */
|
|
133
|
-
|
|
170
|
+
return /* @__PURE__ */ t(
|
|
171
|
+
x.div,
|
|
134
172
|
{
|
|
135
173
|
initial: { scale: 0.5, opacity: 0 },
|
|
136
174
|
animate: { scale: 1, opacity: 1 },
|
|
137
175
|
transition: { duration: 1, ease: "backOut" },
|
|
138
|
-
children: /* @__PURE__ */
|
|
176
|
+
children: /* @__PURE__ */ t("div", { className: a, children: /* @__PURE__ */ t(F, { components: h, children: n }) })
|
|
139
177
|
}
|
|
140
178
|
);
|
|
141
179
|
case "flip":
|
|
142
|
-
return /* @__PURE__ */
|
|
143
|
-
|
|
180
|
+
return /* @__PURE__ */ t(
|
|
181
|
+
x.div,
|
|
144
182
|
{
|
|
145
183
|
initial: { rotateX: -90, opacity: 0 },
|
|
146
184
|
animate: { rotateX: 0, opacity: 1 },
|
|
147
185
|
transition: { duration: 1, ease: "easeOut" },
|
|
148
186
|
style: { transformPerspective: 400 },
|
|
149
|
-
children: /* @__PURE__ */
|
|
187
|
+
children: /* @__PURE__ */ t("div", { className: a, children: /* @__PURE__ */ t(F, { components: h, children: n }) })
|
|
150
188
|
}
|
|
151
189
|
);
|
|
152
190
|
default:
|
|
153
|
-
return /* @__PURE__ */
|
|
191
|
+
return /* @__PURE__ */ t("div", { className: a, children: /* @__PURE__ */ t(F, { components: h, children: n }) });
|
|
154
192
|
}
|
|
155
|
-
},
|
|
156
|
-
const
|
|
157
|
-
if (!
|
|
158
|
-
return
|
|
159
|
-
let a =
|
|
160
|
-
const
|
|
161
|
-
if (
|
|
162
|
-
const
|
|
163
|
-
...
|
|
164
|
-
text: `${
|
|
165
|
-
${
|
|
193
|
+
}, st = (n) => {
|
|
194
|
+
const c = [];
|
|
195
|
+
if (!n || n.length === 0)
|
|
196
|
+
return c;
|
|
197
|
+
let a = n.reduce((l, C) => {
|
|
198
|
+
const m = l.length > 0 ? l[l.length - 1] : null;
|
|
199
|
+
if (m && m.sender === C.sender) {
|
|
200
|
+
const v = {
|
|
201
|
+
...m,
|
|
202
|
+
text: `${m.text}
|
|
203
|
+
${C.text}`
|
|
166
204
|
};
|
|
167
|
-
|
|
205
|
+
l[l.length - 1] = v;
|
|
168
206
|
} else
|
|
169
|
-
|
|
170
|
-
return
|
|
171
|
-
}, []).map((
|
|
172
|
-
role:
|
|
173
|
-
parts: [{ text:
|
|
207
|
+
l.push({ ...C });
|
|
208
|
+
return l;
|
|
209
|
+
}, []).map((l) => ({
|
|
210
|
+
role: l.sender === "bot" ? "model" : "user",
|
|
211
|
+
parts: [{ text: l.text }]
|
|
174
212
|
}));
|
|
175
|
-
const
|
|
176
|
-
if (
|
|
177
|
-
a = a.slice(
|
|
213
|
+
const g = a.findIndex((l) => l.role === "user");
|
|
214
|
+
if (g > -1)
|
|
215
|
+
a = a.slice(g);
|
|
178
216
|
else
|
|
179
217
|
return [];
|
|
180
218
|
return a;
|
|
181
|
-
},
|
|
182
|
-
botName:
|
|
183
|
-
botAvatar:
|
|
184
|
-
userAvatar:
|
|
219
|
+
}, gt = ({
|
|
220
|
+
botName: n = "ChatBot",
|
|
221
|
+
botAvatar: c = /* @__PURE__ */ t(Qe, {}),
|
|
222
|
+
userAvatar: h = /* @__PURE__ */ t(et, {}),
|
|
185
223
|
welcomeMessage: a = "Hello! How can I help?",
|
|
186
|
-
placeholderText:
|
|
187
|
-
customInstruction:
|
|
188
|
-
isOpen:
|
|
189
|
-
disabled:
|
|
190
|
-
isTyping:
|
|
191
|
-
onSend:
|
|
224
|
+
placeholderText: g = "Type a message...",
|
|
225
|
+
customInstruction: l = "",
|
|
226
|
+
isOpen: C = !1,
|
|
227
|
+
disabled: m = !1,
|
|
228
|
+
isTyping: v = !1,
|
|
229
|
+
onSend: O = () => {
|
|
192
230
|
},
|
|
193
|
-
theme:
|
|
194
|
-
geminiApiKey:
|
|
195
|
-
geminiModelName:
|
|
196
|
-
openaiApiKey:
|
|
197
|
-
openaiModelName:
|
|
198
|
-
anthropicApiKey:
|
|
199
|
-
anthropicModelName:
|
|
200
|
-
grokApiKey:
|
|
201
|
-
grokModelName:
|
|
202
|
-
messages:
|
|
231
|
+
theme: k = {},
|
|
232
|
+
geminiApiKey: _,
|
|
233
|
+
geminiModelName: ie = "gemini-1.5-flash",
|
|
234
|
+
openaiApiKey: Y,
|
|
235
|
+
openaiModelName: le = "gpt-4o-mini",
|
|
236
|
+
anthropicApiKey: Z,
|
|
237
|
+
anthropicModelName: ce = "claude-3-haiku-20240307",
|
|
238
|
+
grokApiKey: X,
|
|
239
|
+
grokModelName: de = "llama3-8b-8192",
|
|
240
|
+
messages: ue,
|
|
241
|
+
googleSTTCredentialsPath: Se,
|
|
242
|
+
enableFileUpload: Be = !1,
|
|
243
|
+
fileUploadAccept: Fe = "*",
|
|
244
|
+
onFileUpload: Le = () => {
|
|
245
|
+
}
|
|
203
246
|
}) => {
|
|
204
|
-
const [
|
|
247
|
+
const [w] = R(
|
|
205
248
|
() => `chatbot-instance-${Math.random().toString(36).substring(2, 9)}`
|
|
206
|
-
), [
|
|
207
|
-
} :
|
|
208
|
-
if (!
|
|
249
|
+
), [I, P] = R(C), [Me, je] = R(() => a ? [{ id: 1, text: a, sender: "bot" }] : []), [L, U] = R(""), [D, W] = R(!1), [J, he] = R(!1), [f, E] = R(null), H = typeof ue < "u", T = H ? ue : Me, K = H ? () => {
|
|
250
|
+
} : je, Q = j(null), be = j(null), me = j(null), ze = j(null), fe = j(null), z = j(null), ee = S(() => {
|
|
251
|
+
if (!_) return null;
|
|
209
252
|
try {
|
|
210
|
-
return new
|
|
211
|
-
model:
|
|
212
|
-
systemInstruction:
|
|
253
|
+
return new Ze(_).getGenerativeModel({
|
|
254
|
+
model: ie,
|
|
255
|
+
systemInstruction: l
|
|
213
256
|
});
|
|
214
|
-
} catch (
|
|
215
|
-
return console.error("Failed to initialize Gemini:",
|
|
257
|
+
} catch (e) {
|
|
258
|
+
return console.error("Failed to initialize Gemini:", e), null;
|
|
216
259
|
}
|
|
217
|
-
}, [
|
|
218
|
-
apiKey:
|
|
260
|
+
}, [_, ie, l]), te = S(() => Y ? new Xe({ apiKey: Y, dangerouslyAllowBrowser: !0 }) : null, [Y]), oe = S(() => Z ? new Je({
|
|
261
|
+
apiKey: Z,
|
|
219
262
|
dangerouslyAllowBrowser: !0
|
|
220
|
-
}) : null, [
|
|
221
|
-
var
|
|
222
|
-
const
|
|
263
|
+
}) : null, [Z]), re = S(() => X ? new Ke({ apiKey: X, dangerouslyAllowBrowser: !0 }) : null, [X]), o = S(() => {
|
|
264
|
+
var s;
|
|
265
|
+
const e = ((s = k == null ? void 0 : k.window) == null ? void 0 : s.placement) === "center", r = {
|
|
223
266
|
launcher: {
|
|
224
267
|
backgroundColor: "#4f46e5",
|
|
225
268
|
iconColor: "#ffffff",
|
|
@@ -255,8 +298,8 @@ ${w.text}`
|
|
|
255
298
|
backgroundColor: "#ffffff",
|
|
256
299
|
borderColor: "#e5e7eb",
|
|
257
300
|
borderRadius: "0.75rem",
|
|
258
|
-
width:
|
|
259
|
-
height:
|
|
301
|
+
width: e ? "80vw" : "22rem",
|
|
302
|
+
height: e ? "80vh" : "30rem",
|
|
260
303
|
placement: "bottom-right",
|
|
261
304
|
backdrop: !1,
|
|
262
305
|
backdropColor: "rgba(0, 0, 0, 0.4)",
|
|
@@ -268,279 +311,310 @@ ${w.text}`
|
|
|
268
311
|
}
|
|
269
312
|
};
|
|
270
313
|
return {
|
|
271
|
-
launcher: { ...
|
|
272
|
-
header: { ...
|
|
273
|
-
messages: { ...
|
|
274
|
-
input: { ...
|
|
275
|
-
window: { ...
|
|
314
|
+
launcher: { ...r.launcher, ...k.launcher },
|
|
315
|
+
header: { ...r.header, ...k.header },
|
|
316
|
+
messages: { ...r.messages, ...k.messages },
|
|
317
|
+
input: { ...r.input, ...k.input },
|
|
318
|
+
window: { ...r.window, ...k.window }
|
|
276
319
|
};
|
|
277
|
-
}, [
|
|
320
|
+
}, [k]), Ae = S(
|
|
278
321
|
() => ({
|
|
279
322
|
// Launcher
|
|
280
|
-
"--chatbot-launcher-bg":
|
|
281
|
-
"--chatbot-launcher-icon-color":
|
|
282
|
-
"--chatbot-launcher-size":
|
|
323
|
+
"--chatbot-launcher-bg": o.launcher.backgroundColor,
|
|
324
|
+
"--chatbot-launcher-icon-color": o.launcher.iconColor,
|
|
325
|
+
"--chatbot-launcher-size": o.launcher.size,
|
|
283
326
|
// Header
|
|
284
|
-
"--chatbot-header-bg":
|
|
285
|
-
"--chatbot-header-text-color":
|
|
286
|
-
"--chatbot-header-font-family":
|
|
287
|
-
"--chatbot-header-font-weight":
|
|
327
|
+
"--chatbot-header-bg": o.header.backgroundColor,
|
|
328
|
+
"--chatbot-header-text-color": o.header.textColor,
|
|
329
|
+
"--chatbot-header-font-family": o.header.fontFamily,
|
|
330
|
+
"--chatbot-header-font-weight": o.header.fontWeight,
|
|
288
331
|
// Messages
|
|
289
|
-
"--chatbot-user-msg-bg":
|
|
290
|
-
"--chatbot-user-msg-text-color":
|
|
291
|
-
"--chatbot-bot-msg-bg":
|
|
292
|
-
"--chatbot-bot-msg-text-color":
|
|
293
|
-
"--chatbot-msg-font-family":
|
|
294
|
-
"--chatbot-msg-font-size":
|
|
332
|
+
"--chatbot-user-msg-bg": o.messages.userBackgroundColor,
|
|
333
|
+
"--chatbot-user-msg-text-color": o.messages.userTextColor,
|
|
334
|
+
"--chatbot-bot-msg-bg": o.messages.botBackgroundColor,
|
|
335
|
+
"--chatbot-bot-msg-text-color": o.messages.botTextColor,
|
|
336
|
+
"--chatbot-msg-font-family": o.messages.fontFamily,
|
|
337
|
+
"--chatbot-msg-font-size": o.messages.fontSize,
|
|
295
338
|
// Input
|
|
296
|
-
"--chatbot-input-bg":
|
|
297
|
-
"--chatbot-input-text-color":
|
|
298
|
-
"--chatbot-input-placeholder-color":
|
|
299
|
-
"--chatbot-input-border-color":
|
|
300
|
-
"--chatbot-input-focus-ring":
|
|
339
|
+
"--chatbot-input-bg": o.input.backgroundColor,
|
|
340
|
+
"--chatbot-input-text-color": o.input.textColor,
|
|
341
|
+
"--chatbot-input-placeholder-color": o.input.placeholderTextColor,
|
|
342
|
+
"--chatbot-input-border-color": o.input.borderColor,
|
|
343
|
+
"--chatbot-input-focus-ring": o.input.focusRingColor,
|
|
301
344
|
// Window
|
|
302
|
-
"--chatbot-window-bg":
|
|
303
|
-
"--chatbot-window-border-color":
|
|
304
|
-
"--chatbot-window-border-radius":
|
|
305
|
-
"--chatbot-window-width":
|
|
306
|
-
"--chatbot-window-height":
|
|
345
|
+
"--chatbot-window-bg": o.window.backgroundColor,
|
|
346
|
+
"--chatbot-window-border-color": o.window.borderColor,
|
|
347
|
+
"--chatbot-window-border-radius": o.window.borderRadius,
|
|
348
|
+
"--chatbot-window-width": o.window.width,
|
|
349
|
+
"--chatbot-window-height": o.window.height
|
|
307
350
|
}),
|
|
308
|
-
[
|
|
309
|
-
),
|
|
310
|
-
const
|
|
351
|
+
[o]
|
|
352
|
+
), pe = S(() => {
|
|
353
|
+
const e = o.messages.markdownStyles || {};
|
|
311
354
|
return {
|
|
312
|
-
strong: ({ node:
|
|
313
|
-
em: ({ node:
|
|
314
|
-
a: ({ node:
|
|
315
|
-
code: ({ node:
|
|
355
|
+
strong: ({ node: r, ...s }) => /* @__PURE__ */ t("strong", { style: { color: e.boldColor || "inherit" }, ...s }),
|
|
356
|
+
em: ({ node: r, ...s }) => /* @__PURE__ */ t("em", { style: { color: e.italicColor || "inherit" }, ...s }),
|
|
357
|
+
a: ({ node: r, ...s }) => /* @__PURE__ */ t("a", { style: { color: e.linkColor || "#3b82f6" }, ...s }),
|
|
358
|
+
code: ({ node: r, ...s }) => /* @__PURE__ */ t(
|
|
316
359
|
"code",
|
|
317
360
|
{
|
|
318
361
|
style: {
|
|
319
|
-
color:
|
|
320
|
-
backgroundColor:
|
|
362
|
+
color: e.codeColor || "inherit",
|
|
363
|
+
backgroundColor: e.codeBackgroundColor || "rgba(0, 0, 0, 0.1)",
|
|
321
364
|
padding: "0.1rem 0.3rem",
|
|
322
365
|
borderRadius: "0.25rem"
|
|
323
366
|
},
|
|
324
|
-
...
|
|
367
|
+
...s
|
|
325
368
|
}
|
|
326
369
|
)
|
|
327
370
|
};
|
|
328
|
-
}, [
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
371
|
+
}, [o.messages.markdownStyles]);
|
|
372
|
+
$(() => {
|
|
373
|
+
const e = window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
374
|
+
if (e) {
|
|
375
|
+
const r = new e();
|
|
376
|
+
r.continuous = !0, r.interimResults = !1, r.lang = "en-US", r.onstart = () => he(!0), r.onresult = (s) => {
|
|
377
|
+
const i = s.results[s.results.length - 1][0].transcript;
|
|
378
|
+
U((d) => d + (d ? " " : "") + i);
|
|
379
|
+
}, r.onerror = (s) => {
|
|
380
|
+
console.error("Speech error:", s);
|
|
381
|
+
}, r.onend = () => {
|
|
382
|
+
}, z.current = r;
|
|
383
|
+
}
|
|
384
|
+
}, []), $(() => {
|
|
385
|
+
var d;
|
|
386
|
+
const e = o.window.scrollbarThumbColor, r = o.window.scrollbarTrackColor, s = `scrollbar-style-${w}`;
|
|
387
|
+
(d = document.getElementById(s)) == null || d.remove();
|
|
388
|
+
const i = document.createElement("style");
|
|
389
|
+
return i.id = s, i.innerHTML = `
|
|
390
|
+
/* Target both the message list and the textarea input */
|
|
391
|
+
#${w} .chatbot-message-list,
|
|
392
|
+
#${w} .chatbot-textarea-input {
|
|
337
393
|
scrollbar-width: thin;
|
|
338
|
-
scrollbar-color: ${
|
|
394
|
+
scrollbar-color: ${e} ${r};
|
|
339
395
|
}
|
|
340
396
|
/* WebKit-based browsers (Chrome, Safari, Edge) */
|
|
341
|
-
#${
|
|
397
|
+
#${w} .chatbot-message-list::-webkit-scrollbar,
|
|
398
|
+
#${w} .chatbot-textarea-input::-webkit-scrollbar {
|
|
342
399
|
width: 8px;
|
|
343
400
|
}
|
|
344
|
-
#${
|
|
345
|
-
|
|
401
|
+
#${w} .chatbot-message-list::-webkit-scrollbar-track,
|
|
402
|
+
#${w} .chatbot-textarea-input::-webkit-scrollbar-track {
|
|
403
|
+
background: ${r};
|
|
346
404
|
border-radius: 4px;
|
|
347
405
|
}
|
|
348
|
-
#${
|
|
349
|
-
|
|
406
|
+
#${w} .chatbot-message-list::-webkit-scrollbar-thumb,
|
|
407
|
+
#${w} .chatbot-textarea-input::-webkit-scrollbar-thumb {
|
|
408
|
+
background-color: ${e};
|
|
350
409
|
border-radius: 4px;
|
|
351
|
-
border: 2px solid ${
|
|
410
|
+
border: 2px solid ${r};
|
|
352
411
|
}
|
|
353
|
-
`, document.head.appendChild(
|
|
354
|
-
var
|
|
355
|
-
(
|
|
412
|
+
`, document.head.appendChild(i), () => {
|
|
413
|
+
var A;
|
|
414
|
+
(A = document.getElementById(s)) == null || A.remove();
|
|
356
415
|
};
|
|
357
416
|
}, [
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
]),
|
|
362
|
-
|
|
363
|
-
}, [
|
|
364
|
-
var
|
|
365
|
-
(
|
|
366
|
-
}, [
|
|
367
|
-
var
|
|
368
|
-
|
|
369
|
-
}, [
|
|
370
|
-
const
|
|
371
|
-
|
|
417
|
+
w,
|
|
418
|
+
o.window.scrollbarThumbColor,
|
|
419
|
+
o.window.scrollbarTrackColor
|
|
420
|
+
]), $(() => {
|
|
421
|
+
W(v);
|
|
422
|
+
}, [v]), $(() => {
|
|
423
|
+
var e;
|
|
424
|
+
(e = be.current) == null || e.scrollIntoView({ behavior: "smooth" });
|
|
425
|
+
}, [T, D, v]), $(() => {
|
|
426
|
+
var e, r;
|
|
427
|
+
I ? (e = Q.current) == null || e.focus() : (r = me.current) == null || r.focus();
|
|
428
|
+
}, [I]), $(() => {
|
|
429
|
+
const e = (r) => {
|
|
430
|
+
r.key === "Escape" && I && P(!1);
|
|
372
431
|
};
|
|
373
|
-
return window.addEventListener("keydown",
|
|
374
|
-
}, [
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
if (
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
432
|
+
return window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e);
|
|
433
|
+
}, [I]), $(() => {
|
|
434
|
+
const e = Q.current;
|
|
435
|
+
if (!e) return;
|
|
436
|
+
e.style.height = "auto", e.style.height = `${e.scrollHeight}px`;
|
|
437
|
+
const s = e.scrollHeight - e.clientHeight > 4;
|
|
438
|
+
e.style.overflowY = s ? "auto" : "hidden";
|
|
439
|
+
}, [L]);
|
|
440
|
+
const ne = Te(async () => {
|
|
441
|
+
var A, we, ye, xe, ve, Ce, ke, Ne, Re, $e;
|
|
442
|
+
const e = L.trim();
|
|
443
|
+
if (!e && !f || m || D || v)
|
|
444
|
+
return;
|
|
445
|
+
const r = f ? {
|
|
446
|
+
name: f.name,
|
|
447
|
+
type: f.type,
|
|
448
|
+
size: f.size,
|
|
449
|
+
// Create a temporary URL for rendering in the message list.
|
|
450
|
+
// This URL is valid for the current browser session.
|
|
451
|
+
previewUrl: f.type.startsWith("image/") ? URL.createObjectURL(f) : null
|
|
452
|
+
} : null, s = {
|
|
453
|
+
id: `user-${Date.now()}`,
|
|
454
|
+
text: e,
|
|
455
|
+
sender: "user",
|
|
456
|
+
// Attach file metadata to the message for potential future use (not displayed).
|
|
457
|
+
attachment: r
|
|
458
|
+
};
|
|
459
|
+
H || K((b) => [...b, s]), O(e, f), U(""), W(!0);
|
|
460
|
+
const i = f;
|
|
461
|
+
E(null);
|
|
462
|
+
let d = "Sorry, an error occurred. Please check the console for details.";
|
|
463
|
+
try {
|
|
464
|
+
if (ee) {
|
|
465
|
+
const b = ee.startChat({
|
|
466
|
+
history: st(T)
|
|
467
|
+
}), p = [e];
|
|
468
|
+
if (i) {
|
|
469
|
+
const y = await se(i);
|
|
470
|
+
p.push({
|
|
471
|
+
inlineData: {
|
|
472
|
+
data: y,
|
|
473
|
+
mimeType: i.type
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
d = await (await (await b.sendMessage(p)).response).text() || "(no response from Gemini)";
|
|
478
|
+
} else if (te) {
|
|
479
|
+
const b = T.map((y) => ({
|
|
480
|
+
role: y.sender === "bot" ? "assistant" : "user",
|
|
481
|
+
content: y.text
|
|
482
|
+
})), p = [{ type: "text", text: e }];
|
|
483
|
+
if (i && i.type.startsWith("image/")) {
|
|
484
|
+
const y = await se(i);
|
|
485
|
+
p.push({
|
|
486
|
+
type: "image_url",
|
|
487
|
+
image_url: { url: `data:${i.type};base64,${y}` }
|
|
488
|
+
});
|
|
489
|
+
} else i && (console.warn(
|
|
490
|
+
"OpenAI integration currently only supports image files. File was ignored."
|
|
491
|
+
), d = "Note: The attached file was not an image and was ignored. ");
|
|
492
|
+
const N = ((xe = (ye = (we = (A = (await te.chat.completions.create({
|
|
493
|
+
model: le,
|
|
408
494
|
messages: [
|
|
409
|
-
...
|
|
410
|
-
|
|
411
|
-
{ role: "user", content: o }
|
|
495
|
+
...b,
|
|
496
|
+
{ role: "user", content: p }
|
|
412
497
|
]
|
|
413
|
-
})).choices) == null ? void 0 :
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
const
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
})), B = ((fe = (be = (await Z.messages.create({
|
|
437
|
-
model: oe,
|
|
438
|
-
system: r,
|
|
439
|
-
// Pass instruction to the dedicated 'system' parameter
|
|
498
|
+
})).choices) == null ? void 0 : A[0]) == null ? void 0 : we.message) == null ? void 0 : ye.content) == null ? void 0 : xe.trim()) || "(no response from OpenAI)";
|
|
499
|
+
d = i && !i.type.startsWith("image/") ? d + N : N;
|
|
500
|
+
} else if (oe) {
|
|
501
|
+
const b = T.map((y) => ({
|
|
502
|
+
role: y.sender === "bot" ? "assistant" : "user",
|
|
503
|
+
content: y.text
|
|
504
|
+
})), p = [{ type: "text", text: e }];
|
|
505
|
+
if (i && i.type.startsWith("image/")) {
|
|
506
|
+
const y = await se(i);
|
|
507
|
+
p.unshift({
|
|
508
|
+
type: "image",
|
|
509
|
+
source: {
|
|
510
|
+
type: "base64",
|
|
511
|
+
media_type: i.type,
|
|
512
|
+
data: y
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
} else i && (console.warn(
|
|
516
|
+
"Anthropic integration currently only supports image files. File was ignored."
|
|
517
|
+
), d = "Note: The attached file was not an image and was ignored. ");
|
|
518
|
+
const N = ((ke = (Ce = (ve = (await oe.messages.create({
|
|
519
|
+
model: ce,
|
|
520
|
+
system: l,
|
|
440
521
|
messages: [
|
|
441
|
-
...
|
|
442
|
-
{ role: "user", content:
|
|
522
|
+
...b,
|
|
523
|
+
{ role: "user", content: p }
|
|
443
524
|
],
|
|
444
525
|
max_tokens: 1024
|
|
445
|
-
})).content[0]) == null ? void 0 :
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
]);
|
|
459
|
-
} finally {
|
|
460
|
-
f(!1);
|
|
461
|
-
}
|
|
462
|
-
} else if (X) {
|
|
463
|
-
f(!0);
|
|
464
|
-
try {
|
|
465
|
-
const n = r ? [{ role: "system", content: r }] : [], i = v.map((p) => ({
|
|
466
|
-
role: p.sender === "bot" ? "assistant" : "user",
|
|
467
|
-
content: p.text
|
|
468
|
-
})), x = ((pe = (ge = (me = (await X.chat.completions.create({
|
|
526
|
+
})).content) == null ? void 0 : ve[0]) == null ? void 0 : Ce.text) == null ? void 0 : ke.trim()) || "(no response from Claude)";
|
|
527
|
+
d = i && !i.type.startsWith("image/") ? d + N : N;
|
|
528
|
+
} else if (re) {
|
|
529
|
+
let b = "";
|
|
530
|
+
i && (console.warn(
|
|
531
|
+
"Groq API does not support file uploads. Sending text only."
|
|
532
|
+
), b = `Note: The attached file was ignored as this AI model does not support file uploads. Here is my response to your text:
|
|
533
|
+
|
|
534
|
+
`);
|
|
535
|
+
const p = T.map((N) => ({
|
|
536
|
+
role: N.sender === "bot" ? "assistant" : "user",
|
|
537
|
+
content: N.text
|
|
538
|
+
})), q = await re.chat.completions.create({
|
|
469
539
|
messages: [
|
|
470
|
-
...
|
|
471
|
-
|
|
472
|
-
{ role: "user", content: o }
|
|
540
|
+
...p,
|
|
541
|
+
{ role: "user", content: e }
|
|
473
542
|
],
|
|
474
|
-
model:
|
|
475
|
-
})
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}
|
|
488
|
-
]);
|
|
489
|
-
} finally {
|
|
490
|
-
f(!1);
|
|
491
|
-
}
|
|
492
|
-
} else z || (f(!0), setTimeout(() => {
|
|
493
|
-
const n = {
|
|
494
|
-
id: Date.now() + 1,
|
|
495
|
-
text: `You said: "${o}"`,
|
|
496
|
-
sender: "bot"
|
|
543
|
+
model: de
|
|
544
|
+
});
|
|
545
|
+
d = b + ((($e = (Re = (Ne = q.choices[0]) == null ? void 0 : Ne.message) == null ? void 0 : Re.content) == null ? void 0 : $e.trim()) || "(no response from Groq)");
|
|
546
|
+
} else
|
|
547
|
+
d = `You said: "${e}"`, i && (d += ` and attached a file named "${i.name}".`), await new Promise((b) => setTimeout(b, 800));
|
|
548
|
+
} catch (b) {
|
|
549
|
+
console.error("ChatBot handleSend Error:", b), d = "An error occurred while processing your request.";
|
|
550
|
+
} finally {
|
|
551
|
+
const b = {
|
|
552
|
+
id: `bot-${Date.now()}`,
|
|
553
|
+
text: d,
|
|
554
|
+
sender: "bot",
|
|
555
|
+
attachment: null
|
|
497
556
|
};
|
|
498
|
-
|
|
499
|
-
}
|
|
557
|
+
K((p) => [...p, b]), W(!1);
|
|
558
|
+
}
|
|
500
559
|
}, [
|
|
501
|
-
|
|
502
|
-
|
|
560
|
+
// Dependency array ensures the function is recreated only when necessary.
|
|
561
|
+
L,
|
|
562
|
+
f,
|
|
563
|
+
m,
|
|
564
|
+
D,
|
|
565
|
+
v,
|
|
566
|
+
H,
|
|
567
|
+
T,
|
|
503
568
|
O,
|
|
504
|
-
|
|
505
|
-
|
|
569
|
+
K,
|
|
570
|
+
E,
|
|
506
571
|
U,
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
X,
|
|
510
|
-
z,
|
|
511
|
-
v,
|
|
512
|
-
m,
|
|
572
|
+
W,
|
|
573
|
+
l,
|
|
513
574
|
ee,
|
|
514
|
-
oe,
|
|
515
575
|
te,
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
576
|
+
oe,
|
|
577
|
+
re,
|
|
578
|
+
le,
|
|
579
|
+
ce,
|
|
580
|
+
de
|
|
581
|
+
]), Oe = Te(
|
|
582
|
+
(e) => {
|
|
583
|
+
e.key === "Enter" && !e.shiftKey && (e.preventDefault(), ne());
|
|
521
584
|
},
|
|
522
|
-
[
|
|
523
|
-
),
|
|
585
|
+
[ne]
|
|
586
|
+
), Pe = () => {
|
|
587
|
+
z.current && !J && z.current.start();
|
|
588
|
+
}, Ue = () => {
|
|
589
|
+
z.current && J && (z.current.stop(), he(!1));
|
|
590
|
+
}, De = () => {
|
|
591
|
+
var e;
|
|
592
|
+
(e = fe.current) == null || e.click();
|
|
593
|
+
}, We = (e) => {
|
|
594
|
+
var s;
|
|
595
|
+
const r = (s = e.target.files) == null ? void 0 : s[0];
|
|
596
|
+
r && (E(r), Le(r)), e.target && (e.target.value = null);
|
|
597
|
+
}, ae = (e) => typeof e == "string" ? /* @__PURE__ */ t(
|
|
524
598
|
"img",
|
|
525
599
|
{
|
|
526
|
-
src:
|
|
600
|
+
src: e,
|
|
527
601
|
alt: "avatar",
|
|
528
602
|
className: "w-8 h-8 rounded-full object-cover"
|
|
529
603
|
}
|
|
530
|
-
) : /* @__PURE__ */
|
|
604
|
+
) : /* @__PURE__ */ t("div", { className: "w-8 h-8 rounded-full text-gray-500", children: e }), G = D || v, ge = {
|
|
531
605
|
"bottom-right": "bottom-5 right-5",
|
|
532
606
|
"bottom-left": "bottom-5 left-5",
|
|
533
607
|
center: "top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2"
|
|
534
|
-
},
|
|
608
|
+
}, Ee = o.window.placement === "center", M = {
|
|
535
609
|
rounded: "rounded-xl",
|
|
536
610
|
square: "rounded-md"
|
|
537
611
|
};
|
|
538
|
-
return /* @__PURE__ */ u("div", { id:
|
|
539
|
-
/* @__PURE__ */
|
|
540
|
-
|
|
612
|
+
return /* @__PURE__ */ u("div", { id: w, style: Ae, className: "font-sans", children: [
|
|
613
|
+
/* @__PURE__ */ t(V, { children: !I && /* @__PURE__ */ t(
|
|
614
|
+
x.button,
|
|
541
615
|
{
|
|
542
|
-
ref:
|
|
543
|
-
onClick: () =>
|
|
616
|
+
ref: me,
|
|
617
|
+
onClick: () => P(!0),
|
|
544
618
|
"aria-label": "Open Chat",
|
|
545
619
|
initial: { scale: 0, opacity: 0 },
|
|
546
620
|
animate: { scale: 1, opacity: 1 },
|
|
@@ -553,34 +627,34 @@ ${w.text}`
|
|
|
553
627
|
width: "var(--chatbot-launcher-size)",
|
|
554
628
|
height: "var(--chatbot-launcher-size)"
|
|
555
629
|
},
|
|
556
|
-
children: /* @__PURE__ */
|
|
630
|
+
children: /* @__PURE__ */ t(B, { icon: Ge })
|
|
557
631
|
}
|
|
558
632
|
) }),
|
|
559
|
-
/* @__PURE__ */ u(
|
|
560
|
-
|
|
561
|
-
|
|
633
|
+
/* @__PURE__ */ u(V, { children: [
|
|
634
|
+
I && Ee && o.window.backdrop && /* @__PURE__ */ t(
|
|
635
|
+
x.div,
|
|
562
636
|
{
|
|
563
637
|
initial: { opacity: 0 },
|
|
564
638
|
animate: { opacity: 1 },
|
|
565
639
|
exit: { opacity: 0 },
|
|
566
640
|
style: {
|
|
567
|
-
backgroundColor:
|
|
568
|
-
backdropFilter: `blur(${
|
|
641
|
+
backgroundColor: o.window.backdropColor,
|
|
642
|
+
backdropFilter: `blur(${o.window.backdropBlur})`,
|
|
569
643
|
// For Safari compatibility
|
|
570
|
-
WebkitBackdropFilter: `blur(${
|
|
644
|
+
WebkitBackdropFilter: `blur(${o.window.backdropBlur})`
|
|
571
645
|
},
|
|
572
646
|
className: "fixed inset-0 z-40",
|
|
573
|
-
onClick: () =>
|
|
647
|
+
onClick: () => P(!1)
|
|
574
648
|
},
|
|
575
649
|
"chatbot-backdrop"
|
|
576
650
|
),
|
|
577
|
-
|
|
651
|
+
I && /* @__PURE__ */ u(
|
|
578
652
|
"div",
|
|
579
653
|
{
|
|
580
|
-
ref:
|
|
654
|
+
ref: ze,
|
|
581
655
|
"aria-modal": "true",
|
|
582
656
|
role: "dialog",
|
|
583
|
-
className: `fixed ${
|
|
657
|
+
className: `fixed ${ge[o.window.placement] || ge["bottom-right"]} z-50 flex flex-col overflow-hidden shadow-2xl border`,
|
|
584
658
|
style: {
|
|
585
659
|
width: "var(--chatbot-window-width)",
|
|
586
660
|
height: "var(--chatbot-window-height)",
|
|
@@ -599,8 +673,8 @@ ${w.text}`
|
|
|
599
673
|
},
|
|
600
674
|
children: [
|
|
601
675
|
/* @__PURE__ */ u("div", { className: "flex items-center space-x-3", children: [
|
|
602
|
-
/* @__PURE__ */
|
|
603
|
-
/* @__PURE__ */
|
|
676
|
+
/* @__PURE__ */ t("div", { className: "w-10 h-10 rounded-full bg-white/30 flex items-center justify-center p-1", children: ae(c) }),
|
|
677
|
+
/* @__PURE__ */ t(
|
|
604
678
|
"span",
|
|
605
679
|
{
|
|
606
680
|
style: {
|
|
@@ -608,17 +682,17 @@ ${w.text}`
|
|
|
608
682
|
fontWeight: "var(--chatbot-header-font-weight)"
|
|
609
683
|
},
|
|
610
684
|
className: "text-lg",
|
|
611
|
-
children:
|
|
685
|
+
children: n
|
|
612
686
|
}
|
|
613
687
|
)
|
|
614
688
|
] }),
|
|
615
|
-
/* @__PURE__ */
|
|
689
|
+
/* @__PURE__ */ t(
|
|
616
690
|
"button",
|
|
617
691
|
{
|
|
618
|
-
onClick: () =>
|
|
692
|
+
onClick: () => P(!1),
|
|
619
693
|
"aria-label": "Close Chat",
|
|
620
694
|
className: "p-1 rounded-full hover:bg-white/20 focus:outline-none focus-visible:ring-2 focus-visible:ring-white",
|
|
621
|
-
children: /* @__PURE__ */
|
|
695
|
+
children: /* @__PURE__ */ t(
|
|
622
696
|
"svg",
|
|
623
697
|
{
|
|
624
698
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -627,7 +701,7 @@ ${w.text}`
|
|
|
627
701
|
strokeWidth: 2,
|
|
628
702
|
stroke: "currentColor",
|
|
629
703
|
className: "w-6 h-6",
|
|
630
|
-
children: /* @__PURE__ */
|
|
704
|
+
children: /* @__PURE__ */ t(
|
|
631
705
|
"path",
|
|
632
706
|
{
|
|
633
707
|
strokeLinecap: "round",
|
|
@@ -649,76 +723,112 @@ ${w.text}`
|
|
|
649
723
|
"aria-live": "polite",
|
|
650
724
|
className: "chatbot-message-list flex-1 p-4 overflow-y-auto space-y-4",
|
|
651
725
|
children: [
|
|
652
|
-
/* @__PURE__ */
|
|
653
|
-
|
|
726
|
+
/* @__PURE__ */ t(V, { initial: !1, children: T.map((e, r) => /* @__PURE__ */ u(
|
|
727
|
+
x.div,
|
|
654
728
|
{
|
|
655
729
|
layout: !0,
|
|
656
730
|
initial: { opacity: 0, y: 20 },
|
|
657
731
|
animate: { opacity: 1, y: 0 },
|
|
658
732
|
exit: { opacity: 0, y: -10 },
|
|
659
733
|
transition: { duration: 0.3, ease: "easeOut" },
|
|
660
|
-
className: `flex items-end max-w-[85%] gap-2 ${
|
|
734
|
+
className: `flex items-end max-w-[85%] gap-2 ${e.sender === "user" ? "ml-auto flex-row-reverse" : "mr-auto"}`,
|
|
661
735
|
children: [
|
|
662
|
-
|
|
663
|
-
|
|
736
|
+
o.messages.showAvatars && /* @__PURE__ */ t("div", { className: "w-7 h-7 rounded-full flex-shrink-0 overflow-hidden", children: ae(
|
|
737
|
+
e.sender === "user" ? h : c
|
|
664
738
|
) }),
|
|
665
|
-
/* @__PURE__ */
|
|
666
|
-
|
|
739
|
+
/* @__PURE__ */ u(
|
|
740
|
+
"div",
|
|
667
741
|
{
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
742
|
+
className: `flex flex-col ${e.sender === "user" ? "items-end" : "items-start"}`,
|
|
743
|
+
children: [
|
|
744
|
+
e.sender === "user" && e.attachment && /* @__PURE__ */ t(
|
|
745
|
+
"div",
|
|
746
|
+
{
|
|
747
|
+
className: `p-2 mb-1 max-w-full self-end ${M[o.messages.bubbleShape] || M.rounded} ${// Add pointer ONLY if there's no text bubble below it
|
|
748
|
+
!e.text && o.messages.bubblePointer ? "rounded-br-none" : ""}`,
|
|
749
|
+
style: {
|
|
750
|
+
backgroundColor: "var(--chatbot-user-msg-bg)",
|
|
751
|
+
color: "var(--chatbot-user-msg-text-color)"
|
|
752
|
+
},
|
|
753
|
+
children: e.attachment.previewUrl ? /* @__PURE__ */ t(
|
|
754
|
+
"img",
|
|
755
|
+
{
|
|
756
|
+
src: e.attachment.previewUrl,
|
|
757
|
+
alt: e.attachment.name,
|
|
758
|
+
className: "w-full h-auto object-cover rounded-md max-w-[200px]"
|
|
759
|
+
}
|
|
760
|
+
) : /* @__PURE__ */ u("div", { className: "flex items-center gap-2 text-sm", children: [
|
|
761
|
+
/* @__PURE__ */ t(
|
|
762
|
+
B,
|
|
763
|
+
{
|
|
764
|
+
icon: Ie,
|
|
765
|
+
className: "w-4 h-4 flex-shrink-0"
|
|
766
|
+
}
|
|
767
|
+
),
|
|
768
|
+
/* @__PURE__ */ t("span", { className: "truncate", children: e.attachment.name })
|
|
769
|
+
] })
|
|
770
|
+
}
|
|
771
|
+
),
|
|
772
|
+
e.text && /* @__PURE__ */ t(
|
|
773
|
+
x.div,
|
|
774
|
+
{
|
|
775
|
+
layout: "position",
|
|
776
|
+
transition: { duration: 0.2, ease: "easeOut" },
|
|
777
|
+
className: `px-3 py-2 ${M[o.messages.bubbleShape] || M.rounded} ${// The text bubble always gets the pointer if it exists
|
|
778
|
+
o.messages.bubblePointer ? e.sender === "user" ? "rounded-br-none" : "rounded-bl-none" : ""}`,
|
|
779
|
+
style: {
|
|
780
|
+
backgroundColor: e.sender === "user" ? "var(--chatbot-user-msg-bg)" : "var(--chatbot-bot-msg-bg)",
|
|
781
|
+
color: e.sender === "user" ? "var(--chatbot-user-msg-text-color)" : "var(--chatbot-bot-msg-text-color)",
|
|
782
|
+
fontFamily: "var(--chatbot-msg-font-family)",
|
|
783
|
+
fontSize: "var(--chatbot-msg-font-size)"
|
|
784
|
+
},
|
|
785
|
+
children: e.sender === "bot" && r === T.length - 1 ? /* @__PURE__ */ t(
|
|
786
|
+
at,
|
|
787
|
+
{
|
|
788
|
+
text: e.text,
|
|
789
|
+
animationType: o.messages.animation,
|
|
790
|
+
components: pe
|
|
791
|
+
}
|
|
792
|
+
) : /* @__PURE__ */ t(
|
|
793
|
+
"div",
|
|
794
|
+
{
|
|
795
|
+
className: "prose prose-sm max-w-none text-inherit prose-p:my-0",
|
|
796
|
+
style: { color: "inherit" },
|
|
797
|
+
children: /* @__PURE__ */ t(F, { components: pe, children: e.text })
|
|
798
|
+
}
|
|
799
|
+
)
|
|
800
|
+
}
|
|
801
|
+
)
|
|
802
|
+
]
|
|
692
803
|
}
|
|
693
804
|
)
|
|
694
805
|
]
|
|
695
806
|
},
|
|
696
|
-
|
|
807
|
+
e.id
|
|
697
808
|
)) }),
|
|
698
|
-
|
|
809
|
+
G && /* @__PURE__ */ u(
|
|
699
810
|
"div",
|
|
700
811
|
{
|
|
701
812
|
className: "flex items-end max-w-[85%] gap-2 mr-auto",
|
|
702
813
|
children: [
|
|
703
|
-
" ",
|
|
704
|
-
|
|
705
|
-
/* @__PURE__ */ e(
|
|
814
|
+
o.messages.showAvatars && /* @__PURE__ */ t("div", { className: "w-7 h-7 rounded-full flex-shrink-0 overflow-hidden", children: ae(c) }),
|
|
815
|
+
/* @__PURE__ */ t(
|
|
706
816
|
"div",
|
|
707
817
|
{
|
|
708
|
-
className: `px-3 py-2 ${
|
|
818
|
+
className: `px-3 py-2 ${M[o.messages.bubbleShape] || M.rounded} rounded-bl-none`,
|
|
709
819
|
style: { backgroundColor: "var(--chatbot-bot-msg-bg)" },
|
|
710
|
-
children: /* @__PURE__ */
|
|
820
|
+
children: /* @__PURE__ */ t(ot, {})
|
|
711
821
|
}
|
|
712
822
|
)
|
|
713
823
|
]
|
|
714
824
|
},
|
|
715
825
|
"typing-indicator"
|
|
716
826
|
),
|
|
717
|
-
/* @__PURE__ */
|
|
827
|
+
/* @__PURE__ */ t("div", { ref: be })
|
|
718
828
|
]
|
|
719
829
|
}
|
|
720
830
|
),
|
|
721
|
-
/* @__PURE__ */
|
|
831
|
+
/* @__PURE__ */ u(
|
|
722
832
|
"footer",
|
|
723
833
|
{
|
|
724
834
|
className: "p-3 border-t flex-shrink-0",
|
|
@@ -726,42 +836,134 @@ ${w.text}`
|
|
|
726
836
|
borderColor: "var(--chatbot-window-border-color)",
|
|
727
837
|
backgroundColor: "var(--chatbot-input-bg)"
|
|
728
838
|
},
|
|
729
|
-
children:
|
|
730
|
-
/* @__PURE__ */
|
|
731
|
-
|
|
732
|
-
{
|
|
733
|
-
ref: ne,
|
|
734
|
-
type: "text",
|
|
735
|
-
value: F,
|
|
736
|
-
onChange: (o) => se(o.target.value),
|
|
737
|
-
onKeyPress: ke,
|
|
738
|
-
placeholder: $,
|
|
739
|
-
disabled: h || J,
|
|
740
|
-
"aria-label": "Chat input",
|
|
741
|
-
className: "flex-1 w-full px-4 py-2 bg-transparent rounded-full border focus:outline-none focus:ring-2 disabled:cursor-not-allowed disabled:opacity-60",
|
|
742
|
-
style: {
|
|
743
|
-
color: "var(--chatbot-input-text-color)",
|
|
744
|
-
borderColor: "var(--chatbot-input-border-color)",
|
|
745
|
-
"--tw-ring-color": "var(--chatbot-input-focus-ring)"
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
),
|
|
749
|
-
/* @__PURE__ */ e(
|
|
750
|
-
"button",
|
|
839
|
+
children: [
|
|
840
|
+
/* @__PURE__ */ t(V, { children: f && /* @__PURE__ */ t(
|
|
841
|
+
x.div,
|
|
751
842
|
{
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
backgroundColor: "var(--chatbot-user-msg-bg)",
|
|
758
|
-
color: "var(--chatbot-user-msg-text-color)",
|
|
759
|
-
"--tw-ring-color": "var(--chatbot-user-msg-bg)"
|
|
760
|
-
},
|
|
761
|
-
children: /* @__PURE__ */ e(Ae, {})
|
|
843
|
+
initial: { opacity: 0, height: 0 },
|
|
844
|
+
animate: { opacity: 1, height: "auto" },
|
|
845
|
+
exit: { opacity: 0, height: 0 },
|
|
846
|
+
transition: { duration: 0.2 },
|
|
847
|
+
children: /* @__PURE__ */ t(rt, { file: f, onRemove: () => E(null) })
|
|
762
848
|
}
|
|
763
|
-
)
|
|
764
|
-
|
|
849
|
+
) }),
|
|
850
|
+
/* @__PURE__ */ u("div", { className: "flex items-end space-x-2", children: [
|
|
851
|
+
Be && /* @__PURE__ */ u(He, { children: [
|
|
852
|
+
/* @__PURE__ */ t(
|
|
853
|
+
"button",
|
|
854
|
+
{
|
|
855
|
+
onClick: De,
|
|
856
|
+
disabled: m || G,
|
|
857
|
+
"aria-label": "Upload File",
|
|
858
|
+
className: "w-10 h-10 rounded-full flex items-center justify-center flex-shrink-0 transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed",
|
|
859
|
+
style: {
|
|
860
|
+
backgroundColor: "var(--chatbot-user-msg-bg)",
|
|
861
|
+
color: "var(--chatbot-user-msg-text-color)",
|
|
862
|
+
"--tw-ring-color": "var(--chatbot-user-msg-bg)"
|
|
863
|
+
},
|
|
864
|
+
children: /* @__PURE__ */ t(B, { icon: qe, className: "w-5 h-5" })
|
|
865
|
+
}
|
|
866
|
+
),
|
|
867
|
+
/* @__PURE__ */ t(
|
|
868
|
+
"input",
|
|
869
|
+
{
|
|
870
|
+
type: "file",
|
|
871
|
+
ref: fe,
|
|
872
|
+
onChange: We,
|
|
873
|
+
accept: Fe,
|
|
874
|
+
style: { display: "none" },
|
|
875
|
+
"aria-hidden": "true"
|
|
876
|
+
}
|
|
877
|
+
)
|
|
878
|
+
] }),
|
|
879
|
+
/* @__PURE__ */ t(
|
|
880
|
+
"textarea",
|
|
881
|
+
{
|
|
882
|
+
ref: Q,
|
|
883
|
+
rows: "1",
|
|
884
|
+
value: L,
|
|
885
|
+
onChange: (e) => U(e.target.value),
|
|
886
|
+
onKeyDown: Oe,
|
|
887
|
+
placeholder: g,
|
|
888
|
+
disabled: m || G,
|
|
889
|
+
"aria-label": "Chat input",
|
|
890
|
+
className: "chatbot-textarea-input flex-1 w-full px-4 py-2 bg-transparent rounded-xl border focus:outline-none focus:ring-2 disabled:cursor-not-allowed disabled:opacity-60 resize-none overflow-hidden",
|
|
891
|
+
style: {
|
|
892
|
+
color: "var(--chatbot-input-text-color)",
|
|
893
|
+
borderColor: "var(--chatbot-input-border-color)",
|
|
894
|
+
"--tw-ring-color": "var(--chatbot-input-focus-ring)",
|
|
895
|
+
maxHeight: "100px",
|
|
896
|
+
// Set a max-height before scrollbar appears
|
|
897
|
+
overflowY: "hidden",
|
|
898
|
+
// Add scrollbar when content exceeds max-height
|
|
899
|
+
lineHeight: "1.5"
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
),
|
|
903
|
+
J ? (
|
|
904
|
+
// 1. ALWAYS show STOP button when recording is active.
|
|
905
|
+
/* @__PURE__ */ t(
|
|
906
|
+
x.button,
|
|
907
|
+
{
|
|
908
|
+
onClick: Ue,
|
|
909
|
+
"aria-label": "Stop Recording",
|
|
910
|
+
className: "px-4 h-10 rounded-full flex items-center justify-center flex-shrink-0 font-semibold text-sm transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed",
|
|
911
|
+
style: {
|
|
912
|
+
backgroundColor: "var(--chatbot-user-msg-bg)",
|
|
913
|
+
color: "var(--chatbot-user-msg-text-color)",
|
|
914
|
+
"--tw-ring-color": "var(--chatbot-user-msg-bg)"
|
|
915
|
+
},
|
|
916
|
+
animate: { opacity: [1, 0.8, 1], scale: [1, 1.1, 1] },
|
|
917
|
+
transition: {
|
|
918
|
+
duration: 1,
|
|
919
|
+
repeat: 1 / 0,
|
|
920
|
+
ease: "easeInOut"
|
|
921
|
+
},
|
|
922
|
+
children: /* @__PURE__ */ t(
|
|
923
|
+
B,
|
|
924
|
+
{
|
|
925
|
+
icon: Ve,
|
|
926
|
+
className: "w-5 h-5"
|
|
927
|
+
}
|
|
928
|
+
)
|
|
929
|
+
}
|
|
930
|
+
)
|
|
931
|
+
) : Se && !L.trim() ? (
|
|
932
|
+
// 2. Show START button ONLY if not recording, STT is enabled, and there is no text.
|
|
933
|
+
/* @__PURE__ */ t(
|
|
934
|
+
x.button,
|
|
935
|
+
{
|
|
936
|
+
onClick: Pe,
|
|
937
|
+
"aria-label": "Start Recording",
|
|
938
|
+
className: "px-4 h-10 rounded-full flex items-center justify-center flex-shrink-0 font-semibold text-sm transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed",
|
|
939
|
+
style: {
|
|
940
|
+
backgroundColor: "var(--chatbot-user-msg-bg)",
|
|
941
|
+
color: "var(--chatbot-user-msg-text-color)",
|
|
942
|
+
"--tw-ring-color": "var(--chatbot-user-msg-bg)"
|
|
943
|
+
},
|
|
944
|
+
children: /* @__PURE__ */ t(B, { icon: _e, className: "w-5 h-5" })
|
|
945
|
+
}
|
|
946
|
+
)
|
|
947
|
+
) : (
|
|
948
|
+
// 3. Otherwise, show the SEND button.
|
|
949
|
+
/* @__PURE__ */ t(
|
|
950
|
+
"button",
|
|
951
|
+
{
|
|
952
|
+
onClick: ne,
|
|
953
|
+
disabled: !L.trim() || m || G,
|
|
954
|
+
"aria-label": "Send Message",
|
|
955
|
+
className: "px-4 h-10 rounded-full flex items-center justify-center flex-shrink-0 font-semibold text-sm transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed",
|
|
956
|
+
style: {
|
|
957
|
+
backgroundColor: "var(--chatbot-user-msg-bg)",
|
|
958
|
+
color: "var(--chatbot-user-msg-text-color)",
|
|
959
|
+
"--tw-ring-color": "var(--chatbot-user-msg-bg)"
|
|
960
|
+
},
|
|
961
|
+
children: /* @__PURE__ */ t(tt, {})
|
|
962
|
+
}
|
|
963
|
+
)
|
|
964
|
+
)
|
|
965
|
+
] })
|
|
966
|
+
]
|
|
765
967
|
}
|
|
766
968
|
)
|
|
767
969
|
]
|
|
@@ -772,5 +974,5 @@ ${w.text}`
|
|
|
772
974
|
] });
|
|
773
975
|
};
|
|
774
976
|
export {
|
|
775
|
-
|
|
977
|
+
gt as ChatBot
|
|
776
978
|
};
|