@elqnt/chat 1.0.11 → 1.0.14
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/hooks/use-websocket-chat-admin.js +35 -11
- package/dist/hooks/use-websocket-chat-admin.js.map +1 -1
- package/dist/hooks/use-websocket-chat-admin.mjs +35 -11
- package/dist/hooks/use-websocket-chat-admin.mjs.map +1 -1
- package/dist/hooks/use-websocket-chat-base.js +35 -11
- package/dist/hooks/use-websocket-chat-base.js.map +1 -1
- package/dist/hooks/use-websocket-chat-base.mjs +35 -11
- package/dist/hooks/use-websocket-chat-base.mjs.map +1 -1
- package/dist/hooks/use-websocket-chat-customer.js +35 -11
- package/dist/hooks/use-websocket-chat-customer.js.map +1 -1
- package/dist/hooks/use-websocket-chat-customer.mjs +35 -11
- package/dist/hooks/use-websocket-chat-customer.mjs.map +1 -1
- package/dist/index.js +35 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -294,7 +294,7 @@ var useWebSocketChatBase = ({
|
|
|
294
294
|
if (transportRef.current === "sse") {
|
|
295
295
|
const sseUrl = getRestApiUrl(`stream?orgId=${orgId}&userId=${userId}&clientType=${clientType}&chatId=${currentChatKeyRef.current || ""}`);
|
|
296
296
|
logger.debug("Connecting to SSE:", sseUrl);
|
|
297
|
-
console.log(`\u23F3 Initiating SSE connection to ${
|
|
297
|
+
console.log(`\u23F3 Initiating SSE connection to ${sseUrl}...`);
|
|
298
298
|
const eventSource = new EventSource(sseUrl);
|
|
299
299
|
eventSource.onopen = () => {
|
|
300
300
|
if (!mountedRef.current) {
|
|
@@ -351,6 +351,9 @@ var useWebSocketChatBase = ({
|
|
|
351
351
|
};
|
|
352
352
|
const handleSSEMessage = (event) => {
|
|
353
353
|
if (!mountedRef.current) return;
|
|
354
|
+
if (!event.data || event.data === "") {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
354
357
|
try {
|
|
355
358
|
const data = JSON.parse(event.data);
|
|
356
359
|
if (!isChatEvent(data)) {
|
|
@@ -407,7 +410,6 @@ var useWebSocketChatBase = ({
|
|
|
407
410
|
eventSource.addEventListener("chat_updated", handleSSEMessage);
|
|
408
411
|
eventSource.addEventListener("load_chat_response", handleSSEMessage);
|
|
409
412
|
eventSource.addEventListener("new_chat_created", handleSSEMessage);
|
|
410
|
-
eventSource.addEventListener("error", handleSSEMessage);
|
|
411
413
|
eventSource.addEventListener("show_csat_survey", handleSSEMessage);
|
|
412
414
|
eventSource.addEventListener("csat_response", handleSSEMessage);
|
|
413
415
|
eventSource.addEventListener("user_suggested_actions", handleSSEMessage);
|
|
@@ -752,7 +754,7 @@ var useWebSocketChatBase = ({
|
|
|
752
754
|
switch (fullEvent.type) {
|
|
753
755
|
case "message":
|
|
754
756
|
await sendRestMessage("send", {
|
|
755
|
-
orgId: fullEvent.orgId,
|
|
757
|
+
orgId: fullEvent.orgId || orgId,
|
|
756
758
|
chatKey: fullEvent.chatKey || currentChatKeyRef.current,
|
|
757
759
|
userId: fullEvent.userId,
|
|
758
760
|
message: fullEvent.message
|
|
@@ -760,7 +762,7 @@ var useWebSocketChatBase = ({
|
|
|
760
762
|
break;
|
|
761
763
|
case "typing":
|
|
762
764
|
await sendRestMessage("typing", {
|
|
763
|
-
orgId: fullEvent.orgId,
|
|
765
|
+
orgId: fullEvent.orgId || orgId,
|
|
764
766
|
chatKey: fullEvent.chatKey || currentChatKeyRef.current,
|
|
765
767
|
userId: fullEvent.userId,
|
|
766
768
|
typing: true
|
|
@@ -768,7 +770,7 @@ var useWebSocketChatBase = ({
|
|
|
768
770
|
break;
|
|
769
771
|
case "stopped_typing":
|
|
770
772
|
await sendRestMessage("typing", {
|
|
771
|
-
orgId: fullEvent.orgId,
|
|
773
|
+
orgId: fullEvent.orgId || orgId,
|
|
772
774
|
chatKey: fullEvent.chatKey || currentChatKeyRef.current,
|
|
773
775
|
userId: fullEvent.userId,
|
|
774
776
|
typing: false
|
|
@@ -776,7 +778,7 @@ var useWebSocketChatBase = ({
|
|
|
776
778
|
break;
|
|
777
779
|
case "load_chat":
|
|
778
780
|
const loadResponse = await sendRestMessage("load", {
|
|
779
|
-
orgId: fullEvent.orgId,
|
|
781
|
+
orgId: fullEvent.orgId || orgId,
|
|
780
782
|
chatKey: fullEvent.chatKey,
|
|
781
783
|
userId: fullEvent.userId
|
|
782
784
|
});
|
|
@@ -798,7 +800,7 @@ var useWebSocketChatBase = ({
|
|
|
798
800
|
break;
|
|
799
801
|
case "new_chat":
|
|
800
802
|
const createResponse = await sendRestMessage("create", {
|
|
801
|
-
orgId: fullEvent.orgId,
|
|
803
|
+
orgId: fullEvent.orgId || orgId,
|
|
802
804
|
userId: fullEvent.userId,
|
|
803
805
|
metadata: fullEvent.data
|
|
804
806
|
});
|
|
@@ -824,7 +826,7 @@ var useWebSocketChatBase = ({
|
|
|
824
826
|
break;
|
|
825
827
|
case "end_chat":
|
|
826
828
|
await sendRestMessage("end", {
|
|
827
|
-
orgId: fullEvent.orgId,
|
|
829
|
+
orgId: fullEvent.orgId || orgId,
|
|
828
830
|
chatKey: fullEvent.chatKey || currentChatKeyRef.current,
|
|
829
831
|
userId: fullEvent.userId,
|
|
830
832
|
data: fullEvent.data
|
|
@@ -832,20 +834,42 @@ var useWebSocketChatBase = ({
|
|
|
832
834
|
break;
|
|
833
835
|
case "human_agent_join":
|
|
834
836
|
await sendRestMessage("agent-join", {
|
|
835
|
-
orgId: fullEvent.orgId,
|
|
837
|
+
orgId: fullEvent.orgId || orgId,
|
|
836
838
|
chatKey: fullEvent.chatKey || currentChatKeyRef.current,
|
|
837
839
|
user: fullEvent.data?.user
|
|
838
840
|
});
|
|
839
841
|
break;
|
|
840
842
|
case "human_agent_leave":
|
|
841
843
|
await sendRestMessage("agent-leave", {
|
|
842
|
-
orgId: fullEvent.orgId,
|
|
844
|
+
orgId: fullEvent.orgId || orgId,
|
|
843
845
|
chatKey: fullEvent.chatKey || currentChatKeyRef.current,
|
|
844
846
|
user: fullEvent.data?.user
|
|
845
847
|
});
|
|
846
848
|
break;
|
|
849
|
+
// Event types that use the generic /event endpoint
|
|
850
|
+
case "load_agent_context":
|
|
851
|
+
case "skill_activate":
|
|
852
|
+
case "skill_deactivate":
|
|
853
|
+
case "sync_metadata":
|
|
854
|
+
case "plan_approved":
|
|
855
|
+
case "plan_rejected":
|
|
856
|
+
await sendRestMessage("event", {
|
|
857
|
+
type: fullEvent.type,
|
|
858
|
+
orgId: fullEvent.orgId || orgId,
|
|
859
|
+
chatKey: fullEvent.chatKey || currentChatKeyRef.current,
|
|
860
|
+
userId: fullEvent.userId,
|
|
861
|
+
data: fullEvent.data
|
|
862
|
+
});
|
|
863
|
+
break;
|
|
847
864
|
default:
|
|
848
|
-
logger.warn("
|
|
865
|
+
logger.warn("Sending unrecognized event type via generic endpoint:", fullEvent.type);
|
|
866
|
+
await sendRestMessage("event", {
|
|
867
|
+
type: fullEvent.type,
|
|
868
|
+
orgId: fullEvent.orgId || orgId,
|
|
869
|
+
chatKey: fullEvent.chatKey || currentChatKeyRef.current,
|
|
870
|
+
userId: fullEvent.userId,
|
|
871
|
+
data: fullEvent.data
|
|
872
|
+
});
|
|
849
873
|
break;
|
|
850
874
|
}
|
|
851
875
|
updateMetrics({ messagesSent: metrics.messagesSent + 1 });
|