@elqnt/chat 3.1.0 → 3.3.0

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.
@@ -112,6 +112,7 @@ function createSSETransport(options = {}) {
112
112
  function setupEventListeners(es) {
113
113
  es.addEventListener("message", handleMessage);
114
114
  const eventTypes = [
115
+ "error",
115
116
  "reconnected",
116
117
  "typing",
117
118
  "stopped_typing",
@@ -121,21 +122,53 @@ function createSSETransport(options = {}) {
121
122
  "human_agent_left",
122
123
  "chat_ended",
123
124
  "chat_updated",
125
+ "chat_removed",
124
126
  "load_chat_response",
125
127
  "new_chat_created",
126
128
  "show_csat_survey",
127
129
  "csat_response",
128
130
  "user_suggested_actions",
131
+ "user_suggested_action_selected",
129
132
  "agent_execution_started",
130
133
  "agent_execution_ended",
131
134
  "agent_context_update",
135
+ "load_agent_context_response",
132
136
  "plan_pending_approval",
137
+ "plan_approved",
138
+ "plan_rejected",
133
139
  "step_started",
134
140
  "step_completed",
135
141
  "step_failed",
136
142
  "plan_completed",
137
143
  "skills_changed",
138
- "summary_update"
144
+ "summary_update",
145
+ "message_status_update",
146
+ "delivered",
147
+ "read",
148
+ "sync_metadata_response",
149
+ "sync_user_session_response",
150
+ "client_action",
151
+ "client_action_callback",
152
+ "attachment_processing_started",
153
+ "attachment_processing_progress",
154
+ "attachment_processing_complete",
155
+ "attachment_processing_error",
156
+ "observer_joined",
157
+ "observer_left",
158
+ "block_user",
159
+ "message_edited",
160
+ "message_deleted",
161
+ "message_reaction",
162
+ "user_presence_changed",
163
+ "online_users",
164
+ "get_agents_response",
165
+ "room_created",
166
+ "room_updated",
167
+ "room_deleted",
168
+ "rooms_response",
169
+ "room_user_joined",
170
+ "room_user_left",
171
+ "user_invited"
139
172
  ];
140
173
  eventTypes.forEach((type) => {
141
174
  es.addEventListener(type, handleMessage);
@@ -182,18 +215,34 @@ function createSSETransport(options = {}) {
182
215
  state = retryCount > 0 ? "reconnecting" : "connecting";
183
216
  return new Promise((resolve, reject) => {
184
217
  const connectionStart = Date.now();
185
- const url = `${cfg.baseUrl}/stream?orgId=${cfg.orgId}&userId=${cfg.userId}&clientType=${cfg.clientType}${cfg.chatKey ? `&chatId=${cfg.chatKey}` : ""}`;
218
+ const streamParams = new URLSearchParams({
219
+ orgId: cfg.orgId,
220
+ userId: cfg.userId,
221
+ clientType: cfg.clientType
222
+ });
223
+ if (cfg.chatKey) streamParams.set("chatId", cfg.chatKey);
224
+ const url = `${cfg.baseUrl}/stream?${streamParams.toString()}`;
186
225
  logger.debug("Connecting to:", url);
187
226
  const es = new EventSource(url);
188
227
  es.onopen = () => {
189
228
  const connectionTime = Date.now() - connectionStart;
190
229
  logger.info(`Connected in ${connectionTime}ms`);
230
+ const wasReconnect = retryCount > 0;
191
231
  state = "connected";
192
232
  error = void 0;
193
233
  retryCount = 0;
194
234
  metrics.connectedAt = Date.now();
195
235
  metrics.latency = connectionTime;
196
236
  setupEventListeners(es);
237
+ if (wasReconnect) {
238
+ emit({
239
+ type: "transport_reconnected",
240
+ orgId: cfg.orgId,
241
+ chatKey: cfg.chatKey || "",
242
+ userId: cfg.userId,
243
+ timestamp: Date.now()
244
+ });
245
+ }
197
246
  resolve();
198
247
  };
199
248
  es.onerror = () => {
@@ -464,7 +513,13 @@ function createFetchSSETransport(options = {}) {
464
513
  return events;
465
514
  }
466
515
  async function startStream(cfg) {
467
- const url = `${cfg.baseUrl}/stream?orgId=${cfg.orgId}&userId=${cfg.userId}&clientType=${cfg.clientType}${cfg.chatKey ? `&chatId=${cfg.chatKey}` : ""}`;
516
+ const streamParams = new URLSearchParams({
517
+ orgId: cfg.orgId,
518
+ userId: cfg.userId,
519
+ clientType: cfg.clientType
520
+ });
521
+ if (cfg.chatKey) streamParams.set("chatId", cfg.chatKey);
522
+ const url = `${cfg.baseUrl}/stream?${streamParams.toString()}`;
468
523
  logger.debug("Connecting to:", url);
469
524
  abortController = new AbortController();
470
525
  const response = await customFetch(url, {
@@ -570,6 +625,7 @@ function createFetchSSETransport(options = {}) {
570
625
  state = retryCount > 0 ? "reconnecting" : "connecting";
571
626
  const connectionStart = Date.now();
572
627
  try {
628
+ const wasReconnect = retryCount > 0;
573
629
  await startStream(cfg);
574
630
  const connectionTime = Date.now() - connectionStart;
575
631
  logger.info(`Connected in ${connectionTime}ms`);
@@ -578,6 +634,15 @@ function createFetchSSETransport(options = {}) {
578
634
  retryCount = 0;
579
635
  metrics.connectedAt = Date.now();
580
636
  metrics.latency = connectionTime;
637
+ if (wasReconnect) {
638
+ emit({
639
+ type: "transport_reconnected",
640
+ orgId: cfg.orgId,
641
+ chatKey: cfg.chatKey || "",
642
+ userId: cfg.userId,
643
+ timestamp: Date.now()
644
+ });
645
+ }
581
646
  } catch (err) {
582
647
  const connectError = {
583
648
  code: "CONNECTION_FAILED",
@@ -619,7 +684,8 @@ function createFetchSSETransport(options = {}) {
619
684
  orgId: event.orgId,
620
685
  chatKey: event.chatKey,
621
686
  userId: event.userId,
622
- message: event.message
687
+ message: event.message,
688
+ ...event.data ? { data: event.data } : {}
623
689
  });
624
690
  break;
625
691
  case "typing":
@@ -939,7 +1005,7 @@ function useChat(options) {
939
1005
  [orgId, userId]
940
1006
  );
941
1007
  const sendMessage = useCallback(
942
- async (content, attachments) => {
1008
+ async (content, attachments, data) => {
943
1009
  const transport = transportRef.current;
944
1010
  if (!transport) {
945
1011
  throw new Error("Transport not initialized");
@@ -964,7 +1030,8 @@ function useChat(options) {
964
1030
  chatKey,
965
1031
  userId,
966
1032
  timestamp: Date.now(),
967
- message
1033
+ message,
1034
+ ...data ? { data } : {}
968
1035
  });
969
1036
  setMetrics((prev) => ({
970
1037
  ...prev,