aizek-chatbot 1.0.28 → 1.0.30
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 +64 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +64 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -495,17 +495,7 @@ var extractUIJsonFromText = (text) => {
|
|
|
495
495
|
uiData
|
|
496
496
|
};
|
|
497
497
|
};
|
|
498
|
-
var AizekChatBot = ({
|
|
499
|
-
clientId,
|
|
500
|
-
headers,
|
|
501
|
-
onMounted,
|
|
502
|
-
onReady,
|
|
503
|
-
onOpen,
|
|
504
|
-
onClose,
|
|
505
|
-
onMessage,
|
|
506
|
-
onToolCall,
|
|
507
|
-
onDisconnect
|
|
508
|
-
}) => {
|
|
498
|
+
var AizekChatBot = ({ clientId, headers, onMounted, onReady, onOpen, onClose, onMessage, onToolCall, onDisconnect }) => {
|
|
509
499
|
const messagesEndRef = react.useRef(null);
|
|
510
500
|
const [config, setConfig] = react.useState();
|
|
511
501
|
const [messages, setMessages] = react.useState([]);
|
|
@@ -518,6 +508,7 @@ var AizekChatBot = ({
|
|
|
518
508
|
const [activeSessionId, setActiveSessionIdState] = react.useState(null);
|
|
519
509
|
const [activeTab, setActiveTab] = react.useState("home");
|
|
520
510
|
const [messageView, setMessageView] = react.useState("list");
|
|
511
|
+
const [sessionTitleById, setSessionTitleById] = react.useState({});
|
|
521
512
|
const PROXY_BASE_URL = "https://proxy.aizek.ai/api";
|
|
522
513
|
const createNewSession = async () => {
|
|
523
514
|
const deviceId = getOrCreateDeviceId();
|
|
@@ -677,6 +668,24 @@ var AizekChatBot = ({
|
|
|
677
668
|
setMessages([]);
|
|
678
669
|
}
|
|
679
670
|
}, [activeSessionId, isConfigLoading]);
|
|
671
|
+
react.useEffect(() => {
|
|
672
|
+
if (!sessions.length) return;
|
|
673
|
+
const missing = sessions.filter((sid) => !sessionTitleById[sid]);
|
|
674
|
+
if (!missing.length) return;
|
|
675
|
+
let cancelled = false;
|
|
676
|
+
(async () => {
|
|
677
|
+
for (const sid of missing) {
|
|
678
|
+
if (cancelled) return;
|
|
679
|
+
const title = await fetchLastMessageTitle(sid);
|
|
680
|
+
if (cancelled) return;
|
|
681
|
+
if (!title) continue;
|
|
682
|
+
setSessionTitleById((prev) => prev[sid] ? prev : { ...prev, [sid]: title });
|
|
683
|
+
}
|
|
684
|
+
})();
|
|
685
|
+
return () => {
|
|
686
|
+
cancelled = true;
|
|
687
|
+
};
|
|
688
|
+
}, [sessions]);
|
|
680
689
|
const addMessage = (payload) => {
|
|
681
690
|
const newMessage = {
|
|
682
691
|
text: payload.text,
|
|
@@ -821,9 +830,48 @@ var AizekChatBot = ({
|
|
|
821
830
|
setActiveTab("messages");
|
|
822
831
|
setMessageView("detail");
|
|
823
832
|
};
|
|
824
|
-
const
|
|
825
|
-
|
|
826
|
-
return
|
|
833
|
+
const getSessionTitle = (sid) => {
|
|
834
|
+
if (sessionTitleById[sid]) return sessionTitleById[sid];
|
|
835
|
+
return "New conversation";
|
|
836
|
+
};
|
|
837
|
+
const fetchLastMessageTitle = async (sid) => {
|
|
838
|
+
try {
|
|
839
|
+
const deviceId = getOrCreateDeviceId();
|
|
840
|
+
const res = await fetch(`${PROXY_BASE_URL}/aizek-last-message`, {
|
|
841
|
+
method: "GET",
|
|
842
|
+
headers: {
|
|
843
|
+
"Content-Type": "application/json",
|
|
844
|
+
"x-device-id": deviceId,
|
|
845
|
+
"x-session-id": sid,
|
|
846
|
+
"x-alternate": JSON.stringify(headers)
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
const json = await res.json();
|
|
850
|
+
if (!json?.success) return null;
|
|
851
|
+
const last = json?.data?.lastMessage;
|
|
852
|
+
if (!last) return null;
|
|
853
|
+
let textContent = "";
|
|
854
|
+
if (typeof last.content === "string") {
|
|
855
|
+
textContent = last.content;
|
|
856
|
+
} else if (Array.isArray(last.content)) {
|
|
857
|
+
const parts = [];
|
|
858
|
+
for (const item of last.content) {
|
|
859
|
+
if (item?.type === "text" && typeof item.text === "string") parts.push(item.text);
|
|
860
|
+
}
|
|
861
|
+
textContent = parts.join("\n");
|
|
862
|
+
}
|
|
863
|
+
if (!textContent.trim()) return null;
|
|
864
|
+
const extracted = extractUIJsonFromText(textContent);
|
|
865
|
+
const cleaned = (extracted.cleanedText || "").trim();
|
|
866
|
+
const firstLine = (cleaned.split("\n").find((l) => l.trim()) || "").trim();
|
|
867
|
+
const title = firstLine || cleaned;
|
|
868
|
+
if (!title) return null;
|
|
869
|
+
const compact = title.length > 46 ? `${title.slice(0, 46).trim()}\u2026` : title;
|
|
870
|
+
return compact;
|
|
871
|
+
} catch (e) {
|
|
872
|
+
console.error("Failed to fetch last message title:", e);
|
|
873
|
+
return null;
|
|
874
|
+
}
|
|
827
875
|
};
|
|
828
876
|
const toggleChat = () => {
|
|
829
877
|
const newIsOpen = !isOpen;
|
|
@@ -927,7 +975,7 @@ var AizekChatBot = ({
|
|
|
927
975
|
onClick: () => handleSelectSession(sid),
|
|
928
976
|
children: [
|
|
929
977
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "conversation-meta", children: [
|
|
930
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "conversation-title", children:
|
|
978
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "conversation-title", children: getSessionTitle(sid) }),
|
|
931
979
|
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "conversation-sub", children: [
|
|
932
980
|
"Session ID: ",
|
|
933
981
|
sid.slice(0, 8),
|
|
@@ -963,7 +1011,7 @@ var AizekChatBot = ({
|
|
|
963
1011
|
) }) }),
|
|
964
1012
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "detail-title", children: [
|
|
965
1013
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "detail-title-row", children: [
|
|
966
|
-
/* @__PURE__ */ jsxRuntime.jsx("strong", { className: "detail-title-text", children: activeSessionId ?
|
|
1014
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { className: "detail-title-text", children: activeSessionId ? getSessionTitle(activeSessionId) : "Chat" }),
|
|
967
1015
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: `status-dot ${isLoading ? "typing" : "online"}`, "aria-hidden": "true" })
|
|
968
1016
|
] }),
|
|
969
1017
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "detail-subtitle", children: isLoading ? "Yaz\u0131yor\u2026" : "Online" })
|