@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.
@@ -1,14 +1,17 @@
1
- import { jsx as e, jsxs as u } from "react/jsx-runtime";
2
- import { useState as S, useRef as j, useMemo as M, useEffect as D, useCallback as we } from "react";
3
- import { AnimatePresence as Q, motion as C } from "framer-motion";
4
- import { FontAwesomeIcon as $e } from "@fortawesome/react-fontawesome";
5
- import { faCommentDots as Ie } from "@fortawesome/free-solid-svg-icons";
6
- import { GoogleGenerativeAI as Se } from "@google/generative-ai";
7
- import De from "openai";
8
- import ze from "@anthropic-ai/sdk";
9
- import Ee from "groq-sdk";
10
- import T from "react-markdown";
11
- const Le = () => /* @__PURE__ */ u(
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__ */ e("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" }),
21
- /* @__PURE__ */ e(
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__ */ e("circle", { cx: "9", cy: "10", r: "1", fill: "currentColor" }),
29
- /* @__PURE__ */ e("circle", { cx: "15", cy: "10", r: "1", fill: "currentColor" })
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
- ), Re = () => /* @__PURE__ */ u(
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__ */ e(
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__ */ e(
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
- ), Ae = () => /* @__PURE__ */ u(
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__ */ e(
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__ */ e("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 12h9" })
77
+ /* @__PURE__ */ t("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 12h9" })
75
78
  ]
76
79
  }
77
- ), Fe = () => /* @__PURE__ */ u("div", { className: "flex items-center space-x-1 p-3", children: [
78
- /* @__PURE__ */ e("div", { className: "w-2 h-2 bg-gray-400 rounded-full animate-pulse [animation-delay:-0.3s]" }),
79
- /* @__PURE__ */ e("div", { className: "w-2 h-2 bg-gray-400 rounded-full animate-pulse [animation-delay:-0.15s]" }),
80
- /* @__PURE__ */ e("div", { className: "w-2 h-2 bg-gray-400 rounded-full animate-pulse" })
81
- ] }), Oe = ({ fullText: c, onComplete: d, components: b }) => {
82
- const a = typeof c == "string" ? c : "", [$, r] = S("");
83
- return D(() => {
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
- d == null || d();
123
+ c == null || c();
86
124
  return;
87
125
  }
88
- let w = 0;
89
- r("");
90
- const h = setInterval(() => {
91
- if (w < a.length) {
92
- const g = a.charAt(w);
93
- r((R) => R + g), w++;
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(h), d == null || d();
133
+ clearInterval(m), c == null || c();
96
134
  }, 25);
97
- return () => clearInterval(h);
98
- }, [a, d]), /* @__PURE__ */ e(
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__ */ e(T, { components: b, children: $ || "" })
141
+ children: /* @__PURE__ */ t(F, { components: h, children: g || "" })
104
142
  }
105
143
  );
106
- }, Pe = ({ text: c, animationType: d, components: b }) => {
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 (d) {
146
+ switch (c) {
109
147
  case "typing":
110
- return /* @__PURE__ */ e(Oe, { fullText: c, components: b });
148
+ return /* @__PURE__ */ t(nt, { fullText: n, components: h });
111
149
  case "fade-in":
112
- return /* @__PURE__ */ e(
113
- C.div,
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__ */ e("div", { className: a, children: /* @__PURE__ */ e(T, { components: b, children: c }) })
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__ */ e(
123
- C.div,
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__ */ e("div", { className: a, children: /* @__PURE__ */ e(T, { components: b, children: c }) })
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__ */ e(
133
- C.div,
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__ */ e("div", { className: a, children: /* @__PURE__ */ e(T, { components: b, children: c }) })
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__ */ e(
143
- C.div,
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__ */ e("div", { className: a, children: /* @__PURE__ */ e(T, { components: b, children: c }) })
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__ */ e("div", { className: a, children: /* @__PURE__ */ e(T, { components: b, children: c }) });
191
+ return /* @__PURE__ */ t("div", { className: a, children: /* @__PURE__ */ t(F, { components: h, children: n }) });
154
192
  }
155
- }, je = (c) => {
156
- const d = [];
157
- if (!c || c.length === 0)
158
- return d;
159
- let a = c.reduce((r, w) => {
160
- const h = r.length > 0 ? r[r.length - 1] : null;
161
- if (h && h.sender === w.sender) {
162
- const g = {
163
- ...h,
164
- text: `${h.text}
165
- ${w.text}`
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
- r[r.length - 1] = g;
205
+ l[l.length - 1] = v;
168
206
  } else
169
- r.push({ ...w });
170
- return r;
171
- }, []).map((r) => ({
172
- role: r.sender === "bot" ? "model" : "user",
173
- parts: [{ text: r.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 $ = a.findIndex((r) => r.role === "user");
176
- if ($ > -1)
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
- }, Qe = ({
182
- botName: c = "ChatBot",
183
- botAvatar: d = /* @__PURE__ */ e(Le, {}),
184
- userAvatar: b = /* @__PURE__ */ e(Re, {}),
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: $ = "Type a message...",
187
- customInstruction: r = "",
188
- isOpen: w = !1,
189
- disabled: h = !1,
190
- isTyping: g = !1,
191
- onSend: R = () => {
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: y = {},
194
- geminiApiKey: W,
195
- geminiModelName: K = "gemini-1.5-flash",
196
- openaiApiKey: G,
197
- openaiModelName: ee = "gpt-4o-mini",
198
- anthropicApiKey: H,
199
- anthropicModelName: oe = "claude-3-haiku-20240307",
200
- grokApiKey: q,
201
- grokModelName: te = "llama3-8b-8192",
202
- messages: re
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 [k] = S(
247
+ const [w] = R(
205
248
  () => `chatbot-instance-${Math.random().toString(36).substring(2, 9)}`
206
- ), [N, A] = S(w), [ye, xe] = S(() => a ? [{ id: 1, text: a, sender: "bot" }] : []), [F, se] = S(""), [O, f] = S(!1), z = typeof re < "u", v = z ? re : ye, m = z ? () => {
207
- } : xe, ne = j(null), ae = j(null), le = j(null), ve = j(null), U = M(() => {
208
- if (!W) return null;
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 Se(W).getGenerativeModel({
211
- model: K,
212
- systemInstruction: r
253
+ return new Ze(_).getGenerativeModel({
254
+ model: ie,
255
+ systemInstruction: l
213
256
  });
214
- } catch (o) {
215
- return console.error("Failed to initialize Gemini:", o), null;
257
+ } catch (e) {
258
+ return console.error("Failed to initialize Gemini:", e), null;
216
259
  }
217
- }, [W, K, r]), V = M(() => G ? new De({ apiKey: G, dangerouslyAllowBrowser: !0 }) : null, [G]), Z = M(() => H ? new ze({
218
- apiKey: H,
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, [H]), X = M(() => q ? new Ee({ apiKey: q, dangerouslyAllowBrowser: !0 }) : null, [q]), t = M(() => {
221
- var l;
222
- const o = ((l = y == null ? void 0 : y.window) == null ? void 0 : l.placement) === "center", s = {
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: o ? "80vw" : "22rem",
259
- height: o ? "80vh" : "30rem",
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: { ...s.launcher, ...y.launcher },
272
- header: { ...s.header, ...y.header },
273
- messages: { ...s.messages, ...y.messages },
274
- input: { ...s.input, ...y.input },
275
- window: { ...s.window, ...y.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
- }, [y]), Ce = M(
320
+ }, [k]), Ae = S(
278
321
  () => ({
279
322
  // Launcher
280
- "--chatbot-launcher-bg": t.launcher.backgroundColor,
281
- "--chatbot-launcher-icon-color": t.launcher.iconColor,
282
- "--chatbot-launcher-size": t.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": t.header.backgroundColor,
285
- "--chatbot-header-text-color": t.header.textColor,
286
- "--chatbot-header-font-family": t.header.fontFamily,
287
- "--chatbot-header-font-weight": t.header.fontWeight,
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": t.messages.userBackgroundColor,
290
- "--chatbot-user-msg-text-color": t.messages.userTextColor,
291
- "--chatbot-bot-msg-bg": t.messages.botBackgroundColor,
292
- "--chatbot-bot-msg-text-color": t.messages.botTextColor,
293
- "--chatbot-msg-font-family": t.messages.fontFamily,
294
- "--chatbot-msg-font-size": t.messages.fontSize,
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": t.input.backgroundColor,
297
- "--chatbot-input-text-color": t.input.textColor,
298
- "--chatbot-input-placeholder-color": t.input.placeholderTextColor,
299
- "--chatbot-input-border-color": t.input.borderColor,
300
- "--chatbot-input-focus-ring": t.input.focusRingColor,
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": t.window.backgroundColor,
303
- "--chatbot-window-border-color": t.window.borderColor,
304
- "--chatbot-window-border-radius": t.window.borderRadius,
305
- "--chatbot-window-width": t.window.width,
306
- "--chatbot-window-height": t.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
- [t]
309
- ), ie = M(() => {
310
- const o = t.messages.markdownStyles || {};
351
+ [o]
352
+ ), pe = S(() => {
353
+ const e = o.messages.markdownStyles || {};
311
354
  return {
312
- strong: ({ node: s, ...l }) => /* @__PURE__ */ e("strong", { style: { color: o.boldColor || "inherit" }, ...l }),
313
- em: ({ node: s, ...l }) => /* @__PURE__ */ e("em", { style: { color: o.italicColor || "inherit" }, ...l }),
314
- a: ({ node: s, ...l }) => /* @__PURE__ */ e("a", { style: { color: o.linkColor || "#3b82f6" }, ...l }),
315
- code: ({ node: s, ...l }) => /* @__PURE__ */ e(
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: o.codeColor || "inherit",
320
- backgroundColor: o.codeBackgroundColor || "rgba(0, 0, 0, 0.1)",
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
- ...l
367
+ ...s
325
368
  }
326
369
  )
327
370
  };
328
- }, [t.messages.markdownStyles]);
329
- D(() => {
330
- var E;
331
- const o = t.window.scrollbarThumbColor, s = t.window.scrollbarTrackColor, l = `scrollbar-style-${k}`;
332
- (E = document.getElementById(l)) == null || E.remove();
333
- const I = document.createElement("style");
334
- return I.id = l, I.innerHTML = `
335
- /* Modern browsers */
336
- #${k} .chatbot-message-list {
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: ${o} ${s};
394
+ scrollbar-color: ${e} ${r};
339
395
  }
340
396
  /* WebKit-based browsers (Chrome, Safari, Edge) */
341
- #${k} .chatbot-message-list::-webkit-scrollbar {
397
+ #${w} .chatbot-message-list::-webkit-scrollbar,
398
+ #${w} .chatbot-textarea-input::-webkit-scrollbar {
342
399
  width: 8px;
343
400
  }
344
- #${k} .chatbot-message-list::-webkit-scrollbar-track {
345
- background: ${s};
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
- #${k} .chatbot-message-list::-webkit-scrollbar-thumb {
349
- background-color: ${o};
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 ${s};
410
+ border: 2px solid ${r};
352
411
  }
353
- `, document.head.appendChild(I), () => {
354
- var L;
355
- (L = document.getElementById(l)) == null || L.remove();
412
+ `, document.head.appendChild(i), () => {
413
+ var A;
414
+ (A = document.getElementById(s)) == null || A.remove();
356
415
  };
357
416
  }, [
358
- k,
359
- t.window.scrollbarThumbColor,
360
- t.window.scrollbarTrackColor
361
- ]), D(() => {
362
- f(g);
363
- }, [g]), D(() => {
364
- var o;
365
- (o = ae.current) == null || o.scrollIntoView({ behavior: "smooth" });
366
- }, [v, O, g]), D(() => {
367
- var o, s;
368
- N ? (o = ne.current) == null || o.focus() : (s = le.current) == null || s.focus();
369
- }, [N]), D(() => {
370
- const o = (s) => {
371
- s.key === "Escape" && N && A(!1);
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", o), () => window.removeEventListener("keydown", o);
374
- }, [N]);
375
- const Y = we(async () => {
376
- var I, E, L, de, ue, he, be, fe, me, ge, pe;
377
- const o = F.trim();
378
- if (!o || h || O || g) return;
379
- const s = {
380
- id: Date.now(),
381
- text: o,
382
- sender: "user"
383
- }, l = [...v, s];
384
- if (z || m((n) => [...n, s]), R(o), se(""), U) {
385
- f(!0);
386
- try {
387
- const n = je(l), i = n.slice(0, -1), B = ((E = (I = n[n.length - 1]) == null ? void 0 : I.parts[0]) == null ? void 0 : E.text) || "", Be = await (await (await U.startChat({ history: i }).sendMessage(B)).response).text() || "(no response)", Me = { id: Date.now() + 1, text: Be, sender: "bot" };
388
- m((Te) => [...Te, Me]);
389
- } catch (n) {
390
- console.error("Gemini API Error:", n);
391
- const i = {
392
- id: Date.now() + 1,
393
- text: "Sorry, an error occurred. Please try again.",
394
- sender: "bot"
395
- };
396
- m((B) => [...B, i]);
397
- } finally {
398
- f(!1);
399
- }
400
- } else if (V) {
401
- f(!0);
402
- try {
403
- const n = r ? [{ role: "system", content: r }] : [], i = v.map((p) => ({
404
- role: p.sender === "bot" ? "assistant" : "user",
405
- content: p.text
406
- })), x = ((he = (ue = (de = (L = (await V.chat.completions.create({
407
- model: ee,
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
- ...n,
410
- ...i,
411
- { role: "user", content: o }
495
+ ...b,
496
+ { role: "user", content: p }
412
497
  ]
413
- })).choices) == null ? void 0 : L[0]) == null ? void 0 : de.message) == null ? void 0 : ue.content) == null ? void 0 : he.trim()) || "(no response)";
414
- m((p) => [
415
- ...p,
416
- { id: Date.now() + 1, text: x, sender: "bot" }
417
- ]);
418
- } catch (n) {
419
- console.error("OpenAI Error:", n), m((i) => [
420
- ...i,
421
- {
422
- id: Date.now() + 1,
423
- text: "Sorry, something went wrong with OpenAI.",
424
- sender: "bot"
425
- }
426
- ]);
427
- } finally {
428
- f(!1);
429
- }
430
- } else if (Z) {
431
- f(!0);
432
- try {
433
- const n = v.map((x) => ({
434
- role: x.sender === "bot" ? "assistant" : "user",
435
- content: x.text
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
- ...n,
442
- { role: "user", content: o }
522
+ ...b,
523
+ { role: "user", content: p }
443
524
  ],
444
525
  max_tokens: 1024
445
- })).content[0]) == null ? void 0 : be.text) == null ? void 0 : fe.trim()) || "(no response)";
446
- m((x) => [
447
- ...x,
448
- { id: Date.now() + 1, text: B, sender: "bot" }
449
- ]);
450
- } catch (n) {
451
- console.error("Anthropic API Error:", n), m((i) => [
452
- ...i,
453
- {
454
- id: Date.now() + 1,
455
- text: "Sorry, an error occurred with Claude.",
456
- sender: "bot"
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
- ...n,
471
- ...i,
472
- { role: "user", content: o }
540
+ ...p,
541
+ { role: "user", content: e }
473
542
  ],
474
- model: te
475
- })).choices[0]) == null ? void 0 : me.message) == null ? void 0 : ge.content) == null ? void 0 : pe.trim()) || "(no response)";
476
- m((p) => [
477
- ...p,
478
- { id: Date.now() + 1, text: x, sender: "bot" }
479
- ]);
480
- } catch (n) {
481
- console.error("Groq API Error:", n), m((i) => [
482
- ...i,
483
- {
484
- id: Date.now() + 1,
485
- text: "Sorry, an error occurred with Groq.",
486
- sender: "bot"
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
- m((i) => [...i, n]), f(!1);
499
- }, 800));
557
+ K((p) => [...p, b]), W(!1);
558
+ }
500
559
  }, [
501
- F,
502
- h,
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
- g,
505
- R,
569
+ K,
570
+ E,
506
571
  U,
507
- V,
508
- Z,
509
- X,
510
- z,
511
- v,
512
- m,
572
+ W,
573
+ l,
513
574
  ee,
514
- oe,
515
575
  te,
516
- r
517
- // Add to dependency array
518
- ]), ke = we(
519
- (o) => {
520
- o.key === "Enter" && Y();
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
- [Y]
523
- ), _ = (o) => typeof o == "string" ? /* @__PURE__ */ e(
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: o,
600
+ src: e,
527
601
  alt: "avatar",
528
602
  className: "w-8 h-8 rounded-full object-cover"
529
603
  }
530
- ) : /* @__PURE__ */ e("div", { className: "w-8 h-8 rounded-full text-gray-500", children: o }), J = O || g, ce = {
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
- }, Ne = t.window.placement === "center", P = {
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: k, style: Ce, className: "font-sans", children: [
539
- /* @__PURE__ */ e(Q, { children: !N && /* @__PURE__ */ e(
540
- C.button,
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: le,
543
- onClick: () => A(!0),
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__ */ e($e, { icon: Ie })
630
+ children: /* @__PURE__ */ t(B, { icon: Ge })
557
631
  }
558
632
  ) }),
559
- /* @__PURE__ */ u(Q, { children: [
560
- N && Ne && t.window.backdrop && /* @__PURE__ */ e(
561
- C.div,
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: t.window.backdropColor,
568
- backdropFilter: `blur(${t.window.backdropBlur})`,
641
+ backgroundColor: o.window.backdropColor,
642
+ backdropFilter: `blur(${o.window.backdropBlur})`,
569
643
  // For Safari compatibility
570
- WebkitBackdropFilter: `blur(${t.window.backdropBlur})`
644
+ WebkitBackdropFilter: `blur(${o.window.backdropBlur})`
571
645
  },
572
646
  className: "fixed inset-0 z-40",
573
- onClick: () => A(!1)
647
+ onClick: () => P(!1)
574
648
  },
575
649
  "chatbot-backdrop"
576
650
  ),
577
- N && /* @__PURE__ */ u(
651
+ I && /* @__PURE__ */ u(
578
652
  "div",
579
653
  {
580
- ref: ve,
654
+ ref: ze,
581
655
  "aria-modal": "true",
582
656
  role: "dialog",
583
- className: `fixed ${ce[t.window.placement] || ce["bottom-right"]} z-50 flex flex-col overflow-hidden shadow-2xl border`,
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__ */ e("div", { className: "w-10 h-10 rounded-full bg-white/30 flex items-center justify-center p-1", children: _(d) }),
603
- /* @__PURE__ */ e(
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: c
685
+ children: n
612
686
  }
613
687
  )
614
688
  ] }),
615
- /* @__PURE__ */ e(
689
+ /* @__PURE__ */ t(
616
690
  "button",
617
691
  {
618
- onClick: () => A(!1),
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__ */ e(
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__ */ e(
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__ */ e(Q, { initial: !1, children: v.map((o, s) => /* @__PURE__ */ u(
653
- C.div,
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 ${o.sender === "user" ? "ml-auto flex-row-reverse" : "mr-auto"}`,
734
+ className: `flex items-end max-w-[85%] gap-2 ${e.sender === "user" ? "ml-auto flex-row-reverse" : "mr-auto"}`,
661
735
  children: [
662
- t.messages.showAvatars && /* @__PURE__ */ e("div", { className: "w-7 h-7 rounded-full flex-shrink-0 overflow-hidden", children: _(
663
- o.sender === "user" ? b : d
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__ */ e(
666
- C.div,
739
+ /* @__PURE__ */ u(
740
+ "div",
667
741
  {
668
- layout: "position",
669
- transition: { duration: 0.2, ease: "easeOut" },
670
- className: `px-3 py-2 ${P[t.messages.bubbleShape] || P.rounded} ${t.messages.bubblePointer ? o.sender === "user" ? "rounded-br-none" : "rounded-bl-none" : ""}`,
671
- style: {
672
- backgroundColor: o.sender === "user" ? "var(--chatbot-user-msg-bg)" : "var(--chatbot-bot-msg-bg)",
673
- color: o.sender === "user" ? "var(--chatbot-user-msg-text-color)" : "var(--chatbot-bot-msg-text-color)",
674
- fontFamily: "var(--chatbot-msg-font-family)",
675
- fontSize: "var(--chatbot-msg-font-size)"
676
- },
677
- children: o.sender === "bot" && s === v.length - 1 ? /* @__PURE__ */ e(
678
- Pe,
679
- {
680
- text: o.text,
681
- animationType: t.messages.animation,
682
- components: ie
683
- }
684
- ) : /* @__PURE__ */ e(
685
- "div",
686
- {
687
- 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",
688
- style: { color: "inherit" },
689
- children: /* @__PURE__ */ e(T, { components: ie, children: o.text })
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
- o.id
807
+ e.id
697
808
  )) }),
698
- J && /* @__PURE__ */ u(
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
- t.messages.showAvatars && /* @__PURE__ */ e("div", { className: "w-7 h-7 rounded-full flex-shrink-0 overflow-hidden", children: _(d) }),
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 ${P[t.messages.bubbleShape] || P.rounded} rounded-bl-none`,
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__ */ e(Fe, {})
820
+ children: /* @__PURE__ */ t(ot, {})
711
821
  }
712
822
  )
713
823
  ]
714
824
  },
715
825
  "typing-indicator"
716
826
  ),
717
- /* @__PURE__ */ e("div", { ref: ae })
827
+ /* @__PURE__ */ t("div", { ref: be })
718
828
  ]
719
829
  }
720
830
  ),
721
- /* @__PURE__ */ e(
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: /* @__PURE__ */ u("div", { className: "flex items-center space-x-2", children: [
730
- /* @__PURE__ */ e(
731
- "input",
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
- onClick: Y,
753
- disabled: !F.trim() || h || J,
754
- "aria-label": "Send Message",
755
- 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",
756
- style: {
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
- Qe as ChatBot
977
+ gt as ChatBot
776
978
  };