@elqnt/chat 3.0.3 → 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 = () => {
@@ -242,7 +291,8 @@ function createSSETransport(options = {}) {
242
291
  orgId: event.orgId,
243
292
  chatKey: event.chatKey,
244
293
  userId: event.userId,
245
- message: event.message
294
+ message: event.message,
295
+ ...event.data ? { data: event.data } : {}
246
296
  });
247
297
  break;
248
298
  case "typing":
@@ -463,7 +513,13 @@ function createFetchSSETransport(options = {}) {
463
513
  return events;
464
514
  }
465
515
  async function startStream(cfg) {
466
- 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()}`;
467
523
  logger.debug("Connecting to:", url);
468
524
  abortController = new AbortController();
469
525
  const response = await customFetch(url, {
@@ -569,6 +625,7 @@ function createFetchSSETransport(options = {}) {
569
625
  state = retryCount > 0 ? "reconnecting" : "connecting";
570
626
  const connectionStart = Date.now();
571
627
  try {
628
+ const wasReconnect = retryCount > 0;
572
629
  await startStream(cfg);
573
630
  const connectionTime = Date.now() - connectionStart;
574
631
  logger.info(`Connected in ${connectionTime}ms`);
@@ -577,6 +634,15 @@ function createFetchSSETransport(options = {}) {
577
634
  retryCount = 0;
578
635
  metrics.connectedAt = Date.now();
579
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
+ }
580
646
  } catch (err) {
581
647
  const connectError = {
582
648
  code: "CONNECTION_FAILED",
@@ -618,7 +684,8 @@ function createFetchSSETransport(options = {}) {
618
684
  orgId: event.orgId,
619
685
  chatKey: event.chatKey,
620
686
  userId: event.userId,
621
- message: event.message
687
+ message: event.message,
688
+ ...event.data ? { data: event.data } : {}
622
689
  });
623
690
  break;
624
691
  case "typing":
@@ -938,7 +1005,7 @@ function useChat(options) {
938
1005
  [orgId, userId]
939
1006
  );
940
1007
  const sendMessage = useCallback(
941
- async (content, attachments) => {
1008
+ async (content, attachments, data) => {
942
1009
  const transport = transportRef.current;
943
1010
  if (!transport) {
944
1011
  throw new Error("Transport not initialized");
@@ -963,7 +1030,8 @@ function useChat(options) {
963
1030
  chatKey,
964
1031
  userId,
965
1032
  timestamp: Date.now(),
966
- message
1033
+ message,
1034
+ ...data ? { data } : {}
967
1035
  });
968
1036
  setMetrics((prev) => ({
969
1037
  ...prev,
@@ -1102,9 +1170,21 @@ function useChat(options) {
1102
1170
  import { useMemo } from "react";
1103
1171
 
1104
1172
  // api/index.ts
1173
+ import { browserApiRequest as browserApiRequest2 } from "@elqnt/api-client/browser";
1174
+
1175
+ // api/memory.ts
1105
1176
  import { browserApiRequest } from "@elqnt/api-client/browser";
1177
+ var patchProfileApi = (patch, o) => browserApiRequest("/api/v1/memory/profile", { method: "PATCH", body: patch, ...o });
1178
+ var replaceProfileApi = (p, o) => browserApiRequest("/api/v1/memory/profile", { method: "PUT", body: p, ...o });
1179
+ var clearProfileApi = (o) => browserApiRequest("/api/v1/memory/profile", { method: "DELETE", ...o });
1180
+ var deleteContactApi = (name, o) => browserApiRequest(`/api/v1/memory/profile/contacts/${encodeURIComponent(name)}`, { method: "DELETE", ...o });
1181
+ var deleteNoteApi = (index, o) => browserApiRequest(`/api/v1/memory/profile/notes/${index}`, { method: "DELETE", ...o });
1182
+ var clearSummaryApi = (chatKey, o) => browserApiRequest(`/api/v1/chats/${chatKey}/summary`, { method: "DELETE", ...o });
1183
+ var regenerateSummaryApi = (chatKey, o) => browserApiRequest(`/api/v1/chats/${chatKey}/summary/regenerate`, { method: "POST", ...o });
1184
+
1185
+ // api/index.ts
1106
1186
  async function getChatHistoryApi(options) {
1107
- return browserApiRequest("/api/v1/chats", {
1187
+ return browserApiRequest2("/api/v1/chats", {
1108
1188
  method: "POST",
1109
1189
  body: {
1110
1190
  limit: options.limit || 15,
@@ -1115,26 +1195,26 @@ async function getChatHistoryApi(options) {
1115
1195
  });
1116
1196
  }
1117
1197
  async function getChatApi(chatKey, options) {
1118
- return browserApiRequest(`/api/v1/chats/${chatKey}`, {
1198
+ return browserApiRequest2(`/api/v1/chats/${chatKey}`, {
1119
1199
  method: "GET",
1120
1200
  ...options
1121
1201
  });
1122
1202
  }
1123
1203
  async function updateChatApi(chatKey, updates, options) {
1124
- return browserApiRequest(`/api/v1/chats/${chatKey}`, {
1204
+ return browserApiRequest2(`/api/v1/chats/${chatKey}`, {
1125
1205
  method: "PATCH",
1126
1206
  body: updates,
1127
1207
  ...options
1128
1208
  });
1129
1209
  }
1130
1210
  async function deleteChatApi(chatKey, options) {
1131
- return browserApiRequest(`/api/v1/chats/${chatKey}`, {
1211
+ return browserApiRequest2(`/api/v1/chats/${chatKey}`, {
1132
1212
  method: "DELETE",
1133
1213
  ...options
1134
1214
  });
1135
1215
  }
1136
1216
  async function getActiveChatsCountApi(options) {
1137
- return browserApiRequest("/api/v1/chats/active/count", {
1217
+ return browserApiRequest2("/api/v1/chats/active/count", {
1138
1218
  method: "GET",
1139
1219
  ...options
1140
1220
  });
@@ -1143,37 +1223,37 @@ async function getActiveChatsApi(options) {
1143
1223
  const params = new URLSearchParams();
1144
1224
  if (options.pastHours) params.set("pastHours", String(options.pastHours));
1145
1225
  const queryString = params.toString();
1146
- return browserApiRequest(`/api/v1/chats/active${queryString ? `?${queryString}` : ""}`, {
1226
+ return browserApiRequest2(`/api/v1/chats/active${queryString ? `?${queryString}` : ""}`, {
1147
1227
  method: "GET",
1148
1228
  ...options
1149
1229
  });
1150
1230
  }
1151
1231
  async function getWaitingChatsCountApi(options) {
1152
- return browserApiRequest("/api/v1/chats/waiting/count", {
1232
+ return browserApiRequest2("/api/v1/chats/waiting/count", {
1153
1233
  method: "GET",
1154
1234
  ...options
1155
1235
  });
1156
1236
  }
1157
1237
  async function getChatsByUserApi(userEmail, options) {
1158
- return browserApiRequest(`/api/v1/chats/user/${encodeURIComponent(userEmail)}`, {
1238
+ return browserApiRequest2(`/api/v1/chats/user/${encodeURIComponent(userEmail)}`, {
1159
1239
  method: "GET",
1160
1240
  ...options
1161
1241
  });
1162
1242
  }
1163
1243
  async function listQueuesApi(options) {
1164
- return browserApiRequest("/api/v1/queues", {
1244
+ return browserApiRequest2("/api/v1/queues", {
1165
1245
  method: "GET",
1166
1246
  ...options
1167
1247
  });
1168
1248
  }
1169
1249
  async function getOnlineSessionsApi(options) {
1170
- return browserApiRequest("/api/v1/agents/sessions/online", {
1250
+ return browserApiRequest2("/api/v1/agents/sessions/online", {
1171
1251
  method: "GET",
1172
1252
  ...options
1173
1253
  });
1174
1254
  }
1175
1255
  async function getAgentSessionApi(agentId, options) {
1176
- return browserApiRequest(`/api/v1/agents/sessions/${agentId}`, {
1256
+ return browserApiRequest2(`/api/v1/agents/sessions/${agentId}`, {
1177
1257
  method: "GET",
1178
1258
  ...options
1179
1259
  });
@@ -1308,6 +1388,85 @@ function useHumanAgentSessions(options) {
1308
1388
  );
1309
1389
  }
1310
1390
 
1391
+ // hooks/use-memory.ts
1392
+ import { useCallback as useCallback2, useRef as useRef3, useState as useState2 } from "react";
1393
+ function useMemory(options, initialProfile = null) {
1394
+ const [profile, setProfile] = useState2(initialProfile);
1395
+ const [loading, setLoading] = useState2(false);
1396
+ const requestCountRef = useRef3(0);
1397
+ const runProfileMutation = useCallback2(
1398
+ async (fn) => {
1399
+ requestCountRef.current += 1;
1400
+ setLoading(true);
1401
+ try {
1402
+ const response = await fn();
1403
+ if (!response.error && response.data) {
1404
+ setProfile(response.data);
1405
+ return response.data;
1406
+ }
1407
+ return null;
1408
+ } catch {
1409
+ return null;
1410
+ } finally {
1411
+ requestCountRef.current -= 1;
1412
+ if (requestCountRef.current === 0) {
1413
+ setLoading(false);
1414
+ }
1415
+ }
1416
+ },
1417
+ []
1418
+ );
1419
+ const optionsRef = useRef3(options);
1420
+ optionsRef.current = options;
1421
+ const patchProfile = useCallback2(
1422
+ (patch) => runProfileMutation(() => patchProfileApi(patch, optionsRef.current)),
1423
+ [runProfileMutation]
1424
+ );
1425
+ const replaceProfile = useCallback2(
1426
+ (p) => runProfileMutation(() => replaceProfileApi(p, optionsRef.current)),
1427
+ [runProfileMutation]
1428
+ );
1429
+ const clearProfile = useCallback2(
1430
+ () => runProfileMutation(() => clearProfileApi(optionsRef.current)),
1431
+ [runProfileMutation]
1432
+ );
1433
+ const deleteContact = useCallback2(
1434
+ (name) => runProfileMutation(() => deleteContactApi(name, optionsRef.current)),
1435
+ [runProfileMutation]
1436
+ );
1437
+ const deleteNote = useCallback2(
1438
+ (index) => runProfileMutation(() => deleteNoteApi(index, optionsRef.current)),
1439
+ [runProfileMutation]
1440
+ );
1441
+ const clearSummary = useCallback2(
1442
+ async (chatKey) => {
1443
+ await clearSummaryApi(chatKey, optionsRef.current);
1444
+ },
1445
+ []
1446
+ );
1447
+ const regenerateSummary = useCallback2(
1448
+ async (chatKey) => {
1449
+ const response = await regenerateSummaryApi(chatKey, optionsRef.current);
1450
+ if (!response.error && response.data) {
1451
+ return response.data;
1452
+ }
1453
+ return null;
1454
+ },
1455
+ []
1456
+ );
1457
+ return {
1458
+ profile,
1459
+ loading,
1460
+ patchProfile,
1461
+ replaceProfile,
1462
+ clearProfile,
1463
+ deleteContact,
1464
+ deleteNote,
1465
+ clearSummary,
1466
+ regenerateSummary
1467
+ };
1468
+ }
1469
+
1311
1470
  // hooks/index.ts
1312
1471
  import { useApiAsync as useApiAsync4 } from "@elqnt/api-client/hooks";
1313
1472
  export {
@@ -1316,6 +1475,7 @@ export {
1316
1475
  useChatHistory,
1317
1476
  useChatMonitoring,
1318
1477
  useHumanAgentSessions,
1478
+ useMemory,
1319
1479
  useOptionsRef
1320
1480
  };
1321
1481
  //# sourceMappingURL=index.mjs.map