@elqnt/chat 3.0.1 → 3.0.3

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.js CHANGED
@@ -159,6 +159,7 @@ __export(index_exports, {
159
159
  ChatStatusActive: () => ChatStatusActive,
160
160
  ChatStatusArchived: () => ChatStatusArchived,
161
161
  ChatStatusClosed: () => ChatStatusClosed,
162
+ ChatStatusCompleted: () => ChatStatusCompleted,
162
163
  ChatStatusDisconnected: () => ChatStatusDisconnected,
163
164
  ChatTypeCustomerSupport: () => ChatTypeCustomerSupport,
164
165
  ChatTypeDirect: () => ChatTypeDirect,
@@ -171,6 +172,7 @@ __export(index_exports, {
171
172
  EndAgentSessionSubject: () => EndAgentSessionSubject,
172
173
  GetActiveChatCountSubject: () => GetActiveChatCountSubject,
173
174
  GetActiveChatsSubject: () => GetActiveChatsSubject,
175
+ GetAgentContextSubject: () => GetAgentContextSubject,
174
176
  GetAgentQueuesSubject: () => GetAgentQueuesSubject,
175
177
  GetAgentSessionSubject: () => GetAgentSessionSubject,
176
178
  GetChatSubject: () => GetChatSubject,
@@ -204,7 +206,12 @@ __export(index_exports, {
204
206
  UserStatusBusy: () => UserStatusBusy,
205
207
  UserStatusOffline: () => UserStatusOffline,
206
208
  UserStatusOnline: () => UserStatusOnline,
207
- useChat: () => useChat
209
+ useApiAsync: () => import_hooks4.useApiAsync,
210
+ useChat: () => useChat,
211
+ useChatHistory: () => useChatHistory,
212
+ useChatMonitoring: () => useChatMonitoring,
213
+ useHumanAgentSessions: () => useHumanAgentSessions,
214
+ useOptionsRef: () => useOptionsRef
208
215
  });
209
216
  module.exports = __toCommonJS(index_exports);
210
217
 
@@ -580,8 +587,394 @@ function createSSETransport(options = {}) {
580
587
  return transport;
581
588
  }
582
589
 
590
+ // transport/sse-fetch.ts
591
+ function createFetchSSETransport(options = {}) {
592
+ const {
593
+ retryConfig = DEFAULT_RETRY_CONFIG,
594
+ debug = false,
595
+ logger = createLogger(debug),
596
+ customFetch = fetch
597
+ } = options;
598
+ let abortController;
599
+ let config;
600
+ let state = "disconnected";
601
+ let error;
602
+ let retryCount = 0;
603
+ let reconnectTimeout;
604
+ let intentionalDisconnect = false;
605
+ const metrics = {
606
+ latency: 0,
607
+ messagesSent: 0,
608
+ messagesReceived: 0,
609
+ messagesQueued: 0,
610
+ reconnectCount: 0,
611
+ transportType: "sse-fetch"
612
+ };
613
+ const globalHandlers = /* @__PURE__ */ new Set();
614
+ const typeHandlers = /* @__PURE__ */ new Map();
615
+ function emit(event) {
616
+ metrics.messagesReceived++;
617
+ metrics.lastMessageAt = Date.now();
618
+ globalHandlers.forEach((handler) => {
619
+ try {
620
+ handler(event);
621
+ } catch (err) {
622
+ logger.error("Error in message handler:", err);
623
+ }
624
+ });
625
+ const handlers = typeHandlers.get(event.type);
626
+ if (handlers) {
627
+ handlers.forEach((handler) => {
628
+ try {
629
+ handler(event);
630
+ } catch (err) {
631
+ logger.error(`Error in ${event.type} handler:`, err);
632
+ }
633
+ });
634
+ }
635
+ }
636
+ async function sendRest(endpoint, body) {
637
+ if (!config) {
638
+ throw new Error("Transport not connected");
639
+ }
640
+ const url = `${config.baseUrl}/${endpoint}`;
641
+ logger.debug(`POST ${endpoint}`, body);
642
+ const response = await customFetch(url, {
643
+ method: "POST",
644
+ headers: { "Content-Type": "application/json" },
645
+ body: JSON.stringify(body)
646
+ });
647
+ if (!response.ok) {
648
+ const errorText = await response.text();
649
+ throw new Error(`API error: ${response.status} - ${errorText}`);
650
+ }
651
+ const json = await response.json();
652
+ if (json && typeof json === "object" && "data" in json) {
653
+ return json.data;
654
+ }
655
+ return json;
656
+ }
657
+ function parseSSEChunk(chunk) {
658
+ const events = [];
659
+ const lines = chunk.split("\n");
660
+ let eventType = "message";
661
+ let data = "";
662
+ for (const line of lines) {
663
+ if (line.startsWith("event:")) {
664
+ eventType = line.slice(6).trim();
665
+ } else if (line.startsWith("data:")) {
666
+ data = line.slice(5).trim();
667
+ } else if (line === "" && data) {
668
+ try {
669
+ const parsed = JSON.parse(data);
670
+ events.push(parsed);
671
+ } catch {
672
+ logger.warn("Failed to parse SSE data:", data);
673
+ }
674
+ eventType = "message";
675
+ data = "";
676
+ }
677
+ }
678
+ return events;
679
+ }
680
+ async function startStream(cfg) {
681
+ const url = `${cfg.baseUrl}/stream?orgId=${cfg.orgId}&userId=${cfg.userId}&clientType=${cfg.clientType}${cfg.chatKey ? `&chatId=${cfg.chatKey}` : ""}`;
682
+ logger.debug("Connecting to:", url);
683
+ abortController = new AbortController();
684
+ const response = await customFetch(url, {
685
+ method: "GET",
686
+ headers: {
687
+ Accept: "text/event-stream",
688
+ "Cache-Control": "no-cache"
689
+ },
690
+ signal: abortController.signal
691
+ });
692
+ if (!response.ok) {
693
+ throw new Error(`Stream connection failed: ${response.status}`);
694
+ }
695
+ if (!response.body) {
696
+ throw new Error("Response body is null - ReadableStream not supported");
697
+ }
698
+ const reader = response.body.getReader();
699
+ const decoder = new TextDecoder();
700
+ let buffer = "";
701
+ const readStream = async () => {
702
+ try {
703
+ while (true) {
704
+ const { done, value } = await reader.read();
705
+ if (done) {
706
+ logger.info("Stream ended");
707
+ break;
708
+ }
709
+ buffer += decoder.decode(value, { stream: true });
710
+ const lastNewline = buffer.lastIndexOf("\n\n");
711
+ if (lastNewline !== -1) {
712
+ const complete = buffer.slice(0, lastNewline + 2);
713
+ buffer = buffer.slice(lastNewline + 2);
714
+ const events = parseSSEChunk(complete);
715
+ events.forEach(emit);
716
+ }
717
+ }
718
+ } catch (err) {
719
+ if (err.name === "AbortError") {
720
+ logger.debug("Stream aborted");
721
+ return;
722
+ }
723
+ logger.error("Stream error:", err);
724
+ throw err;
725
+ }
726
+ if (!intentionalDisconnect) {
727
+ state = "disconnected";
728
+ scheduleReconnect();
729
+ }
730
+ };
731
+ readStream().catch((err) => {
732
+ if (!intentionalDisconnect) {
733
+ error = {
734
+ code: "CONNECTION_FAILED",
735
+ message: err.message,
736
+ retryable: true,
737
+ timestamp: Date.now(),
738
+ originalError: err
739
+ };
740
+ metrics.lastError = error;
741
+ state = "disconnected";
742
+ scheduleReconnect();
743
+ }
744
+ });
745
+ }
746
+ function scheduleReconnect() {
747
+ if (intentionalDisconnect || !config) return;
748
+ const maxRetries = retryConfig.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries;
749
+ if (retryCount >= maxRetries) {
750
+ logger.error(`Max retries (${maxRetries}) exceeded`);
751
+ error = {
752
+ code: "CONNECTION_FAILED",
753
+ message: `Max retries (${maxRetries}) exceeded`,
754
+ retryable: false,
755
+ timestamp: Date.now()
756
+ };
757
+ return;
758
+ }
759
+ const interval = calculateRetryInterval(retryCount, retryConfig);
760
+ retryCount++;
761
+ metrics.reconnectCount++;
762
+ logger.info(`Reconnecting in ${interval}ms (attempt ${retryCount})`);
763
+ state = "reconnecting";
764
+ reconnectTimeout = setTimeout(() => {
765
+ if (config) {
766
+ transport.connect(config).catch((err) => {
767
+ logger.error("Reconnect failed:", err);
768
+ });
769
+ }
770
+ }, interval);
771
+ }
772
+ const transport = {
773
+ async connect(cfg) {
774
+ config = cfg;
775
+ intentionalDisconnect = false;
776
+ if (abortController) {
777
+ abortController.abort();
778
+ abortController = void 0;
779
+ }
780
+ if (reconnectTimeout) {
781
+ clearTimeout(reconnectTimeout);
782
+ reconnectTimeout = void 0;
783
+ }
784
+ state = retryCount > 0 ? "reconnecting" : "connecting";
785
+ const connectionStart = Date.now();
786
+ try {
787
+ await startStream(cfg);
788
+ const connectionTime = Date.now() - connectionStart;
789
+ logger.info(`Connected in ${connectionTime}ms`);
790
+ state = "connected";
791
+ error = void 0;
792
+ retryCount = 0;
793
+ metrics.connectedAt = Date.now();
794
+ metrics.latency = connectionTime;
795
+ } catch (err) {
796
+ const connectError = {
797
+ code: "CONNECTION_FAILED",
798
+ message: err.message,
799
+ retryable: true,
800
+ timestamp: Date.now(),
801
+ originalError: err
802
+ };
803
+ error = connectError;
804
+ metrics.lastError = connectError;
805
+ state = "disconnected";
806
+ if (!intentionalDisconnect) {
807
+ scheduleReconnect();
808
+ }
809
+ throw connectError;
810
+ }
811
+ },
812
+ disconnect(intentional = true) {
813
+ logger.info("Disconnecting", { intentional });
814
+ intentionalDisconnect = intentional;
815
+ if (reconnectTimeout) {
816
+ clearTimeout(reconnectTimeout);
817
+ reconnectTimeout = void 0;
818
+ }
819
+ if (abortController) {
820
+ abortController.abort();
821
+ abortController = void 0;
822
+ }
823
+ state = "disconnected";
824
+ retryCount = 0;
825
+ },
826
+ async send(event) {
827
+ if (!config) {
828
+ throw new Error("Transport not connected");
829
+ }
830
+ switch (event.type) {
831
+ case "message":
832
+ await sendRest("send", {
833
+ orgId: event.orgId,
834
+ chatKey: event.chatKey,
835
+ userId: event.userId,
836
+ message: event.message
837
+ });
838
+ break;
839
+ case "typing":
840
+ await sendRest("typing", {
841
+ orgId: event.orgId,
842
+ chatKey: event.chatKey,
843
+ userId: event.userId,
844
+ typing: true
845
+ });
846
+ break;
847
+ case "stopped_typing":
848
+ await sendRest("typing", {
849
+ orgId: event.orgId,
850
+ chatKey: event.chatKey,
851
+ userId: event.userId,
852
+ typing: false
853
+ });
854
+ break;
855
+ case "load_chat":
856
+ await sendRest("load", {
857
+ orgId: event.orgId,
858
+ chatKey: event.chatKey,
859
+ userId: event.userId
860
+ });
861
+ break;
862
+ case "new_chat":
863
+ await sendRest("create", {
864
+ orgId: event.orgId,
865
+ userId: event.userId,
866
+ metadata: event.data
867
+ });
868
+ break;
869
+ case "end_chat":
870
+ await sendRest("end", {
871
+ orgId: event.orgId,
872
+ chatKey: event.chatKey,
873
+ userId: event.userId,
874
+ data: event.data
875
+ });
876
+ break;
877
+ default:
878
+ await sendRest("event", {
879
+ type: event.type,
880
+ orgId: event.orgId,
881
+ chatKey: event.chatKey,
882
+ userId: event.userId,
883
+ data: event.data
884
+ });
885
+ }
886
+ metrics.messagesSent++;
887
+ },
888
+ async sendMessage(message) {
889
+ if (!config) {
890
+ throw new Error("Transport not connected");
891
+ }
892
+ await sendRest("send", {
893
+ orgId: config.orgId,
894
+ chatKey: config.chatKey,
895
+ userId: config.userId,
896
+ message
897
+ });
898
+ metrics.messagesSent++;
899
+ },
900
+ async createChat(options2) {
901
+ if (!config) {
902
+ throw new Error("Transport not connected");
903
+ }
904
+ const response = await sendRest("create", {
905
+ orgId: options2.orgId,
906
+ userId: options2.userId,
907
+ metadata: options2.metadata
908
+ });
909
+ if (!response?.chatKey) {
910
+ throw new Error("Failed to create chat: no chatKey returned");
911
+ }
912
+ return { chatKey: response.chatKey };
913
+ },
914
+ async loadChatData(options2) {
915
+ if (!config) {
916
+ throw new Error("Transport not connected");
917
+ }
918
+ const response = await sendRest("load", {
919
+ orgId: options2.orgId,
920
+ chatKey: options2.chatKey,
921
+ userId: options2.userId
922
+ });
923
+ if (!response?.chat) {
924
+ throw new Error("Failed to load chat: no chat data returned");
925
+ }
926
+ return {
927
+ chat: response.chat,
928
+ agentId: response.agentId
929
+ };
930
+ },
931
+ onMessage(handler) {
932
+ globalHandlers.add(handler);
933
+ return () => globalHandlers.delete(handler);
934
+ },
935
+ on(eventType, handler) {
936
+ if (!typeHandlers.has(eventType)) {
937
+ typeHandlers.set(eventType, /* @__PURE__ */ new Set());
938
+ }
939
+ typeHandlers.get(eventType).add(handler);
940
+ return () => {
941
+ const handlers = typeHandlers.get(eventType);
942
+ if (handlers) {
943
+ handlers.delete(handler);
944
+ if (handlers.size === 0) {
945
+ typeHandlers.delete(eventType);
946
+ }
947
+ }
948
+ };
949
+ },
950
+ getState() {
951
+ return state;
952
+ },
953
+ getMetrics() {
954
+ return { ...metrics };
955
+ },
956
+ getError() {
957
+ return error;
958
+ },
959
+ clearError() {
960
+ error = void 0;
961
+ }
962
+ };
963
+ return transport;
964
+ }
965
+
583
966
  // hooks/use-chat.ts
584
967
  function getDefaultTransport(type, debug) {
968
+ if (type === "sse-fetch") {
969
+ return createFetchSSETransport({ debug });
970
+ }
971
+ if (type === "sse") {
972
+ return createSSETransport({ debug });
973
+ }
974
+ const isReactNative = typeof navigator !== "undefined" && navigator.product === "ReactNative";
975
+ if (isReactNative || typeof EventSource === "undefined") {
976
+ return createFetchSSETransport({ debug });
977
+ }
585
978
  return createSSETransport({ debug });
586
979
  }
587
980
  function useChat(options) {
@@ -692,6 +1085,7 @@ function useChat(options) {
692
1085
  throw err;
693
1086
  }
694
1087
  setConnectionState("connecting");
1088
+ onConnectionChange?.("connecting");
695
1089
  try {
696
1090
  const unsubscribe = transport.onMessage(handleEvent);
697
1091
  await transport.connect({
@@ -710,6 +1104,7 @@ function useChat(options) {
710
1104
  } catch (err) {
711
1105
  const transportError = err;
712
1106
  setConnectionState("disconnected");
1107
+ onConnectionChange?.("disconnected");
713
1108
  setError(transportError);
714
1109
  onErrorRef.current?.(transportError);
715
1110
  throw err;
@@ -739,7 +1134,7 @@ function useChat(options) {
739
1134
  },
740
1135
  [orgId, userId]
741
1136
  );
742
- const loadChat = (0, import_react.useCallback)(
1137
+ const loadChat2 = (0, import_react.useCallback)(
743
1138
  async (key) => {
744
1139
  const transport = transportRef.current;
745
1140
  if (!transport) {
@@ -792,7 +1187,7 @@ function useChat(options) {
792
1187
  },
793
1188
  [orgId, chatKey, userId]
794
1189
  );
795
- const endChat = (0, import_react.useCallback)(
1190
+ const endChat2 = (0, import_react.useCallback)(
796
1191
  async (reason) => {
797
1192
  const transport = transportRef.current;
798
1193
  if (!transport) {
@@ -814,7 +1209,7 @@ function useChat(options) {
814
1209
  },
815
1210
  [orgId, chatKey, userId]
816
1211
  );
817
- const sendEvent = (0, import_react.useCallback)(
1212
+ const sendEvent2 = (0, import_react.useCallback)(
818
1213
  async (event) => {
819
1214
  const transport = transportRef.current;
820
1215
  if (!transport) {
@@ -899,10 +1294,10 @@ function useChat(options) {
899
1294
  isConnected,
900
1295
  // Chat operations
901
1296
  startChat,
902
- loadChat,
1297
+ loadChat: loadChat2,
903
1298
  sendMessage,
904
- sendEvent,
905
- endChat,
1299
+ sendEvent: sendEvent2,
1300
+ endChat: endChat2,
906
1301
  // Typing
907
1302
  startTyping,
908
1303
  stopTyping,
@@ -918,12 +1313,226 @@ function useChat(options) {
918
1313
  };
919
1314
  }
920
1315
 
1316
+ // hooks/use-chat-history.ts
1317
+ var import_react3 = require("react");
1318
+
1319
+ // api/index.ts
1320
+ var import_browser = require("@elqnt/api-client/browser");
1321
+ async function getChatHistoryApi(options) {
1322
+ return (0, import_browser.browserApiRequest)("/api/v1/chats", {
1323
+ method: "POST",
1324
+ body: {
1325
+ limit: options.limit || 15,
1326
+ offset: options.offset || 0,
1327
+ ...options.skipCache ? { skipCache: true } : {}
1328
+ },
1329
+ ...options
1330
+ });
1331
+ }
1332
+ async function getChatApi(chatKey, options) {
1333
+ return (0, import_browser.browserApiRequest)(`/api/v1/chats/${chatKey}`, {
1334
+ method: "GET",
1335
+ ...options
1336
+ });
1337
+ }
1338
+ async function updateChatApi(chatKey, updates, options) {
1339
+ return (0, import_browser.browserApiRequest)(`/api/v1/chats/${chatKey}`, {
1340
+ method: "PATCH",
1341
+ body: updates,
1342
+ ...options
1343
+ });
1344
+ }
1345
+ async function deleteChatApi(chatKey, options) {
1346
+ return (0, import_browser.browserApiRequest)(`/api/v1/chats/${chatKey}`, {
1347
+ method: "DELETE",
1348
+ ...options
1349
+ });
1350
+ }
1351
+ async function getActiveChatsCountApi(options) {
1352
+ return (0, import_browser.browserApiRequest)("/api/v1/chats/active/count", {
1353
+ method: "GET",
1354
+ ...options
1355
+ });
1356
+ }
1357
+ async function getActiveChatsApi(options) {
1358
+ const params = new URLSearchParams();
1359
+ if (options.pastHours) params.set("pastHours", String(options.pastHours));
1360
+ const queryString = params.toString();
1361
+ return (0, import_browser.browserApiRequest)(`/api/v1/chats/active${queryString ? `?${queryString}` : ""}`, {
1362
+ method: "GET",
1363
+ ...options
1364
+ });
1365
+ }
1366
+ async function getWaitingChatsCountApi(options) {
1367
+ return (0, import_browser.browserApiRequest)("/api/v1/chats/waiting/count", {
1368
+ method: "GET",
1369
+ ...options
1370
+ });
1371
+ }
1372
+ async function getChatsByUserApi(userEmail, options) {
1373
+ return (0, import_browser.browserApiRequest)(`/api/v1/chats/user/${encodeURIComponent(userEmail)}`, {
1374
+ method: "GET",
1375
+ ...options
1376
+ });
1377
+ }
1378
+ async function listQueuesApi(options) {
1379
+ return (0, import_browser.browserApiRequest)("/api/v1/queues", {
1380
+ method: "GET",
1381
+ ...options
1382
+ });
1383
+ }
1384
+ async function getOnlineSessionsApi(options) {
1385
+ return (0, import_browser.browserApiRequest)("/api/v1/agents/sessions/online", {
1386
+ method: "GET",
1387
+ ...options
1388
+ });
1389
+ }
1390
+ async function getAgentSessionApi(agentId, options) {
1391
+ return (0, import_browser.browserApiRequest)(`/api/v1/agents/sessions/${agentId}`, {
1392
+ method: "GET",
1393
+ ...options
1394
+ });
1395
+ }
1396
+
1397
+ // hooks/use-chat-history.ts
1398
+ var import_hooks = require("@elqnt/api-client/hooks");
1399
+
1400
+ // hooks/use-options-ref.ts
1401
+ var import_react2 = require("react");
1402
+ function useOptionsRef(options) {
1403
+ const optionsRef = (0, import_react2.useRef)(options);
1404
+ (0, import_react2.useEffect)(() => {
1405
+ optionsRef.current = options;
1406
+ }, [options]);
1407
+ return optionsRef;
1408
+ }
1409
+
1410
+ // hooks/use-chat-history.ts
1411
+ function useChatHistory(options) {
1412
+ const optionsRef = useOptionsRef(options);
1413
+ const { execute: getChatHistory, loading: listLoading, error: listError } = (0, import_hooks.useApiAsync)(
1414
+ (params) => getChatHistoryApi({ ...optionsRef.current, ...params }),
1415
+ (data) => ({
1416
+ chats: data.chats,
1417
+ total: data.total,
1418
+ hasMore: data.hasMore
1419
+ }),
1420
+ { chats: [], total: 0, hasMore: false }
1421
+ );
1422
+ const { execute: getChat, loading: getLoading, error: getError } = (0, import_hooks.useApiAsync)(
1423
+ (chatKey) => getChatApi(chatKey, optionsRef.current),
1424
+ (data) => data.chat || null,
1425
+ null
1426
+ );
1427
+ const { execute: updateChat, loading: updateLoading, error: updateError } = (0, import_hooks.useApiAsync)(
1428
+ (chatKey, updates) => updateChatApi(chatKey, updates, optionsRef.current),
1429
+ (data) => !!data.chatKey,
1430
+ false
1431
+ );
1432
+ const { execute: deleteChat, loading: deleteLoading, error: deleteError } = (0, import_hooks.useApiAsync)(
1433
+ (chatKey) => deleteChatApi(chatKey, optionsRef.current),
1434
+ (data) => data.success,
1435
+ false
1436
+ );
1437
+ const { execute: getChatsByUser, loading: userChatsLoading, error: userChatsError } = (0, import_hooks.useApiAsync)(
1438
+ (userEmail) => getChatsByUserApi(userEmail, optionsRef.current),
1439
+ (data) => data.chats,
1440
+ []
1441
+ );
1442
+ const loading = listLoading || getLoading || updateLoading || deleteLoading || userChatsLoading;
1443
+ const error = listError || getError || updateError || deleteError || userChatsError;
1444
+ return (0, import_react3.useMemo)(
1445
+ () => ({
1446
+ loading,
1447
+ error,
1448
+ getChatHistory,
1449
+ getChat,
1450
+ updateChat,
1451
+ deleteChat,
1452
+ getChatsByUser
1453
+ }),
1454
+ [loading, error, getChatHistory, getChat, updateChat, deleteChat, getChatsByUser]
1455
+ );
1456
+ }
1457
+
1458
+ // hooks/use-chat-monitoring.ts
1459
+ var import_react4 = require("react");
1460
+ var import_hooks2 = require("@elqnt/api-client/hooks");
1461
+ function useChatMonitoring(options) {
1462
+ const optionsRef = useOptionsRef(options);
1463
+ const { execute: getActiveChats, loading: activeLoading, error: activeError } = (0, import_hooks2.useApiAsync)(
1464
+ (pastHours) => getActiveChatsApi({ ...optionsRef.current, pastHours }),
1465
+ (data) => data.chats,
1466
+ []
1467
+ );
1468
+ const { execute: getActiveChatsCount, loading: activeCountLoading, error: activeCountError } = (0, import_hooks2.useApiAsync)(
1469
+ () => getActiveChatsCountApi(optionsRef.current),
1470
+ (data) => data.count,
1471
+ 0
1472
+ );
1473
+ const { execute: getWaitingChatsCount, loading: waitingCountLoading, error: waitingCountError } = (0, import_hooks2.useApiAsync)(
1474
+ () => getWaitingChatsCountApi(optionsRef.current),
1475
+ (data) => data.count,
1476
+ 0
1477
+ );
1478
+ const { execute: listQueues, loading: queuesLoading, error: queuesError } = (0, import_hooks2.useApiAsync)(
1479
+ () => listQueuesApi(optionsRef.current),
1480
+ (data) => data.queues,
1481
+ []
1482
+ );
1483
+ const loading = activeLoading || activeCountLoading || waitingCountLoading || queuesLoading;
1484
+ const error = activeError || activeCountError || waitingCountError || queuesError;
1485
+ return (0, import_react4.useMemo)(
1486
+ () => ({
1487
+ loading,
1488
+ error,
1489
+ getActiveChats,
1490
+ getActiveChatsCount,
1491
+ getWaitingChatsCount,
1492
+ listQueues
1493
+ }),
1494
+ [loading, error, getActiveChats, getActiveChatsCount, getWaitingChatsCount, listQueues]
1495
+ );
1496
+ }
1497
+
1498
+ // hooks/use-human-agent-sessions.ts
1499
+ var import_react5 = require("react");
1500
+ var import_hooks3 = require("@elqnt/api-client/hooks");
1501
+ function useHumanAgentSessions(options) {
1502
+ const optionsRef = useOptionsRef(options);
1503
+ const { execute: getOnlineSessions, loading: onlineLoading, error: onlineError } = (0, import_hooks3.useApiAsync)(
1504
+ () => getOnlineSessionsApi(optionsRef.current),
1505
+ (data) => data.sessions,
1506
+ []
1507
+ );
1508
+ const { execute: getAgentSession, loading: sessionLoading, error: sessionError } = (0, import_hooks3.useApiAsync)(
1509
+ (agentId) => getAgentSessionApi(agentId, optionsRef.current),
1510
+ (data) => data.session || null,
1511
+ null
1512
+ );
1513
+ const loading = onlineLoading || sessionLoading;
1514
+ const error = onlineError || sessionError;
1515
+ return (0, import_react5.useMemo)(
1516
+ () => ({
1517
+ loading,
1518
+ error,
1519
+ getOnlineSessions,
1520
+ getAgentSession
1521
+ }),
1522
+ [loading, error, getOnlineSessions, getAgentSession]
1523
+ );
1524
+ }
1525
+
1526
+ // hooks/index.ts
1527
+ var import_hooks4 = require("@elqnt/api-client/hooks");
1528
+
921
1529
  // models/chat-models.ts
922
1530
  var ChatStatusActive = "active";
923
1531
  var ChatStatusDisconnected = "disconnected";
924
1532
  var ChatStatusAbandoned = "abandoned";
925
1533
  var ChatStatusClosed = "closed";
926
1534
  var ChatStatusArchived = "archived";
1535
+ var ChatStatusCompleted = "completed";
927
1536
  var ChatTypeCustomerSupport = "customer_support";
928
1537
  var ChatTypePublicRoom = "public_room";
929
1538
  var ChatTypePrivateRoom = "private_room";
@@ -1107,6 +1716,7 @@ var UpdateUserStatusSubject = "chat.user.status.update";
1107
1716
  var GetOnlineUsersSubject = "chat.users.online.get";
1108
1717
  var TriggerAnalyticsScanSubject = "chat.analytics.trigger-scan";
1109
1718
  var SetupOrgSubject = "chat.org.setup";
1719
+ var GetAgentContextSubject = "chat.agent-context.get";
1110
1720
  // Annotate the CommonJS export names for ESM import in node:
1111
1721
  0 && (module.exports = {
1112
1722
  AgentStatusAway,
@@ -1247,6 +1857,7 @@ var SetupOrgSubject = "chat.org.setup";
1247
1857
  ChatStatusActive,
1248
1858
  ChatStatusArchived,
1249
1859
  ChatStatusClosed,
1860
+ ChatStatusCompleted,
1250
1861
  ChatStatusDisconnected,
1251
1862
  ChatTypeCustomerSupport,
1252
1863
  ChatTypeDirect,
@@ -1259,6 +1870,7 @@ var SetupOrgSubject = "chat.org.setup";
1259
1870
  EndAgentSessionSubject,
1260
1871
  GetActiveChatCountSubject,
1261
1872
  GetActiveChatsSubject,
1873
+ GetAgentContextSubject,
1262
1874
  GetAgentQueuesSubject,
1263
1875
  GetAgentSessionSubject,
1264
1876
  GetChatSubject,
@@ -1292,6 +1904,11 @@ var SetupOrgSubject = "chat.org.setup";
1292
1904
  UserStatusBusy,
1293
1905
  UserStatusOffline,
1294
1906
  UserStatusOnline,
1295
- useChat
1907
+ useApiAsync,
1908
+ useChat,
1909
+ useChatHistory,
1910
+ useChatMonitoring,
1911
+ useHumanAgentSessions,
1912
+ useOptionsRef
1296
1913
  });
1297
1914
  //# sourceMappingURL=index.js.map