@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.
@@ -317,7 +317,7 @@ var useWebSocketChatBase = ({
317
317
  if (transportRef.current === "sse") {
318
318
  const sseUrl = getRestApiUrl(`stream?orgId=${orgId}&userId=${userId}&clientType=${clientType}&chatId=${currentChatKeyRef.current || ""}`);
319
319
  logger.debug("Connecting to SSE:", sseUrl);
320
- console.log(`\u23F3 Initiating SSE connection to ${serverBaseUrl}...`);
320
+ console.log(`\u23F3 Initiating SSE connection to ${sseUrl}...`);
321
321
  const eventSource = new EventSource(sseUrl);
322
322
  eventSource.onopen = () => {
323
323
  if (!mountedRef.current) {
@@ -374,6 +374,9 @@ var useWebSocketChatBase = ({
374
374
  };
375
375
  const handleSSEMessage = (event) => {
376
376
  if (!mountedRef.current) return;
377
+ if (!event.data || event.data === "") {
378
+ return;
379
+ }
377
380
  try {
378
381
  const data = JSON.parse(event.data);
379
382
  if (!isChatEvent(data)) {
@@ -430,7 +433,6 @@ var useWebSocketChatBase = ({
430
433
  eventSource.addEventListener("chat_updated", handleSSEMessage);
431
434
  eventSource.addEventListener("load_chat_response", handleSSEMessage);
432
435
  eventSource.addEventListener("new_chat_created", handleSSEMessage);
433
- eventSource.addEventListener("error", handleSSEMessage);
434
436
  eventSource.addEventListener("show_csat_survey", handleSSEMessage);
435
437
  eventSource.addEventListener("csat_response", handleSSEMessage);
436
438
  eventSource.addEventListener("user_suggested_actions", handleSSEMessage);
@@ -775,7 +777,7 @@ var useWebSocketChatBase = ({
775
777
  switch (fullEvent.type) {
776
778
  case "message":
777
779
  await sendRestMessage("send", {
778
- orgId: fullEvent.orgId,
780
+ orgId: fullEvent.orgId || orgId,
779
781
  chatKey: fullEvent.chatKey || currentChatKeyRef.current,
780
782
  userId: fullEvent.userId,
781
783
  message: fullEvent.message
@@ -783,7 +785,7 @@ var useWebSocketChatBase = ({
783
785
  break;
784
786
  case "typing":
785
787
  await sendRestMessage("typing", {
786
- orgId: fullEvent.orgId,
788
+ orgId: fullEvent.orgId || orgId,
787
789
  chatKey: fullEvent.chatKey || currentChatKeyRef.current,
788
790
  userId: fullEvent.userId,
789
791
  typing: true
@@ -791,7 +793,7 @@ var useWebSocketChatBase = ({
791
793
  break;
792
794
  case "stopped_typing":
793
795
  await sendRestMessage("typing", {
794
- orgId: fullEvent.orgId,
796
+ orgId: fullEvent.orgId || orgId,
795
797
  chatKey: fullEvent.chatKey || currentChatKeyRef.current,
796
798
  userId: fullEvent.userId,
797
799
  typing: false
@@ -799,7 +801,7 @@ var useWebSocketChatBase = ({
799
801
  break;
800
802
  case "load_chat":
801
803
  const loadResponse = await sendRestMessage("load", {
802
- orgId: fullEvent.orgId,
804
+ orgId: fullEvent.orgId || orgId,
803
805
  chatKey: fullEvent.chatKey,
804
806
  userId: fullEvent.userId
805
807
  });
@@ -821,7 +823,7 @@ var useWebSocketChatBase = ({
821
823
  break;
822
824
  case "new_chat":
823
825
  const createResponse = await sendRestMessage("create", {
824
- orgId: fullEvent.orgId,
826
+ orgId: fullEvent.orgId || orgId,
825
827
  userId: fullEvent.userId,
826
828
  metadata: fullEvent.data
827
829
  });
@@ -847,7 +849,7 @@ var useWebSocketChatBase = ({
847
849
  break;
848
850
  case "end_chat":
849
851
  await sendRestMessage("end", {
850
- orgId: fullEvent.orgId,
852
+ orgId: fullEvent.orgId || orgId,
851
853
  chatKey: fullEvent.chatKey || currentChatKeyRef.current,
852
854
  userId: fullEvent.userId,
853
855
  data: fullEvent.data
@@ -855,20 +857,42 @@ var useWebSocketChatBase = ({
855
857
  break;
856
858
  case "human_agent_join":
857
859
  await sendRestMessage("agent-join", {
858
- orgId: fullEvent.orgId,
860
+ orgId: fullEvent.orgId || orgId,
859
861
  chatKey: fullEvent.chatKey || currentChatKeyRef.current,
860
862
  user: fullEvent.data?.user
861
863
  });
862
864
  break;
863
865
  case "human_agent_leave":
864
866
  await sendRestMessage("agent-leave", {
865
- orgId: fullEvent.orgId,
867
+ orgId: fullEvent.orgId || orgId,
866
868
  chatKey: fullEvent.chatKey || currentChatKeyRef.current,
867
869
  user: fullEvent.data?.user
868
870
  });
869
871
  break;
872
+ // Event types that use the generic /event endpoint
873
+ case "load_agent_context":
874
+ case "skill_activate":
875
+ case "skill_deactivate":
876
+ case "sync_metadata":
877
+ case "plan_approved":
878
+ case "plan_rejected":
879
+ await sendRestMessage("event", {
880
+ type: fullEvent.type,
881
+ orgId: fullEvent.orgId || orgId,
882
+ chatKey: fullEvent.chatKey || currentChatKeyRef.current,
883
+ userId: fullEvent.userId,
884
+ data: fullEvent.data
885
+ });
886
+ break;
870
887
  default:
871
- logger.warn("Unrecognized event type for SSE REST:", fullEvent.type);
888
+ logger.warn("Sending unrecognized event type via generic endpoint:", fullEvent.type);
889
+ await sendRestMessage("event", {
890
+ type: fullEvent.type,
891
+ orgId: fullEvent.orgId || orgId,
892
+ chatKey: fullEvent.chatKey || currentChatKeyRef.current,
893
+ userId: fullEvent.userId,
894
+ data: fullEvent.data
895
+ });
872
896
  break;
873
897
  }
874
898
  updateMetrics({ messagesSent: metrics.messagesSent + 1 });