@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.
- package/dist/hooks/index.d.mts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +73 -6
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +73 -6
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +85 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -6
- package/dist/index.mjs.map +1 -1
- package/dist/models/index.d.mts +89 -4
- package/dist/models/index.d.ts +89 -4
- package/dist/models/index.js +12 -0
- package/dist/models/index.js.map +1 -1
- package/dist/models/index.mjs +8 -0
- package/dist/models/index.mjs.map +1 -1
- package/dist/transport/index.js +70 -4
- package/dist/transport/index.js.map +1 -1
- package/dist/transport/index.mjs +70 -4
- package/dist/transport/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -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
|
|
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
|
|
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,
|
|
@@ -1434,6 +1501,7 @@ var ChatEventTypeStoppedTyping = "stopped_typing";
|
|
|
1434
1501
|
var ChatEventTypeRead = "read";
|
|
1435
1502
|
var ChatEventTypeDelivered = "delivered";
|
|
1436
1503
|
var ChatEventTypeReconnected = "reconnected";
|
|
1504
|
+
var ChatEventTypeTransportReconnected = "transport_reconnected";
|
|
1437
1505
|
var ChatEventTypeError = "error";
|
|
1438
1506
|
var ChatEventTypeWaiting = "waiting";
|
|
1439
1507
|
var ChatEventTypeLoadChat = "load_chat";
|
|
@@ -1573,6 +1641,9 @@ var GetActiveChatsSubject = "chat.get_active_chats";
|
|
|
1573
1641
|
var GetUserChatsSubject = "chat.get_user_chats";
|
|
1574
1642
|
var GetChatSubject = "chat.get_chat";
|
|
1575
1643
|
var ChatArchiveSubjectPattern = "chat.archive.%s.server";
|
|
1644
|
+
var ListIdleChatsSubject = "chat.maintenance.list_idle_chats";
|
|
1645
|
+
var CloseAndDeleteChatSubject = "chat.maintenance.close_and_delete_chat";
|
|
1646
|
+
var MarkChatClosedSubject = "chat.maintenance.mark_closed";
|
|
1576
1647
|
var StartAgentSessionSubject = "chat.agent_session.start";
|
|
1577
1648
|
var EndAgentSessionSubject = "chat.agent_session.end";
|
|
1578
1649
|
var UpdateAgentStatusSubject = "chat.agent_session.update_status";
|
|
@@ -1703,6 +1774,7 @@ export {
|
|
|
1703
1774
|
ChatEventTypeSyncMetadataResponse,
|
|
1704
1775
|
ChatEventTypeSyncUserSession,
|
|
1705
1776
|
ChatEventTypeSyncUserSessionResponse,
|
|
1777
|
+
ChatEventTypeTransportReconnected,
|
|
1706
1778
|
ChatEventTypeTyping,
|
|
1707
1779
|
ChatEventTypeUpdateRoom,
|
|
1708
1780
|
ChatEventTypeUserActivity,
|
|
@@ -1741,6 +1813,7 @@ export {
|
|
|
1741
1813
|
ChatTypeGroup,
|
|
1742
1814
|
ChatTypePrivateRoom,
|
|
1743
1815
|
ChatTypePublicRoom,
|
|
1816
|
+
CloseAndDeleteChatSubject,
|
|
1744
1817
|
CompleteChatByAgentSubject,
|
|
1745
1818
|
CreateAgentQueueSubject,
|
|
1746
1819
|
DeleteAgentQueueSubject,
|
|
@@ -1760,6 +1833,8 @@ export {
|
|
|
1760
1833
|
GetUserChatsSubject,
|
|
1761
1834
|
GetWaitingForAgentChatCountSubject,
|
|
1762
1835
|
GetWaitingForAgentChatsSubject,
|
|
1836
|
+
ListIdleChatsSubject,
|
|
1837
|
+
MarkChatClosedSubject,
|
|
1763
1838
|
MessageStatusDelivered,
|
|
1764
1839
|
MessageStatusFailed,
|
|
1765
1840
|
MessageStatusRead,
|