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.mjs
CHANGED
|
@@ -487,17 +487,7 @@ var extractUIJsonFromText = (text) => {
|
|
|
487
487
|
uiData
|
|
488
488
|
};
|
|
489
489
|
};
|
|
490
|
-
var AizekChatBot = ({
|
|
491
|
-
clientId,
|
|
492
|
-
headers,
|
|
493
|
-
onMounted,
|
|
494
|
-
onReady,
|
|
495
|
-
onOpen,
|
|
496
|
-
onClose,
|
|
497
|
-
onMessage,
|
|
498
|
-
onToolCall,
|
|
499
|
-
onDisconnect
|
|
500
|
-
}) => {
|
|
490
|
+
var AizekChatBot = ({ clientId, headers, onMounted, onReady, onOpen, onClose, onMessage, onToolCall, onDisconnect }) => {
|
|
501
491
|
const messagesEndRef = useRef(null);
|
|
502
492
|
const [config, setConfig] = useState();
|
|
503
493
|
const [messages, setMessages] = useState([]);
|
|
@@ -510,6 +500,7 @@ var AizekChatBot = ({
|
|
|
510
500
|
const [activeSessionId, setActiveSessionIdState] = useState(null);
|
|
511
501
|
const [activeTab, setActiveTab] = useState("home");
|
|
512
502
|
const [messageView, setMessageView] = useState("list");
|
|
503
|
+
const [sessionTitleById, setSessionTitleById] = useState({});
|
|
513
504
|
const PROXY_BASE_URL = "https://proxy.aizek.ai/api";
|
|
514
505
|
const createNewSession = async () => {
|
|
515
506
|
const deviceId = getOrCreateDeviceId();
|
|
@@ -669,6 +660,24 @@ var AizekChatBot = ({
|
|
|
669
660
|
setMessages([]);
|
|
670
661
|
}
|
|
671
662
|
}, [activeSessionId, isConfigLoading]);
|
|
663
|
+
useEffect(() => {
|
|
664
|
+
if (!sessions.length) return;
|
|
665
|
+
const missing = sessions.filter((sid) => !sessionTitleById[sid]);
|
|
666
|
+
if (!missing.length) return;
|
|
667
|
+
let cancelled = false;
|
|
668
|
+
(async () => {
|
|
669
|
+
for (const sid of missing) {
|
|
670
|
+
if (cancelled) return;
|
|
671
|
+
const title = await fetchLastMessageTitle(sid);
|
|
672
|
+
if (cancelled) return;
|
|
673
|
+
if (!title) continue;
|
|
674
|
+
setSessionTitleById((prev) => prev[sid] ? prev : { ...prev, [sid]: title });
|
|
675
|
+
}
|
|
676
|
+
})();
|
|
677
|
+
return () => {
|
|
678
|
+
cancelled = true;
|
|
679
|
+
};
|
|
680
|
+
}, [sessions]);
|
|
672
681
|
const addMessage = (payload) => {
|
|
673
682
|
const newMessage = {
|
|
674
683
|
text: payload.text,
|
|
@@ -813,9 +822,48 @@ var AizekChatBot = ({
|
|
|
813
822
|
setActiveTab("messages");
|
|
814
823
|
setMessageView("detail");
|
|
815
824
|
};
|
|
816
|
-
const
|
|
817
|
-
|
|
818
|
-
return
|
|
825
|
+
const getSessionTitle = (sid) => {
|
|
826
|
+
if (sessionTitleById[sid]) return sessionTitleById[sid];
|
|
827
|
+
return "New conversation";
|
|
828
|
+
};
|
|
829
|
+
const fetchLastMessageTitle = async (sid) => {
|
|
830
|
+
try {
|
|
831
|
+
const deviceId = getOrCreateDeviceId();
|
|
832
|
+
const res = await fetch(`${PROXY_BASE_URL}/aizek-last-message`, {
|
|
833
|
+
method: "GET",
|
|
834
|
+
headers: {
|
|
835
|
+
"Content-Type": "application/json",
|
|
836
|
+
"x-device-id": deviceId,
|
|
837
|
+
"x-session-id": sid,
|
|
838
|
+
"x-alternate": JSON.stringify(headers)
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
const json = await res.json();
|
|
842
|
+
if (!json?.success) return null;
|
|
843
|
+
const last = json?.data?.lastMessage;
|
|
844
|
+
if (!last) return null;
|
|
845
|
+
let textContent = "";
|
|
846
|
+
if (typeof last.content === "string") {
|
|
847
|
+
textContent = last.content;
|
|
848
|
+
} else if (Array.isArray(last.content)) {
|
|
849
|
+
const parts = [];
|
|
850
|
+
for (const item of last.content) {
|
|
851
|
+
if (item?.type === "text" && typeof item.text === "string") parts.push(item.text);
|
|
852
|
+
}
|
|
853
|
+
textContent = parts.join("\n");
|
|
854
|
+
}
|
|
855
|
+
if (!textContent.trim()) return null;
|
|
856
|
+
const extracted = extractUIJsonFromText(textContent);
|
|
857
|
+
const cleaned = (extracted.cleanedText || "").trim();
|
|
858
|
+
const firstLine = (cleaned.split("\n").find((l) => l.trim()) || "").trim();
|
|
859
|
+
const title = firstLine || cleaned;
|
|
860
|
+
if (!title) return null;
|
|
861
|
+
const compact = title.length > 46 ? `${title.slice(0, 46).trim()}\u2026` : title;
|
|
862
|
+
return compact;
|
|
863
|
+
} catch (e) {
|
|
864
|
+
console.error("Failed to fetch last message title:", e);
|
|
865
|
+
return null;
|
|
866
|
+
}
|
|
819
867
|
};
|
|
820
868
|
const toggleChat = () => {
|
|
821
869
|
const newIsOpen = !isOpen;
|
|
@@ -919,7 +967,7 @@ var AizekChatBot = ({
|
|
|
919
967
|
onClick: () => handleSelectSession(sid),
|
|
920
968
|
children: [
|
|
921
969
|
/* @__PURE__ */ jsxs("div", { className: "conversation-meta", children: [
|
|
922
|
-
/* @__PURE__ */ jsx("p", { className: "conversation-title", children:
|
|
970
|
+
/* @__PURE__ */ jsx("p", { className: "conversation-title", children: getSessionTitle(sid) }),
|
|
923
971
|
/* @__PURE__ */ jsxs("p", { className: "conversation-sub", children: [
|
|
924
972
|
"Session ID: ",
|
|
925
973
|
sid.slice(0, 8),
|
|
@@ -955,7 +1003,7 @@ var AizekChatBot = ({
|
|
|
955
1003
|
) }) }),
|
|
956
1004
|
/* @__PURE__ */ jsxs("div", { className: "detail-title", children: [
|
|
957
1005
|
/* @__PURE__ */ jsxs("div", { className: "detail-title-row", children: [
|
|
958
|
-
/* @__PURE__ */ jsx("strong", { className: "detail-title-text", children: activeSessionId ?
|
|
1006
|
+
/* @__PURE__ */ jsx("strong", { className: "detail-title-text", children: activeSessionId ? getSessionTitle(activeSessionId) : "Chat" }),
|
|
959
1007
|
/* @__PURE__ */ jsx("span", { className: `status-dot ${isLoading ? "typing" : "online"}`, "aria-hidden": "true" })
|
|
960
1008
|
] }),
|
|
961
1009
|
/* @__PURE__ */ jsx("p", { className: "detail-subtitle", children: isLoading ? "Yaz\u0131yor\u2026" : "Online" })
|