aizek-chatbot 1.0.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/dist/index.cjs +818 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +52 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.mjs +790 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +42 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,790 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useState, useEffect, useRef } from 'react';
|
|
3
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
|
+
import OpenAI from 'openai';
|
|
5
|
+
import ReactMarkdown from 'react-markdown';
|
|
6
|
+
import remarkGfm from 'remark-gfm';
|
|
7
|
+
|
|
8
|
+
// src/utils/cx.ts
|
|
9
|
+
function cx(...args) {
|
|
10
|
+
return args.filter(Boolean).join(" ");
|
|
11
|
+
}
|
|
12
|
+
var base = {
|
|
13
|
+
display: "inline-flex",
|
|
14
|
+
alignItems: "center",
|
|
15
|
+
justifyContent: "center",
|
|
16
|
+
borderRadius: 12,
|
|
17
|
+
fontWeight: 600,
|
|
18
|
+
lineHeight: 1,
|
|
19
|
+
transition: "background-color .2s ease, color .2s ease, border-color .2s ease",
|
|
20
|
+
outline: "none",
|
|
21
|
+
cursor: "pointer"
|
|
22
|
+
};
|
|
23
|
+
var sizes = {
|
|
24
|
+
sm: { height: 36, padding: "0 12px", fontSize: 14 },
|
|
25
|
+
md: { height: 40, padding: "0 16px", fontSize: 16 },
|
|
26
|
+
lg: { height: 44, padding: "0 20px", fontSize: 18 }
|
|
27
|
+
};
|
|
28
|
+
var palette = {
|
|
29
|
+
brand: {
|
|
30
|
+
primary: "#2563eb",
|
|
31
|
+
primaryHover: "#1d4ed8"
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
function styleFor(variant) {
|
|
35
|
+
switch (variant) {
|
|
36
|
+
case "outline":
|
|
37
|
+
return {
|
|
38
|
+
background: "transparent",
|
|
39
|
+
color: palette.brand.primary,
|
|
40
|
+
border: `1px solid ${palette.brand.primary}`
|
|
41
|
+
};
|
|
42
|
+
case "ghost":
|
|
43
|
+
return {
|
|
44
|
+
background: "transparent",
|
|
45
|
+
color: palette.brand.primary,
|
|
46
|
+
border: "1px solid transparent"
|
|
47
|
+
};
|
|
48
|
+
default:
|
|
49
|
+
return {
|
|
50
|
+
background: palette.brand.primary,
|
|
51
|
+
color: "#fff",
|
|
52
|
+
border: "1px solid transparent"
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
var Button = React.forwardRef(
|
|
57
|
+
({ variant = "primary", size = "md", style, className, onMouseEnter, onMouseLeave, ...props }, ref) => {
|
|
58
|
+
const [hover, setHover] = React.useState(false);
|
|
59
|
+
const hoverStyle = variant === "primary" ? { background: hover ? palette.brand.primaryHover : palette.brand.primary } : variant === "outline" ? { borderColor: hover ? palette.brand.primaryHover : palette.brand.primary } : { background: hover ? "rgba(37, 99, 235, 0.08)" : "transparent" };
|
|
60
|
+
return /* @__PURE__ */ jsx(
|
|
61
|
+
"button",
|
|
62
|
+
{
|
|
63
|
+
ref,
|
|
64
|
+
className: cx("rui-btn", className),
|
|
65
|
+
style: { ...base, ...sizes[size], ...styleFor(variant), ...hover ? hoverStyle : {}, ...style },
|
|
66
|
+
onMouseEnter: (e) => {
|
|
67
|
+
setHover(true);
|
|
68
|
+
onMouseEnter?.(e);
|
|
69
|
+
},
|
|
70
|
+
onMouseLeave: (e) => {
|
|
71
|
+
setHover(false);
|
|
72
|
+
onMouseLeave?.(e);
|
|
73
|
+
},
|
|
74
|
+
...props
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
Button.displayName = "Button";
|
|
80
|
+
var useChatbot = (options = {}) => {
|
|
81
|
+
const { mcpUrl, apiKey } = options;
|
|
82
|
+
const client = new OpenAI({ apiKey, dangerouslyAllowBrowser: true });
|
|
83
|
+
const [messages, setMessages] = useState([]);
|
|
84
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
85
|
+
const generateId = () => {
|
|
86
|
+
return Date.now().toString() + Math.random().toString(36).substr(2, 9);
|
|
87
|
+
};
|
|
88
|
+
const addMessage = (content, role) => {
|
|
89
|
+
const newMessage = {
|
|
90
|
+
id: generateId(),
|
|
91
|
+
content,
|
|
92
|
+
role,
|
|
93
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
94
|
+
};
|
|
95
|
+
setMessages((prev) => [...prev, newMessage]);
|
|
96
|
+
return newMessage;
|
|
97
|
+
};
|
|
98
|
+
const sendMessage = async (message) => {
|
|
99
|
+
if (!message.trim() || isLoading) return;
|
|
100
|
+
addMessage(message, "user");
|
|
101
|
+
setIsLoading(true);
|
|
102
|
+
console.log(options.userToken);
|
|
103
|
+
try {
|
|
104
|
+
const resp = await client.responses.create({
|
|
105
|
+
model: "gpt-5",
|
|
106
|
+
tools: [
|
|
107
|
+
{
|
|
108
|
+
type: "mcp",
|
|
109
|
+
server_label: "aizek-mcp",
|
|
110
|
+
server_url: mcpUrl,
|
|
111
|
+
require_approval: "never",
|
|
112
|
+
authorization: options.userToken ? `Bearer ${options.userToken}` : void 0
|
|
113
|
+
}
|
|
114
|
+
],
|
|
115
|
+
input: message
|
|
116
|
+
});
|
|
117
|
+
let responseText = "";
|
|
118
|
+
if (resp && Array.isArray(resp)) {
|
|
119
|
+
const messageItem = resp.find((item) => item.type === "message");
|
|
120
|
+
if (messageItem && messageItem.content && Array.isArray(messageItem.content)) {
|
|
121
|
+
const textContent = messageItem.content.find((content) => content.type === "output_text");
|
|
122
|
+
if (textContent && textContent.text) {
|
|
123
|
+
responseText = textContent.text;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
if (resp && resp.output_text) {
|
|
128
|
+
responseText = resp.output_text;
|
|
129
|
+
} else if (typeof resp === "string") {
|
|
130
|
+
responseText = resp;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!responseText) {
|
|
134
|
+
responseText = `"${message}" mesaj\u0131n\u0131z\u0131 ald\u0131m. Size nas\u0131l yard\u0131mc\u0131 olabilirim?`;
|
|
135
|
+
}
|
|
136
|
+
addMessage(responseText, "assistant");
|
|
137
|
+
setIsLoading(false);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error("Error sending message:", error);
|
|
140
|
+
addMessage("\xDCzg\xFCn\xFCm, bir hata olu\u015Ftu. L\xFCtfen tekrar deneyin.", "assistant");
|
|
141
|
+
setIsLoading(false);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
messages,
|
|
146
|
+
isLoading,
|
|
147
|
+
sendMessage,
|
|
148
|
+
addMessage
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/services/chatWidgetApi.ts
|
|
153
|
+
var API_BASE_URL = "https://api.elviz24.com";
|
|
154
|
+
var fetchChatWidgetSettings = async (clientId) => {
|
|
155
|
+
try {
|
|
156
|
+
const response = await fetch(`${API_BASE_URL}/ChatWidgetSettings/GetByClientId?client_id=${clientId}`, {
|
|
157
|
+
method: "GET",
|
|
158
|
+
headers: {
|
|
159
|
+
"Content-Type": "application/json"
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
if (!response.ok) {
|
|
163
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
164
|
+
}
|
|
165
|
+
const data = await response.json();
|
|
166
|
+
return data;
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error("Error fetching chat widget settings:", error);
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
var mapApiSettingsToConfig = (apiSettings) => {
|
|
173
|
+
if (!apiSettings) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
const buttonSizeMap = {
|
|
177
|
+
"small": "sm",
|
|
178
|
+
"medium": "md",
|
|
179
|
+
"large": "lg"
|
|
180
|
+
};
|
|
181
|
+
return {
|
|
182
|
+
welcomeMessage: apiSettings.welcome_message,
|
|
183
|
+
buttonBackground: apiSettings.button_background,
|
|
184
|
+
placeholder: apiSettings.placeholder,
|
|
185
|
+
buttonPosition: apiSettings.button_position,
|
|
186
|
+
buttonSize: buttonSizeMap[apiSettings.button_size] || "md",
|
|
187
|
+
chatWidth: apiSettings.chat_width,
|
|
188
|
+
chatHeight: apiSettings.chat_height,
|
|
189
|
+
showTypingIndicator: apiSettings.show_typing_indicator,
|
|
190
|
+
initialOpen: apiSettings.initial_open,
|
|
191
|
+
headerBackground: apiSettings.header_background,
|
|
192
|
+
companyLogo: apiSettings.company_logo || void 0,
|
|
193
|
+
companyName: apiSettings.company_name
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// src/styles/messageStyles.ts
|
|
198
|
+
var getMessageBubbleStyles = (isUser) => ({
|
|
199
|
+
maxWidth: "80%",
|
|
200
|
+
padding: "12px 16px",
|
|
201
|
+
borderRadius: isUser ? "18px 18px 4px 18px" : "18px 18px 18px 4px",
|
|
202
|
+
marginBottom: "8px",
|
|
203
|
+
wordWrap: "break-word",
|
|
204
|
+
lineHeight: 1.4,
|
|
205
|
+
fontSize: "14px",
|
|
206
|
+
position: "relative",
|
|
207
|
+
...isUser ? {
|
|
208
|
+
background: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
|
|
209
|
+
color: "#ffffff",
|
|
210
|
+
marginLeft: "auto",
|
|
211
|
+
marginRight: "0"
|
|
212
|
+
} : {
|
|
213
|
+
background: "#f8fafc",
|
|
214
|
+
color: "#334155",
|
|
215
|
+
border: "1px solid #e2e8f0",
|
|
216
|
+
marginLeft: "0",
|
|
217
|
+
marginRight: "auto"
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
var getTimeStyles = (isUser) => ({
|
|
221
|
+
fontSize: "11px",
|
|
222
|
+
opacity: 0.7,
|
|
223
|
+
marginTop: "4px",
|
|
224
|
+
textAlign: isUser ? "right" : "left"
|
|
225
|
+
});
|
|
226
|
+
var getMarkdownStyles = () => ({
|
|
227
|
+
lineHeight: 1.6
|
|
228
|
+
});
|
|
229
|
+
var getMarkdownElementStyles = (isUser) => `
|
|
230
|
+
.markdown-content p {
|
|
231
|
+
margin: 0 0 12px 0;
|
|
232
|
+
line-height: 1.6;
|
|
233
|
+
}
|
|
234
|
+
.markdown-content p:last-child {
|
|
235
|
+
margin-bottom: 0;
|
|
236
|
+
}
|
|
237
|
+
.markdown-content ul {
|
|
238
|
+
margin: 12px 0 16px 0;
|
|
239
|
+
padding-left: 0;
|
|
240
|
+
list-style: none;
|
|
241
|
+
}
|
|
242
|
+
.markdown-content li {
|
|
243
|
+
margin-bottom: 12px;
|
|
244
|
+
line-height: 1.6;
|
|
245
|
+
padding: 12px 16px;
|
|
246
|
+
background: ${isUser ? "rgba(255,255,255,0.1)" : "#ffffff"};
|
|
247
|
+
border-radius: 12px;
|
|
248
|
+
border: 1px solid ${isUser ? "rgba(255,255,255,0.2)" : "#e2e8f0"};
|
|
249
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
|
250
|
+
position: relative;
|
|
251
|
+
transition: all 0.2s ease;
|
|
252
|
+
}
|
|
253
|
+
.markdown-content li:hover {
|
|
254
|
+
transform: translateY(-1px);
|
|
255
|
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
|
256
|
+
}
|
|
257
|
+
.markdown-content li::before {
|
|
258
|
+
content: "\u2022";
|
|
259
|
+
color: ${isUser ? "#ffffff" : "#667eea"};
|
|
260
|
+
font-weight: bold;
|
|
261
|
+
font-size: 18px;
|
|
262
|
+
position: absolute;
|
|
263
|
+
left: -8px;
|
|
264
|
+
top: 12px;
|
|
265
|
+
}
|
|
266
|
+
.markdown-content li strong {
|
|
267
|
+
display: block;
|
|
268
|
+
font-size: 15px;
|
|
269
|
+
margin-bottom: 4px;
|
|
270
|
+
color: ${isUser ? "#ffffff" : "#1e293b"};
|
|
271
|
+
}
|
|
272
|
+
.markdown-content li em {
|
|
273
|
+
display: block;
|
|
274
|
+
font-size: 13px;
|
|
275
|
+
opacity: 0.8;
|
|
276
|
+
margin-top: 4px;
|
|
277
|
+
}
|
|
278
|
+
.markdown-content strong {
|
|
279
|
+
font-weight: 600;
|
|
280
|
+
color: ${isUser ? "#ffffff" : "#1e293b"};
|
|
281
|
+
}
|
|
282
|
+
.markdown-content em {
|
|
283
|
+
font-style: italic;
|
|
284
|
+
opacity: 0.9;
|
|
285
|
+
}
|
|
286
|
+
.markdown-content code {
|
|
287
|
+
background: ${isUser ? "rgba(255,255,255,0.2)" : "#f1f5f9"};
|
|
288
|
+
padding: 2px 6px;
|
|
289
|
+
border-radius: 4px;
|
|
290
|
+
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
|
291
|
+
font-size: 13px;
|
|
292
|
+
}
|
|
293
|
+
.markdown-content pre {
|
|
294
|
+
background: ${isUser ? "rgba(255,255,255,0.1)" : "#f8fafc"};
|
|
295
|
+
padding: 12px;
|
|
296
|
+
border-radius: 8px;
|
|
297
|
+
overflow-x: auto;
|
|
298
|
+
margin: 8px 0;
|
|
299
|
+
border: 1px solid ${isUser ? "rgba(255,255,255,0.2)" : "#e2e8f0"};
|
|
300
|
+
}
|
|
301
|
+
.markdown-content pre code {
|
|
302
|
+
background: none;
|
|
303
|
+
padding: 0;
|
|
304
|
+
}
|
|
305
|
+
.markdown-content blockquote {
|
|
306
|
+
border-left: 3px solid ${isUser ? "rgba(255,255,255,0.5)" : "#cbd5e1"};
|
|
307
|
+
padding-left: 12px;
|
|
308
|
+
margin: 8px 0;
|
|
309
|
+
opacity: 0.8;
|
|
310
|
+
}
|
|
311
|
+
.markdown-content h1, .markdown-content h2, .markdown-content h3 {
|
|
312
|
+
margin: 16px 0 8px 0;
|
|
313
|
+
font-weight: 600;
|
|
314
|
+
}
|
|
315
|
+
.markdown-content h1 {
|
|
316
|
+
font-size: 18px;
|
|
317
|
+
}
|
|
318
|
+
.markdown-content h2 {
|
|
319
|
+
font-size: 16px;
|
|
320
|
+
}
|
|
321
|
+
.markdown-content h3 {
|
|
322
|
+
font-size: 15px;
|
|
323
|
+
}
|
|
324
|
+
.markdown-content table {
|
|
325
|
+
border-collapse: collapse;
|
|
326
|
+
width: 100%;
|
|
327
|
+
margin: 8px 0;
|
|
328
|
+
}
|
|
329
|
+
.markdown-content th, .markdown-content td {
|
|
330
|
+
border: 1px solid ${isUser ? "rgba(255,255,255,0.3)" : "#e2e8f0"};
|
|
331
|
+
padding: 8px 12px;
|
|
332
|
+
text-align: left;
|
|
333
|
+
}
|
|
334
|
+
.markdown-content th {
|
|
335
|
+
background: ${isUser ? "rgba(255,255,255,0.1)" : "#f8fafc"};
|
|
336
|
+
font-weight: 600;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/* Enhanced list styling */
|
|
340
|
+
.markdown-content li {
|
|
341
|
+
position: relative;
|
|
342
|
+
overflow: hidden;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
.markdown-content li::after {
|
|
346
|
+
content: "";
|
|
347
|
+
position: absolute;
|
|
348
|
+
top: 0;
|
|
349
|
+
left: 0;
|
|
350
|
+
width: 4px;
|
|
351
|
+
height: 100%;
|
|
352
|
+
background: linear-gradient(135deg, ${isUser ? "#ffffff" : "#667eea"}, ${isUser ? "rgba(255,255,255,0.5)" : "#764ba2"});
|
|
353
|
+
border-radius: 0 2px 2px 0;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/* Product name styling */
|
|
357
|
+
.markdown-content li strong:first-child {
|
|
358
|
+
color: ${isUser ? "#ffffff" : "#1e293b"};
|
|
359
|
+
font-size: 16px;
|
|
360
|
+
font-weight: 700;
|
|
361
|
+
display: block;
|
|
362
|
+
margin-bottom: 8px;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/* Product details styling */
|
|
366
|
+
.markdown-content li strong:not(:first-child) {
|
|
367
|
+
color: ${isUser ? "#ffffff" : "#059669"};
|
|
368
|
+
font-size: 13px;
|
|
369
|
+
font-weight: 600;
|
|
370
|
+
margin-right: 8px;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/* Add some spacing between product details */
|
|
374
|
+
.markdown-content li br + * {
|
|
375
|
+
margin-top: 4px;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/* Hover effect enhancement */
|
|
379
|
+
.markdown-content li:hover::after {
|
|
380
|
+
width: 6px;
|
|
381
|
+
background: linear-gradient(135deg, ${isUser ? "#ffffff" : "#667eea"}, ${isUser ? "#ffffff" : "#764ba2"});
|
|
382
|
+
}
|
|
383
|
+
`;
|
|
384
|
+
var getMessageContainerStyles = (isUser) => ({
|
|
385
|
+
display: "flex",
|
|
386
|
+
flexDirection: "column",
|
|
387
|
+
alignItems: isUser ? "flex-end" : "flex-start",
|
|
388
|
+
width: "100%"
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// src/styles/inputStyles.ts
|
|
392
|
+
var getInputContainerStyles = () => ({
|
|
393
|
+
display: "flex",
|
|
394
|
+
alignItems: "flex-end",
|
|
395
|
+
gap: "12px",
|
|
396
|
+
padding: "16px",
|
|
397
|
+
background: "#ffffff",
|
|
398
|
+
borderTop: "1px solid #e2e8f0",
|
|
399
|
+
borderRadius: "0 0 12px 12px"
|
|
400
|
+
});
|
|
401
|
+
var getTextareaStyles = (isLoading) => ({
|
|
402
|
+
flex: 1,
|
|
403
|
+
minHeight: "44px",
|
|
404
|
+
maxHeight: "120px",
|
|
405
|
+
padding: "12px 16px",
|
|
406
|
+
border: "1px solid #e2e8f0",
|
|
407
|
+
borderRadius: "22px",
|
|
408
|
+
fontSize: "14px",
|
|
409
|
+
lineHeight: 1.4,
|
|
410
|
+
resize: "none",
|
|
411
|
+
outline: "none",
|
|
412
|
+
transition: "border-color 0.2s ease, box-shadow 0.2s ease",
|
|
413
|
+
fontFamily: "inherit",
|
|
414
|
+
background: "#f8fafc",
|
|
415
|
+
color: "#334155",
|
|
416
|
+
...isLoading ? {
|
|
417
|
+
opacity: 0.6,
|
|
418
|
+
cursor: "not-allowed"
|
|
419
|
+
} : {}
|
|
420
|
+
});
|
|
421
|
+
var getSendButtonStyles = (isLoading, hasMessage) => ({
|
|
422
|
+
width: "44px",
|
|
423
|
+
height: "44px",
|
|
424
|
+
borderRadius: "50%",
|
|
425
|
+
border: "none",
|
|
426
|
+
background: isLoading || !hasMessage ? "#e2e8f0" : "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
|
|
427
|
+
color: "#ffffff",
|
|
428
|
+
cursor: isLoading || !hasMessage ? "not-allowed" : "pointer",
|
|
429
|
+
display: "flex",
|
|
430
|
+
alignItems: "center",
|
|
431
|
+
justifyContent: "center",
|
|
432
|
+
transition: "all 0.2s ease",
|
|
433
|
+
fontSize: "16px"
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
// src/styles/headerStyles.ts
|
|
437
|
+
var getHeaderStyles = (headerBackground) => ({
|
|
438
|
+
padding: "16px 20px",
|
|
439
|
+
background: headerBackground,
|
|
440
|
+
color: "#ffffff",
|
|
441
|
+
display: "flex",
|
|
442
|
+
alignItems: "center",
|
|
443
|
+
gap: "12px"
|
|
444
|
+
});
|
|
445
|
+
var getLogoContainerStyles = () => ({
|
|
446
|
+
width: "40px",
|
|
447
|
+
height: "40px",
|
|
448
|
+
borderRadius: "50%",
|
|
449
|
+
background: "rgba(255, 255, 255, 0.2)",
|
|
450
|
+
display: "flex",
|
|
451
|
+
alignItems: "center",
|
|
452
|
+
justifyContent: "center",
|
|
453
|
+
fontSize: "18px",
|
|
454
|
+
overflow: "hidden"
|
|
455
|
+
});
|
|
456
|
+
var getLogoImageStyles = () => ({
|
|
457
|
+
width: "100%",
|
|
458
|
+
height: "100%",
|
|
459
|
+
objectFit: "cover",
|
|
460
|
+
borderRadius: "50%"
|
|
461
|
+
});
|
|
462
|
+
var getLogoTextStyles = () => ({
|
|
463
|
+
fontSize: "16px",
|
|
464
|
+
fontWeight: "bold"
|
|
465
|
+
});
|
|
466
|
+
var getCompanyNameStyles = () => ({
|
|
467
|
+
margin: 0,
|
|
468
|
+
fontSize: "16px",
|
|
469
|
+
fontWeight: 600
|
|
470
|
+
});
|
|
471
|
+
var getStatusTextStyles = () => ({
|
|
472
|
+
margin: 0,
|
|
473
|
+
fontSize: "12px",
|
|
474
|
+
opacity: 0.8
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
// src/styles/containerStyles.ts
|
|
478
|
+
var getButtonSizes = () => ({
|
|
479
|
+
sm: { width: "50px", height: "50px", fontSize: "20px" },
|
|
480
|
+
md: { width: "60px", height: "60px", fontSize: "24px" },
|
|
481
|
+
lg: { width: "70px", height: "70px", fontSize: "28px" }
|
|
482
|
+
});
|
|
483
|
+
var getFloatingButtonStyles = (buttonPosition, buttonSize, buttonBackground, isOpen) => {
|
|
484
|
+
const buttonSizes = getButtonSizes();
|
|
485
|
+
const buttonSizeStyle = buttonSizes[buttonSize];
|
|
486
|
+
return {
|
|
487
|
+
position: "fixed",
|
|
488
|
+
[buttonPosition === "bottom-left" ? "left" : "right"]: "20px",
|
|
489
|
+
bottom: "20px",
|
|
490
|
+
width: buttonSizeStyle.width,
|
|
491
|
+
height: buttonSizeStyle.height,
|
|
492
|
+
borderRadius: "50%",
|
|
493
|
+
background: buttonBackground,
|
|
494
|
+
border: "none",
|
|
495
|
+
color: "#ffffff",
|
|
496
|
+
cursor: "pointer",
|
|
497
|
+
display: "flex",
|
|
498
|
+
alignItems: "center",
|
|
499
|
+
justifyContent: "center",
|
|
500
|
+
fontSize: buttonSizeStyle.fontSize,
|
|
501
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
|
|
502
|
+
transition: "all 0.3s ease",
|
|
503
|
+
zIndex: 1e3,
|
|
504
|
+
transform: isOpen ? "scale(0.9)" : "scale(1)"
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
var getChatContainerStyles = (buttonPosition, chatWidth, chatHeight, isOpen) => ({
|
|
508
|
+
position: "fixed",
|
|
509
|
+
[buttonPosition === "bottom-left" ? "left" : "right"]: "20px",
|
|
510
|
+
bottom: "90px",
|
|
511
|
+
width: chatWidth,
|
|
512
|
+
height: chatHeight,
|
|
513
|
+
zIndex: 9999999,
|
|
514
|
+
transform: isOpen ? "translateY(0) scale(1)" : "translateY(20px) scale(0.95)",
|
|
515
|
+
opacity: isOpen ? 1 : 0,
|
|
516
|
+
visibility: isOpen ? "visible" : "hidden",
|
|
517
|
+
transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
|
|
518
|
+
transformOrigin: buttonPosition === "bottom-left" ? "bottom left" : "bottom right"
|
|
519
|
+
});
|
|
520
|
+
var getOverlayStyles = (isOpen) => ({
|
|
521
|
+
position: "fixed",
|
|
522
|
+
top: 0,
|
|
523
|
+
left: 0,
|
|
524
|
+
right: 0,
|
|
525
|
+
bottom: 0,
|
|
526
|
+
background: "rgba(0, 0, 0, 0.1)",
|
|
527
|
+
zIndex: 998,
|
|
528
|
+
opacity: isOpen ? 1 : 0,
|
|
529
|
+
visibility: isOpen ? "visible" : "hidden",
|
|
530
|
+
transition: "all 0.3s ease"
|
|
531
|
+
});
|
|
532
|
+
var getChatbotContainerStyles = () => ({
|
|
533
|
+
display: "flex",
|
|
534
|
+
flexDirection: "column",
|
|
535
|
+
height: "100%",
|
|
536
|
+
background: "#ffffff",
|
|
537
|
+
borderRadius: "12px",
|
|
538
|
+
boxShadow: "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)",
|
|
539
|
+
border: "1px solid #e2e8f0",
|
|
540
|
+
overflow: "hidden"
|
|
541
|
+
});
|
|
542
|
+
var getMessagesContainerStyles = () => ({
|
|
543
|
+
flex: 1,
|
|
544
|
+
overflowY: "auto",
|
|
545
|
+
padding: "16px",
|
|
546
|
+
display: "flex",
|
|
547
|
+
flexDirection: "column",
|
|
548
|
+
gap: "4px",
|
|
549
|
+
background: "#f8fafc"
|
|
550
|
+
});
|
|
551
|
+
var getEmptyStateStyles = () => ({
|
|
552
|
+
display: "flex",
|
|
553
|
+
flexDirection: "column",
|
|
554
|
+
alignItems: "center",
|
|
555
|
+
justifyContent: "center",
|
|
556
|
+
height: "100%",
|
|
557
|
+
color: "#64748b",
|
|
558
|
+
textAlign: "center",
|
|
559
|
+
padding: "40px 20px"
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
// src/styles/loadingStyles.ts
|
|
563
|
+
var getLoadingSpinnerStyles = () => ({
|
|
564
|
+
width: "16px",
|
|
565
|
+
height: "16px",
|
|
566
|
+
border: "2px solid transparent",
|
|
567
|
+
borderTop: "2px solid currentColor",
|
|
568
|
+
borderRadius: "50%",
|
|
569
|
+
animation: "spin 1s linear infinite"
|
|
570
|
+
});
|
|
571
|
+
var AizekChatBot = ({ clientId, userToken }) => {
|
|
572
|
+
const defaultConfig = {
|
|
573
|
+
welcomeMessage: "Merhaba! Size nas\u0131l yard\u0131mc\u0131 olabilirim?",
|
|
574
|
+
buttonBackground: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
|
|
575
|
+
placeholder: "Mesaj\u0131n\u0131z\u0131 yaz\u0131n...",
|
|
576
|
+
buttonPosition: "bottom-left",
|
|
577
|
+
buttonSize: "md",
|
|
578
|
+
chatWidth: "400px",
|
|
579
|
+
chatHeight: "600px",
|
|
580
|
+
showTypingIndicator: true,
|
|
581
|
+
initialOpen: true,
|
|
582
|
+
headerBackground: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
|
|
583
|
+
companyLogo: void 0,
|
|
584
|
+
companyName: "AI Asistan"
|
|
585
|
+
};
|
|
586
|
+
const [config, setConfig] = useState(defaultConfig);
|
|
587
|
+
const [isConfigLoading, setIsConfigLoading] = useState(true);
|
|
588
|
+
const [finalMcpUrl, setFinalMcpUrl] = useState("");
|
|
589
|
+
const [apiKey, setApiKey] = useState("");
|
|
590
|
+
const { welcomeMessage, buttonBackground, placeholder, buttonPosition, buttonSize, chatWidth, chatHeight, showTypingIndicator, initialOpen, headerBackground, companyLogo, companyName } = config;
|
|
591
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
592
|
+
useEffect(() => {
|
|
593
|
+
const loadConfig = async () => {
|
|
594
|
+
try {
|
|
595
|
+
setIsConfigLoading(true);
|
|
596
|
+
const apiResponse = await fetchChatWidgetSettings(clientId);
|
|
597
|
+
setFinalMcpUrl(apiResponse.data.mcp_url);
|
|
598
|
+
setApiKey(apiResponse.data.openai_key || "");
|
|
599
|
+
const apiConfig = mapApiSettingsToConfig(apiResponse.data.chat_widget_settings);
|
|
600
|
+
if (apiConfig) {
|
|
601
|
+
setConfig(apiConfig);
|
|
602
|
+
}
|
|
603
|
+
} catch (error) {
|
|
604
|
+
console.error("Failed to load chat widget config:", error);
|
|
605
|
+
setFinalMcpUrl("");
|
|
606
|
+
} finally {
|
|
607
|
+
setIsConfigLoading(false);
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
loadConfig();
|
|
611
|
+
}, [clientId]);
|
|
612
|
+
const internalChatbot = useChatbot({ mcpUrl: finalMcpUrl, apiKey, userToken });
|
|
613
|
+
const messages = internalChatbot.messages;
|
|
614
|
+
const isLoading = internalChatbot.isLoading;
|
|
615
|
+
const handleSendMessage = internalChatbot.sendMessage;
|
|
616
|
+
const toggleChat = () => {
|
|
617
|
+
const newIsOpen = !isOpen;
|
|
618
|
+
setIsOpen(newIsOpen);
|
|
619
|
+
};
|
|
620
|
+
useEffect(() => {
|
|
621
|
+
setIsOpen(initialOpen);
|
|
622
|
+
}, [initialOpen]);
|
|
623
|
+
const messagesEndRef = useRef(null);
|
|
624
|
+
useEffect(() => {
|
|
625
|
+
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
626
|
+
}, [messages]);
|
|
627
|
+
const MessageBubble = ({ message }) => {
|
|
628
|
+
const isUser = message.role === "user";
|
|
629
|
+
return /* @__PURE__ */ jsxs("div", { style: getMessageContainerStyles(isUser), children: [
|
|
630
|
+
/* @__PURE__ */ jsx("style", { children: getMarkdownElementStyles(isUser) }),
|
|
631
|
+
/* @__PURE__ */ jsxs("div", { style: getMessageBubbleStyles(isUser), children: [
|
|
632
|
+
/* @__PURE__ */ jsx("div", { style: getMarkdownStyles(), className: "markdown-content", children: /* @__PURE__ */ jsx(ReactMarkdown, { remarkPlugins: [remarkGfm], children: message.content }) }),
|
|
633
|
+
message.isTyping && /* @__PURE__ */ jsx("div", { style: {
|
|
634
|
+
display: "inline-flex",
|
|
635
|
+
alignItems: "center",
|
|
636
|
+
marginLeft: "8px"
|
|
637
|
+
}, children: /* @__PURE__ */ jsx(TypingDots, {}) })
|
|
638
|
+
] }),
|
|
639
|
+
/* @__PURE__ */ jsx("div", { style: getTimeStyles(isUser), children: message.timestamp.toLocaleTimeString("tr-TR", {
|
|
640
|
+
hour: "2-digit",
|
|
641
|
+
minute: "2-digit"
|
|
642
|
+
}) })
|
|
643
|
+
] });
|
|
644
|
+
};
|
|
645
|
+
const TypingDots = () => {
|
|
646
|
+
const [dots, setDots] = useState("");
|
|
647
|
+
useEffect(() => {
|
|
648
|
+
const interval = setInterval(() => {
|
|
649
|
+
setDots((prev) => {
|
|
650
|
+
if (prev === "...") return "";
|
|
651
|
+
return prev + ".";
|
|
652
|
+
});
|
|
653
|
+
}, 500);
|
|
654
|
+
return () => clearInterval(interval);
|
|
655
|
+
}, []);
|
|
656
|
+
return /* @__PURE__ */ jsx("span", { children: dots });
|
|
657
|
+
};
|
|
658
|
+
const ChatInput = () => {
|
|
659
|
+
const [message, setMessage] = useState("");
|
|
660
|
+
const textareaRef = useRef(null);
|
|
661
|
+
const handleSubmit = (e) => {
|
|
662
|
+
e.preventDefault();
|
|
663
|
+
if (message.trim() && !isLoading) {
|
|
664
|
+
handleSendMessage(message.trim());
|
|
665
|
+
setMessage("");
|
|
666
|
+
if (textareaRef.current) {
|
|
667
|
+
textareaRef.current.style.height = "auto";
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
const handleKeyDown = (e) => {
|
|
672
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
673
|
+
e.preventDefault();
|
|
674
|
+
handleSubmit(e);
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
const handleInputChange = (e) => {
|
|
678
|
+
setMessage(e.target.value);
|
|
679
|
+
const textarea = e.target;
|
|
680
|
+
textarea.style.height = "auto";
|
|
681
|
+
textarea.style.height = Math.min(textarea.scrollHeight, 120) + "px";
|
|
682
|
+
};
|
|
683
|
+
return /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, style: getInputContainerStyles(), children: [
|
|
684
|
+
/* @__PURE__ */ jsx(
|
|
685
|
+
"textarea",
|
|
686
|
+
{
|
|
687
|
+
ref: textareaRef,
|
|
688
|
+
value: message,
|
|
689
|
+
onChange: handleInputChange,
|
|
690
|
+
onKeyDown: handleKeyDown,
|
|
691
|
+
placeholder,
|
|
692
|
+
disabled: isLoading,
|
|
693
|
+
style: getTextareaStyles(isLoading)
|
|
694
|
+
}
|
|
695
|
+
),
|
|
696
|
+
/* @__PURE__ */ jsx(
|
|
697
|
+
"button",
|
|
698
|
+
{
|
|
699
|
+
type: "submit",
|
|
700
|
+
disabled: isLoading || !message.trim(),
|
|
701
|
+
style: getSendButtonStyles(isLoading, !!message.trim()),
|
|
702
|
+
onMouseEnter: (e) => {
|
|
703
|
+
if (!isLoading && message.trim()) {
|
|
704
|
+
e.currentTarget.style.transform = "scale(1.05)";
|
|
705
|
+
}
|
|
706
|
+
},
|
|
707
|
+
onMouseLeave: (e) => {
|
|
708
|
+
e.currentTarget.style.transform = "scale(1)";
|
|
709
|
+
},
|
|
710
|
+
children: isLoading ? /* @__PURE__ */ jsx(LoadingSpinner, {}) : /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M2.01 21L23 12 2.01 3 2 10l15 2-15 2z" }) })
|
|
711
|
+
}
|
|
712
|
+
)
|
|
713
|
+
] });
|
|
714
|
+
};
|
|
715
|
+
const LoadingSpinner = () => {
|
|
716
|
+
return /* @__PURE__ */ jsx("div", { style: getLoadingSpinnerStyles() });
|
|
717
|
+
};
|
|
718
|
+
if (isConfigLoading) {
|
|
719
|
+
return /* @__PURE__ */ jsx("div", { style: getFloatingButtonStyles(buttonPosition, buttonSize, buttonBackground, false), children: /* @__PURE__ */ jsx("div", { style: getLoadingSpinnerStyles() }) });
|
|
720
|
+
}
|
|
721
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
722
|
+
isOpen && /* @__PURE__ */ jsx(
|
|
723
|
+
"div",
|
|
724
|
+
{
|
|
725
|
+
style: getOverlayStyles(isOpen),
|
|
726
|
+
onClick: toggleChat,
|
|
727
|
+
className: "floating-chat-overlay"
|
|
728
|
+
}
|
|
729
|
+
),
|
|
730
|
+
/* @__PURE__ */ jsx("div", { style: getChatContainerStyles(buttonPosition, chatWidth, chatHeight, isOpen), className: "floating-chat-container", children: /* @__PURE__ */ jsxs("div", { style: getChatbotContainerStyles(), children: [
|
|
731
|
+
/* @__PURE__ */ jsxs("div", { style: getHeaderStyles(headerBackground), children: [
|
|
732
|
+
/* @__PURE__ */ jsx("div", { style: getLogoContainerStyles(), children: companyLogo ? companyLogo.startsWith("http") || companyLogo.startsWith("data:") ? /* @__PURE__ */ jsx(
|
|
733
|
+
"img",
|
|
734
|
+
{
|
|
735
|
+
src: companyLogo,
|
|
736
|
+
alt: "Company Logo",
|
|
737
|
+
style: getLogoImageStyles()
|
|
738
|
+
}
|
|
739
|
+
) : /* @__PURE__ */ jsx("span", { style: getLogoTextStyles(), children: companyLogo }) : "\u{1F916}" }),
|
|
740
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
741
|
+
/* @__PURE__ */ jsx("h3", { style: getCompanyNameStyles(), children: companyName }),
|
|
742
|
+
/* @__PURE__ */ jsx("p", { style: getStatusTextStyles(), children: isLoading ? "Yaz\u0131yor..." : "\xC7evrimi\xE7i" })
|
|
743
|
+
] })
|
|
744
|
+
] }),
|
|
745
|
+
/* @__PURE__ */ jsxs("div", { style: getMessagesContainerStyles(), children: [
|
|
746
|
+
messages.length === 0 ? /* @__PURE__ */ jsxs("div", { style: getEmptyStateStyles(), children: [
|
|
747
|
+
/* @__PURE__ */ jsx("div", { style: { fontSize: "48px", marginBottom: "16px" }, children: "\u{1F4AC}" }),
|
|
748
|
+
/* @__PURE__ */ jsx("h4", { style: { margin: "0 0 8px 0", fontSize: "18px" }, children: welcomeMessage }),
|
|
749
|
+
/* @__PURE__ */ jsx("p", { style: { margin: 0, fontSize: "14px", opacity: 0.8 }, children: "A\u015Fa\u011F\u0131daki alana mesaj\u0131n\u0131z\u0131 yazarak ba\u015Flayabilirsiniz." })
|
|
750
|
+
] }) : messages.map((message) => /* @__PURE__ */ jsx(MessageBubble, { message }, message.id)),
|
|
751
|
+
showTypingIndicator && isLoading && messages.length > 0 && /* @__PURE__ */ jsx(
|
|
752
|
+
MessageBubble,
|
|
753
|
+
{
|
|
754
|
+
message: {
|
|
755
|
+
id: "typing",
|
|
756
|
+
content: "",
|
|
757
|
+
role: "assistant",
|
|
758
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
759
|
+
isTyping: true
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
),
|
|
763
|
+
/* @__PURE__ */ jsx("div", { ref: messagesEndRef })
|
|
764
|
+
] }),
|
|
765
|
+
/* @__PURE__ */ jsx(ChatInput, {})
|
|
766
|
+
] }) }),
|
|
767
|
+
/* @__PURE__ */ jsx(
|
|
768
|
+
"button",
|
|
769
|
+
{
|
|
770
|
+
onClick: toggleChat,
|
|
771
|
+
style: getFloatingButtonStyles(buttonPosition, buttonSize, buttonBackground, isOpen),
|
|
772
|
+
onMouseEnter: (e) => {
|
|
773
|
+
e.currentTarget.style.transform = isOpen ? "scale(0.85)" : "scale(1.1)";
|
|
774
|
+
e.currentTarget.style.boxShadow = "0 6px 20px rgba(0, 0, 0, 0.25)";
|
|
775
|
+
},
|
|
776
|
+
onMouseLeave: (e) => {
|
|
777
|
+
e.currentTarget.style.transform = isOpen ? "scale(0.9)" : "scale(1)";
|
|
778
|
+
e.currentTarget.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.15)";
|
|
779
|
+
},
|
|
780
|
+
className: "floating-chat-button",
|
|
781
|
+
"aria-label": isOpen ? "Chati kapat" : "Chati a\xE7",
|
|
782
|
+
children: isOpen ? /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" }) }) : /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M20 2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h4l4 4 4-4h4c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-2 12H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z" }) })
|
|
783
|
+
}
|
|
784
|
+
)
|
|
785
|
+
] });
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
export { AizekChatBot, Button, useChatbot };
|
|
789
|
+
//# sourceMappingURL=index.mjs.map
|
|
790
|
+
//# sourceMappingURL=index.mjs.map
|