aizek-chatbot 1.0.6 → 1.0.8
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 +252 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +252 -40
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -9,6 +9,25 @@ import remarkGfm from 'remark-gfm';
|
|
|
9
9
|
function cx(...args) {
|
|
10
10
|
return args.filter(Boolean).join(" ");
|
|
11
11
|
}
|
|
12
|
+
function validateHeaders(headers, authConfig, opts = {}) {
|
|
13
|
+
const { caseSensitive = false, allowExtra = false } = opts;
|
|
14
|
+
const normalize = (s) => caseSensitive ? s : s.toLowerCase();
|
|
15
|
+
const headerEntries = Object.entries(headers).map(([k, v]) => [normalize(k), v.trim()]);
|
|
16
|
+
const authEntries = Object.entries(authConfig).map(([k, v]) => [normalize(k), v.trim()]);
|
|
17
|
+
const headerKeys = headerEntries.map(([k]) => k);
|
|
18
|
+
const authKeys = authEntries.map(([k]) => k);
|
|
19
|
+
const requiredSet = new Set(authKeys);
|
|
20
|
+
const missingKeys = authKeys.filter((k) => !headerKeys.includes(k));
|
|
21
|
+
const extraKeys = headerKeys.filter((k) => !requiredSet.has(k));
|
|
22
|
+
const hasAllRequired = missingKeys.length === 0;
|
|
23
|
+
const hasExtraKeys = extraKeys.length > 0 && !allowExtra;
|
|
24
|
+
const emptyValueKeys = authKeys.filter((k) => {
|
|
25
|
+
const val = headerEntries.find(([key]) => key === k)?.[1];
|
|
26
|
+
return !val || val.length === 0;
|
|
27
|
+
});
|
|
28
|
+
const isValid = hasAllRequired && !hasExtraKeys && emptyValueKeys.length === 0;
|
|
29
|
+
return { isValid, missingKeys, extraKeys, emptyValueKeys };
|
|
30
|
+
}
|
|
12
31
|
var base = {
|
|
13
32
|
display: "inline-flex",
|
|
14
33
|
alignItems: "center",
|
|
@@ -102,44 +121,21 @@ var useChatbot = (options = {}) => {
|
|
|
102
121
|
setIsLoading(true);
|
|
103
122
|
try {
|
|
104
123
|
let resp;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
],
|
|
121
|
-
input: message,
|
|
122
|
-
previous_response_id: responseId || void 0
|
|
123
|
-
});
|
|
124
|
-
} else {
|
|
125
|
-
resp = await client.responses.create({
|
|
126
|
-
model: "gpt-5",
|
|
127
|
-
tools: [
|
|
128
|
-
{
|
|
129
|
-
type: "mcp",
|
|
130
|
-
server_label: "aizek-mcp",
|
|
131
|
-
server_url: mcpUrl,
|
|
132
|
-
require_approval: "never",
|
|
133
|
-
headers: {
|
|
134
|
-
brandId: "c5bfc750-69fd-4653-8dbb-f01614bc3319",
|
|
135
|
-
"privy-token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IlNLb3JzbjRsMnJWSllrNEFrd0EtY0NaVVY1M0ticUQ2eHZ6UTNPeDdsY3cifQ.eyJzaWQiOiJjbWdqN25yb3EwMWRqbGEwY2M3a3hoamVzIiwiaXNzIjoicHJpdnkuaW8iLCJpYXQiOjE3NjAwMTMzMTYsImF1ZCI6ImNsc3U1eWM4NTA4d2hpMGZhZWR1a2Uxd3MiLCJzdWIiOiJkaWQ6cHJpdnk6Y2x0Y3d4MTNuMGkwNTEyeXRmNWI5d3NzdSIsImV4cCI6MTc2MDAxNjkxNn0.qzUpTuk5e8W0mggf4FTAAP3zZyjJjwpMi-QXU_2pLO9kgfMV5IYPzymR9XjTEBMfJxgC9dApMDvOAX8MvX7URw"
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
],
|
|
139
|
-
input: message,
|
|
140
|
-
previous_response_id: responseId || void 0
|
|
141
|
-
});
|
|
142
|
-
}
|
|
124
|
+
console.log(options.headers);
|
|
125
|
+
resp = await client.responses.create({
|
|
126
|
+
model: "gpt-5",
|
|
127
|
+
tools: [
|
|
128
|
+
{
|
|
129
|
+
type: "mcp",
|
|
130
|
+
server_label: "aizek-mcp",
|
|
131
|
+
server_url: mcpUrl,
|
|
132
|
+
require_approval: "never",
|
|
133
|
+
headers: options.headers || {}
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
input: message,
|
|
137
|
+
previous_response_id: responseId || void 0
|
|
138
|
+
});
|
|
143
139
|
setResponseId(resp.id);
|
|
144
140
|
let responseText = "";
|
|
145
141
|
if (resp && Array.isArray(resp)) {
|
|
@@ -190,6 +186,7 @@ var fetchChatWidgetSettings = async (clientId) => {
|
|
|
190
186
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
191
187
|
}
|
|
192
188
|
const data = await response.json();
|
|
189
|
+
console.log(data);
|
|
193
190
|
return data;
|
|
194
191
|
} catch (error) {
|
|
195
192
|
console.error("Error fetching chat widget settings:", error);
|
|
@@ -595,7 +592,110 @@ var getLoadingSpinnerStyles = () => ({
|
|
|
595
592
|
borderRadius: "50%",
|
|
596
593
|
animation: "spin 1s linear infinite"
|
|
597
594
|
});
|
|
598
|
-
|
|
595
|
+
|
|
596
|
+
// src/styles/alertStyles.ts
|
|
597
|
+
var getAlertContainerStyles = (type) => {
|
|
598
|
+
const colors = {
|
|
599
|
+
error: {
|
|
600
|
+
background: "linear-gradient(135deg, #ef4444 0%, #dc2626 100%)",
|
|
601
|
+
border: "#dc2626",
|
|
602
|
+
shadow: "rgba(239, 68, 68, 0.2)"
|
|
603
|
+
},
|
|
604
|
+
warning: {
|
|
605
|
+
background: "linear-gradient(135deg, #f59e0b 0%, #d97706 100%)",
|
|
606
|
+
border: "#d97706",
|
|
607
|
+
shadow: "rgba(245, 158, 11, 0.2)"
|
|
608
|
+
},
|
|
609
|
+
success: {
|
|
610
|
+
background: "linear-gradient(135deg, #10b981 0%, #059669 100%)",
|
|
611
|
+
border: "#059669",
|
|
612
|
+
shadow: "rgba(16, 185, 129, 0.2)"
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
const selectedColor = colors[type];
|
|
616
|
+
return {
|
|
617
|
+
background: selectedColor.background,
|
|
618
|
+
border: `1px solid ${selectedColor.border}`,
|
|
619
|
+
borderRadius: "12px",
|
|
620
|
+
padding: "14px 16px",
|
|
621
|
+
margin: "12px 16px",
|
|
622
|
+
boxShadow: `0 4px 12px ${selectedColor.shadow}`,
|
|
623
|
+
color: "#ffffff",
|
|
624
|
+
fontSize: "13px",
|
|
625
|
+
display: "flex",
|
|
626
|
+
alignItems: "flex-start",
|
|
627
|
+
gap: "12px",
|
|
628
|
+
position: "relative",
|
|
629
|
+
animation: "slideDown 0.3s ease-out"
|
|
630
|
+
};
|
|
631
|
+
};
|
|
632
|
+
var getAlertIconContainerStyles = () => ({
|
|
633
|
+
display: "flex",
|
|
634
|
+
alignItems: "center",
|
|
635
|
+
justifyContent: "center",
|
|
636
|
+
width: "24px",
|
|
637
|
+
height: "24px",
|
|
638
|
+
flexShrink: 0,
|
|
639
|
+
marginTop: "2px"
|
|
640
|
+
});
|
|
641
|
+
var getAlertContentStyles = () => ({
|
|
642
|
+
flex: 1,
|
|
643
|
+
display: "flex",
|
|
644
|
+
flexDirection: "column",
|
|
645
|
+
gap: "8px"
|
|
646
|
+
});
|
|
647
|
+
var getAlertTitleStyles = () => ({
|
|
648
|
+
fontWeight: 600,
|
|
649
|
+
fontSize: "14px",
|
|
650
|
+
margin: 0,
|
|
651
|
+
lineHeight: 1.4
|
|
652
|
+
});
|
|
653
|
+
var getAlertMessageStyles = () => ({
|
|
654
|
+
margin: 0,
|
|
655
|
+
lineHeight: 1.5,
|
|
656
|
+
opacity: 0.95
|
|
657
|
+
});
|
|
658
|
+
var getAlertListStyles = () => ({
|
|
659
|
+
margin: "8px 0 0 0",
|
|
660
|
+
paddingLeft: "20px",
|
|
661
|
+
listStyle: "none"
|
|
662
|
+
});
|
|
663
|
+
var getAlertListItemStyles = () => ({
|
|
664
|
+
marginBottom: "4px",
|
|
665
|
+
position: "relative",
|
|
666
|
+
paddingLeft: "12px",
|
|
667
|
+
lineHeight: 1.4
|
|
668
|
+
});
|
|
669
|
+
var getAlertCloseButtonStyles = () => ({
|
|
670
|
+
position: "absolute",
|
|
671
|
+
top: "12px",
|
|
672
|
+
right: "12px",
|
|
673
|
+
background: "rgba(255, 255, 255, 0.2)",
|
|
674
|
+
border: "none",
|
|
675
|
+
borderRadius: "6px",
|
|
676
|
+
width: "24px",
|
|
677
|
+
height: "24px",
|
|
678
|
+
display: "flex",
|
|
679
|
+
alignItems: "center",
|
|
680
|
+
justifyContent: "center",
|
|
681
|
+
cursor: "pointer",
|
|
682
|
+
color: "#ffffff",
|
|
683
|
+
transition: "all 0.2s ease",
|
|
684
|
+
padding: 0
|
|
685
|
+
});
|
|
686
|
+
var getAlertAnimationStyles = () => `
|
|
687
|
+
@keyframes slideDown {
|
|
688
|
+
from {
|
|
689
|
+
opacity: 0;
|
|
690
|
+
transform: translateY(-10px);
|
|
691
|
+
}
|
|
692
|
+
to {
|
|
693
|
+
opacity: 1;
|
|
694
|
+
transform: translateY(0);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
`;
|
|
698
|
+
var AizekChatBot = ({ clientId, headers }) => {
|
|
599
699
|
const defaultConfig = {
|
|
600
700
|
welcomeMessage: "Merhaba! Size nas\u0131l yard\u0131mc\u0131 olabilirim?",
|
|
601
701
|
buttonBackground: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
|
|
@@ -614,13 +714,24 @@ var AizekChatBot = ({ clientId, userToken }) => {
|
|
|
614
714
|
const [isConfigLoading, setIsConfigLoading] = useState(true);
|
|
615
715
|
const [finalMcpUrl, setFinalMcpUrl] = useState("");
|
|
616
716
|
const [apiKey, setApiKey] = useState("");
|
|
717
|
+
const [validConfig, setValidConfig] = useState(false);
|
|
617
718
|
const { welcomeMessage, buttonBackground, placeholder, buttonPosition, buttonSize, chatWidth, chatHeight, showTypingIndicator, initialOpen, headerBackground, companyLogo, companyName } = config;
|
|
618
719
|
const [isOpen, setIsOpen] = useState(false);
|
|
720
|
+
const [headerValidation, setHeaderValidation] = useState(null);
|
|
721
|
+
const [showAlert, setShowAlert] = useState(true);
|
|
619
722
|
useEffect(() => {
|
|
620
723
|
const loadConfig = async () => {
|
|
621
724
|
try {
|
|
622
725
|
setIsConfigLoading(true);
|
|
623
726
|
const apiResponse = await fetchChatWidgetSettings(clientId);
|
|
727
|
+
if (headers && apiResponse.data.auth_config) {
|
|
728
|
+
const validationResult = validateHeaders(headers, apiResponse.data.auth_config, {
|
|
729
|
+
allowExtra: false,
|
|
730
|
+
caseSensitive: true
|
|
731
|
+
});
|
|
732
|
+
console.log(validationResult);
|
|
733
|
+
setHeaderValidation(validationResult);
|
|
734
|
+
}
|
|
624
735
|
setFinalMcpUrl(apiResponse.data.mcp_url);
|
|
625
736
|
setApiKey(apiResponse.data.openai_key || "");
|
|
626
737
|
const apiConfig = mapApiSettingsToConfig(apiResponse.data.chat_widget_settings);
|
|
@@ -636,7 +747,7 @@ var AizekChatBot = ({ clientId, userToken }) => {
|
|
|
636
747
|
};
|
|
637
748
|
loadConfig();
|
|
638
749
|
}, [clientId]);
|
|
639
|
-
const internalChatbot = useChatbot({ mcpUrl: finalMcpUrl, apiKey,
|
|
750
|
+
const internalChatbot = useChatbot({ mcpUrl: finalMcpUrl, apiKey, headers });
|
|
640
751
|
const messages = internalChatbot.messages;
|
|
641
752
|
const isLoading = internalChatbot.isLoading;
|
|
642
753
|
const handleSendMessage = internalChatbot.sendMessage;
|
|
@@ -682,6 +793,106 @@ var AizekChatBot = ({ clientId, userToken }) => {
|
|
|
682
793
|
}, []);
|
|
683
794
|
return /* @__PURE__ */ jsx("span", { children: dots });
|
|
684
795
|
};
|
|
796
|
+
const HeaderValidationAlert = () => {
|
|
797
|
+
if (!headerValidation || !showAlert) return null;
|
|
798
|
+
const { isValid, missingKeys, extraKeys, emptyValueKeys } = headerValidation;
|
|
799
|
+
if (isValid && missingKeys.length === 0 && extraKeys.length === 0 && emptyValueKeys.length === 0) {
|
|
800
|
+
return null;
|
|
801
|
+
}
|
|
802
|
+
const hasErrors = missingKeys.length > 0 || emptyValueKeys.length > 0;
|
|
803
|
+
const hasWarnings = extraKeys.length > 0;
|
|
804
|
+
const alertType = hasErrors ? "error" : "warning";
|
|
805
|
+
const getAlertIcon = () => {
|
|
806
|
+
if (hasErrors) {
|
|
807
|
+
return /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z" }) });
|
|
808
|
+
}
|
|
809
|
+
return /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ jsx("path", { d: "M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z" }) });
|
|
810
|
+
};
|
|
811
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
812
|
+
/* @__PURE__ */ jsx("style", { children: getAlertAnimationStyles() }),
|
|
813
|
+
/* @__PURE__ */ jsxs("div", { style: getAlertContainerStyles(alertType), children: [
|
|
814
|
+
/* @__PURE__ */ jsx("div", { style: getAlertIconContainerStyles(), children: getAlertIcon() }),
|
|
815
|
+
/* @__PURE__ */ jsxs("div", { style: getAlertContentStyles(), children: [
|
|
816
|
+
/* @__PURE__ */ jsx("h4", { style: getAlertTitleStyles(), children: hasErrors ? "Header Do\u011Frulama Hatas\u0131" : "Header Uyar\u0131s\u0131" }),
|
|
817
|
+
/* @__PURE__ */ jsx("p", { style: getAlertMessageStyles(), children: hasErrors && hasWarnings ? "Header yap\u0131land\u0131rman\u0131zda hatalar ve uyar\u0131lar bulundu." : hasErrors ? "Header yap\u0131land\u0131rman\u0131zda hatalar bulundu." : "Header yap\u0131land\u0131rman\u0131zda fazla anahtarlar bulundu." }),
|
|
818
|
+
missingKeys.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
819
|
+
/* @__PURE__ */ jsx("strong", { style: { fontSize: "13px" }, children: "Eksik Header'lar:" }),
|
|
820
|
+
/* @__PURE__ */ jsx("ul", { style: getAlertListStyles(), children: missingKeys.map((key, index) => /* @__PURE__ */ jsxs("li", { style: getAlertListItemStyles(), children: [
|
|
821
|
+
/* @__PURE__ */ jsx("span", { style: {
|
|
822
|
+
position: "absolute",
|
|
823
|
+
left: "0",
|
|
824
|
+
top: "2px",
|
|
825
|
+
fontWeight: "bold"
|
|
826
|
+
}, children: "\u2022" }),
|
|
827
|
+
/* @__PURE__ */ jsx("code", { style: {
|
|
828
|
+
background: "rgba(255, 255, 255, 0.2)",
|
|
829
|
+
padding: "2px 6px",
|
|
830
|
+
borderRadius: "4px",
|
|
831
|
+
fontFamily: "monospace",
|
|
832
|
+
fontSize: "12px"
|
|
833
|
+
}, children: key })
|
|
834
|
+
] }, index)) })
|
|
835
|
+
] }),
|
|
836
|
+
emptyValueKeys.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
837
|
+
/* @__PURE__ */ jsx("strong", { style: { fontSize: "13px" }, children: "Bo\u015F De\u011Ferli Header'lar:" }),
|
|
838
|
+
/* @__PURE__ */ jsx("ul", { style: getAlertListStyles(), children: emptyValueKeys.map((key, index) => /* @__PURE__ */ jsxs("li", { style: getAlertListItemStyles(), children: [
|
|
839
|
+
/* @__PURE__ */ jsx("span", { style: {
|
|
840
|
+
position: "absolute",
|
|
841
|
+
left: "0",
|
|
842
|
+
top: "2px",
|
|
843
|
+
fontWeight: "bold"
|
|
844
|
+
}, children: "\u2022" }),
|
|
845
|
+
/* @__PURE__ */ jsx("code", { style: {
|
|
846
|
+
background: "rgba(255, 255, 255, 0.2)",
|
|
847
|
+
padding: "2px 6px",
|
|
848
|
+
borderRadius: "4px",
|
|
849
|
+
fontFamily: "monospace",
|
|
850
|
+
fontSize: "12px"
|
|
851
|
+
}, children: key }),
|
|
852
|
+
/* @__PURE__ */ jsx("span", { style: {
|
|
853
|
+
marginLeft: "6px",
|
|
854
|
+
fontSize: "11px",
|
|
855
|
+
opacity: 0.9
|
|
856
|
+
}, children: "(de\u011Fer bo\u015F olamaz)" })
|
|
857
|
+
] }, index)) })
|
|
858
|
+
] }),
|
|
859
|
+
extraKeys.length > 0 && /* @__PURE__ */ jsxs("div", { children: [
|
|
860
|
+
/* @__PURE__ */ jsx("strong", { style: { fontSize: "13px" }, children: "Fazla Header'lar:" }),
|
|
861
|
+
/* @__PURE__ */ jsx("ul", { style: getAlertListStyles(), children: extraKeys.map((key, index) => /* @__PURE__ */ jsxs("li", { style: getAlertListItemStyles(), children: [
|
|
862
|
+
/* @__PURE__ */ jsx("span", { style: {
|
|
863
|
+
position: "absolute",
|
|
864
|
+
left: "0",
|
|
865
|
+
top: "2px",
|
|
866
|
+
fontWeight: "bold"
|
|
867
|
+
}, children: "\u2022" }),
|
|
868
|
+
/* @__PURE__ */ jsx("code", { style: {
|
|
869
|
+
background: "rgba(255, 255, 255, 0.2)",
|
|
870
|
+
padding: "2px 6px",
|
|
871
|
+
borderRadius: "4px",
|
|
872
|
+
fontFamily: "monospace",
|
|
873
|
+
fontSize: "12px"
|
|
874
|
+
}, children: key })
|
|
875
|
+
] }, index)) })
|
|
876
|
+
] })
|
|
877
|
+
] }),
|
|
878
|
+
/* @__PURE__ */ jsx(
|
|
879
|
+
"button",
|
|
880
|
+
{
|
|
881
|
+
onClick: () => setShowAlert(false),
|
|
882
|
+
style: getAlertCloseButtonStyles(),
|
|
883
|
+
onMouseEnter: (e) => {
|
|
884
|
+
e.currentTarget.style.background = "rgba(255, 255, 255, 0.3)";
|
|
885
|
+
},
|
|
886
|
+
onMouseLeave: (e) => {
|
|
887
|
+
e.currentTarget.style.background = "rgba(255, 255, 255, 0.2)";
|
|
888
|
+
},
|
|
889
|
+
"aria-label": "Uyar\u0131y\u0131 kapat",
|
|
890
|
+
children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", 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" }) })
|
|
891
|
+
}
|
|
892
|
+
)
|
|
893
|
+
] })
|
|
894
|
+
] });
|
|
895
|
+
};
|
|
685
896
|
const ChatInput = () => {
|
|
686
897
|
const [message, setMessage] = useState("");
|
|
687
898
|
const textareaRef = useRef(null);
|
|
@@ -770,6 +981,7 @@ var AizekChatBot = ({ clientId, userToken }) => {
|
|
|
770
981
|
] })
|
|
771
982
|
] }),
|
|
772
983
|
/* @__PURE__ */ jsxs("div", { style: getMessagesContainerStyles(), children: [
|
|
984
|
+
/* @__PURE__ */ jsx(HeaderValidationAlert, {}),
|
|
773
985
|
messages.length === 0 ? /* @__PURE__ */ jsxs("div", { style: getEmptyStateStyles(), children: [
|
|
774
986
|
/* @__PURE__ */ jsx("div", { style: { fontSize: "48px", marginBottom: "16px" }, children: "\u{1F4AC}" }),
|
|
775
987
|
/* @__PURE__ */ jsx("h4", { style: { margin: "0 0 8px 0", fontSize: "18px" }, children: welcomeMessage }),
|