@elqnt/chat 1.0.1 → 1.0.2
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/chunk-3PXNBY7J.js +73 -0
- package/dist/chunk-3PXNBY7J.js.map +1 -0
- package/dist/chunk-AC5J5LX5.mjs +529 -0
- package/dist/chunk-AC5J5LX5.mjs.map +1 -0
- package/dist/chunk-DTFTLFSY.js +637 -0
- package/dist/chunk-DTFTLFSY.js.map +1 -0
- package/dist/chunk-E2FJX52R.js +529 -0
- package/dist/chunk-E2FJX52R.js.map +1 -0
- package/dist/chunk-F6OOS4ZM.mjs +637 -0
- package/dist/chunk-F6OOS4ZM.mjs.map +1 -0
- package/dist/chunk-XVYABY2Z.mjs +73 -0
- package/dist/chunk-XVYABY2Z.mjs.map +1 -0
- package/dist/hooks/use-websocket-chat-admin.d.mts +16 -0
- package/dist/hooks/use-websocket-chat-admin.d.ts +16 -0
- package/dist/hooks/use-websocket-chat-admin.js +9 -0
- package/dist/hooks/use-websocket-chat-admin.js.map +1 -0
- package/dist/hooks/use-websocket-chat-admin.mjs +9 -0
- package/dist/hooks/use-websocket-chat-admin.mjs.map +1 -0
- package/dist/hooks/use-websocket-chat-base.d.mts +4 -0
- package/dist/hooks/use-websocket-chat-base.d.ts +4 -0
- package/dist/hooks/use-websocket-chat-base.js +8 -0
- package/dist/hooks/use-websocket-chat-base.js.map +1 -0
- package/dist/hooks/use-websocket-chat-base.mjs +8 -0
- package/dist/hooks/use-websocket-chat-base.mjs.map +1 -0
- package/dist/hooks/use-websocket-chat-customer.d.mts +23 -0
- package/dist/hooks/use-websocket-chat-customer.d.ts +23 -0
- package/dist/hooks/use-websocket-chat-customer.js +9 -0
- package/dist/hooks/use-websocket-chat-customer.js.map +1 -0
- package/dist/hooks/use-websocket-chat-customer.mjs +9 -0
- package/dist/hooks/use-websocket-chat-customer.mjs.map +1 -0
- package/dist/index.d.mts +10 -1015
- package/dist/index.d.ts +10 -1015
- package/dist/index.js +616 -1710
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +198 -1063
- package/dist/index.mjs.map +1 -1
- package/dist/use-websocket-chat-base-CZDONnTz.d.mts +989 -0
- package/dist/use-websocket-chat-base-CZDONnTz.d.ts +989 -0
- package/package.json +16 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,186 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentStatusAway,
|
|
3
|
+
AgentStatusBusy,
|
|
4
|
+
AgentStatusOffline,
|
|
5
|
+
AgentStatusOnline,
|
|
6
|
+
AssignChatToAgentSubject,
|
|
7
|
+
AttachmentTypeActions,
|
|
8
|
+
AttachmentTypeArticles,
|
|
9
|
+
AttachmentTypeAudio,
|
|
10
|
+
AttachmentTypeBullets,
|
|
11
|
+
AttachmentTypeData,
|
|
12
|
+
AttachmentTypeDocument,
|
|
13
|
+
AttachmentTypeDocumentAnalysis,
|
|
14
|
+
AttachmentTypeDocumentSources,
|
|
15
|
+
AttachmentTypeImage,
|
|
16
|
+
AttachmentTypeKGNodes,
|
|
17
|
+
AttachmentTypeLocation,
|
|
18
|
+
AttachmentTypeRecords,
|
|
19
|
+
AttachmentTypeReferences,
|
|
20
|
+
AttachmentTypeSticker,
|
|
21
|
+
AttachmentTypeSubsections,
|
|
22
|
+
AttachmentTypeVideo,
|
|
23
|
+
ChatArchiveSubjectPattern,
|
|
24
|
+
ChatEventTypeAgentActivityPing,
|
|
25
|
+
ChatEventTypeAgentChatAssigned,
|
|
26
|
+
ChatEventTypeAgentChatCompleted,
|
|
27
|
+
ChatEventTypeAgentContextUpdate,
|
|
28
|
+
ChatEventTypeAgentExecutionEnded,
|
|
29
|
+
ChatEventTypeAgentExecutionStarted,
|
|
30
|
+
ChatEventTypeAgentSessionEnd,
|
|
31
|
+
ChatEventTypeAgentSessionStart,
|
|
32
|
+
ChatEventTypeAgentStatusChange,
|
|
33
|
+
ChatEventTypeBlockUser,
|
|
34
|
+
ChatEventTypeCSATRequest,
|
|
35
|
+
ChatEventTypeCSATResponse,
|
|
36
|
+
ChatEventTypeCSATSurvey,
|
|
37
|
+
ChatEventTypeChatEnded,
|
|
38
|
+
ChatEventTypeChatRemoved,
|
|
39
|
+
ChatEventTypeChatUpdated,
|
|
40
|
+
ChatEventTypeClientAction,
|
|
41
|
+
ChatEventTypeClientActionCallback,
|
|
42
|
+
ChatEventTypeCreateRoom,
|
|
43
|
+
ChatEventTypeDeleteRoom,
|
|
44
|
+
ChatEventTypeDelivered,
|
|
45
|
+
ChatEventTypeEndChat,
|
|
46
|
+
ChatEventTypeError,
|
|
47
|
+
ChatEventTypeGetAgents,
|
|
48
|
+
ChatEventTypeGetAgentsResponse,
|
|
49
|
+
ChatEventTypeGetOnlineUsers,
|
|
50
|
+
ChatEventTypeHumanAgentJoined,
|
|
51
|
+
ChatEventTypeHumanAgentLeft,
|
|
52
|
+
ChatEventTypeInviteUser,
|
|
53
|
+
ChatEventTypeJoinRoom,
|
|
54
|
+
ChatEventTypeLeaveRoom,
|
|
55
|
+
ChatEventTypeListChats,
|
|
56
|
+
ChatEventTypeListRooms,
|
|
57
|
+
ChatEventTypeLoadAgentContext,
|
|
58
|
+
ChatEventTypeLoadAgentContextResponse,
|
|
59
|
+
ChatEventTypeLoadChat,
|
|
60
|
+
ChatEventTypeLoadChatResponse,
|
|
61
|
+
ChatEventTypeMentionUser,
|
|
62
|
+
ChatEventTypeMessage,
|
|
63
|
+
ChatEventTypeMessageDeleted,
|
|
64
|
+
ChatEventTypeMessageDeletedResponse,
|
|
65
|
+
ChatEventTypeMessageEdited,
|
|
66
|
+
ChatEventTypeMessageEditedResponse,
|
|
67
|
+
ChatEventTypeMessageReaction,
|
|
68
|
+
ChatEventTypeMessageReactionResponse,
|
|
69
|
+
ChatEventTypeMessageReply,
|
|
70
|
+
ChatEventTypeMessageStatusUpdate,
|
|
71
|
+
ChatEventTypeNewChat,
|
|
72
|
+
ChatEventTypeNewChatCreated,
|
|
73
|
+
ChatEventTypeObserverJoined,
|
|
74
|
+
ChatEventTypeObserverLeft,
|
|
75
|
+
ChatEventTypeOnlineUsersResponse,
|
|
76
|
+
ChatEventTypePing,
|
|
77
|
+
ChatEventTypePlanApproved,
|
|
78
|
+
ChatEventTypePlanCompleted,
|
|
79
|
+
ChatEventTypePlanPendingApproval,
|
|
80
|
+
ChatEventTypePlanRejected,
|
|
81
|
+
ChatEventTypePong,
|
|
82
|
+
ChatEventTypeRead,
|
|
83
|
+
ChatEventTypeReconnected,
|
|
84
|
+
ChatEventTypeRoomCreated,
|
|
85
|
+
ChatEventTypeRoomDeleted,
|
|
86
|
+
ChatEventTypeRoomUpdated,
|
|
87
|
+
ChatEventTypeRoomUserJoined,
|
|
88
|
+
ChatEventTypeRoomUserLeft,
|
|
89
|
+
ChatEventTypeRoomsResponse,
|
|
90
|
+
ChatEventTypeStepCompleted,
|
|
91
|
+
ChatEventTypeStepFailed,
|
|
92
|
+
ChatEventTypeStepStarted,
|
|
93
|
+
ChatEventTypeStoppedTyping,
|
|
94
|
+
ChatEventTypeSummaryUpdate,
|
|
95
|
+
ChatEventTypeSyncMetadata,
|
|
96
|
+
ChatEventTypeSyncMetadataResponse,
|
|
97
|
+
ChatEventTypeSyncUserSession,
|
|
98
|
+
ChatEventTypeSyncUserSessionResponse,
|
|
99
|
+
ChatEventTypeTyping,
|
|
100
|
+
ChatEventTypeUpdateRoom,
|
|
101
|
+
ChatEventTypeUserActivity,
|
|
102
|
+
ChatEventTypeUserActivityUpdate,
|
|
103
|
+
ChatEventTypeUserInvited,
|
|
104
|
+
ChatEventTypeUserJoined,
|
|
105
|
+
ChatEventTypeUserLeft,
|
|
106
|
+
ChatEventTypeUserPresenceChanged,
|
|
107
|
+
ChatEventTypeUserPresenceEnd,
|
|
108
|
+
ChatEventTypeUserPresenceStart,
|
|
109
|
+
ChatEventTypeUserRemoved,
|
|
110
|
+
ChatEventTypeUserStatusChange,
|
|
111
|
+
ChatEventTypeUserSuggestedActionSelected,
|
|
112
|
+
ChatEventTypeUserSuggestedActions,
|
|
113
|
+
ChatEventTypeWaiting,
|
|
114
|
+
ChatEventTypeWaitingForAgent,
|
|
115
|
+
ChatRoleAI,
|
|
116
|
+
ChatRoleDataQuery,
|
|
117
|
+
ChatRoleEvent,
|
|
118
|
+
ChatRoleHumanAgent,
|
|
119
|
+
ChatRoleObserver,
|
|
120
|
+
ChatRoleSystem,
|
|
121
|
+
ChatRoleTool,
|
|
122
|
+
ChatRoleUser,
|
|
123
|
+
ChatSessionStatusActive,
|
|
124
|
+
ChatSessionStatusExpired,
|
|
125
|
+
ChatSessionStatusIdle,
|
|
126
|
+
ChatStatusAbandoned,
|
|
127
|
+
ChatStatusActive,
|
|
128
|
+
ChatStatusArchived,
|
|
129
|
+
ChatStatusClosed,
|
|
130
|
+
ChatStatusDisconnected,
|
|
131
|
+
ChatTypeCustomerSupport,
|
|
132
|
+
ChatTypeDirect,
|
|
133
|
+
ChatTypeGroup,
|
|
134
|
+
ChatTypePrivateRoom,
|
|
135
|
+
ChatTypePublicRoom,
|
|
136
|
+
CompleteChatByAgentSubject,
|
|
137
|
+
CreateAgentQueueSubject,
|
|
138
|
+
DeleteAgentQueueSubject,
|
|
139
|
+
EndAgentSessionSubject,
|
|
140
|
+
GetActiveChatCountSubject,
|
|
141
|
+
GetActiveChatsSubject,
|
|
142
|
+
GetAgentQueuesSubject,
|
|
143
|
+
GetAgentSessionSubject,
|
|
144
|
+
GetChatSubject,
|
|
145
|
+
GetDailyChatCountSubject,
|
|
146
|
+
GetOnlineAgentCountSubject,
|
|
147
|
+
GetOnlineAgentsSubject,
|
|
148
|
+
GetOnlineUsersSubject,
|
|
149
|
+
GetQueueChatCountSubject,
|
|
150
|
+
GetQueueChatsSubject,
|
|
151
|
+
GetUserChatsSubject,
|
|
152
|
+
GetWaitingForAgentChatCountSubject,
|
|
153
|
+
GetWaitingForAgentChatsSubject,
|
|
154
|
+
MessageStatusDelivered,
|
|
155
|
+
MessageStatusFailed,
|
|
156
|
+
MessageStatusRead,
|
|
157
|
+
MessageStatusSending,
|
|
158
|
+
MessageStatusSent,
|
|
159
|
+
QueueTypeComplexity,
|
|
160
|
+
QueueTypeDepartment,
|
|
161
|
+
QueueTypePriority,
|
|
162
|
+
QueueTypeSkill,
|
|
163
|
+
QueueTypes,
|
|
164
|
+
SetupOrgSubject,
|
|
165
|
+
StartAgentSessionSubject,
|
|
166
|
+
TriggerAnalyticsScanSubject,
|
|
167
|
+
UpdateAgentLastActivitySubject,
|
|
168
|
+
UpdateAgentQueueSubject,
|
|
169
|
+
UpdateAgentStatusSubject,
|
|
170
|
+
UpdateUserStatusSubject,
|
|
171
|
+
UserStatusAway,
|
|
172
|
+
UserStatusBusy,
|
|
173
|
+
UserStatusOffline,
|
|
174
|
+
UserStatusOnline,
|
|
175
|
+
useWebSocketChatAdmin
|
|
176
|
+
} from "./chunk-AC5J5LX5.mjs";
|
|
177
|
+
import {
|
|
178
|
+
useWebSocketChatCustomer
|
|
179
|
+
} from "./chunk-XVYABY2Z.mjs";
|
|
180
|
+
import {
|
|
181
|
+
useWebSocketChatBase
|
|
182
|
+
} from "./chunk-F6OOS4ZM.mjs";
|
|
183
|
+
|
|
1
184
|
// components/admin/admin-chat-input.tsx
|
|
2
185
|
import { useUserContext } from "@elqnt/auth";
|
|
3
186
|
import KSUID from "ksuid";
|
|
@@ -200,1058 +383,10 @@ var __iconNode14 = [
|
|
|
200
383
|
var User = createLucideIcon("User", __iconNode14);
|
|
201
384
|
|
|
202
385
|
// components/admin/admin-chat-input.tsx
|
|
203
|
-
import { useRef
|
|
386
|
+
import { useRef, useState } from "react";
|
|
204
387
|
|
|
205
388
|
// context/websocket-chat-admin-context.tsx
|
|
206
389
|
import { createContext, useContext } from "react";
|
|
207
|
-
|
|
208
|
-
// hooks/use-websocket-chat-admin.ts
|
|
209
|
-
import { useCallback as useCallback2, useState as useState2 } from "react";
|
|
210
|
-
|
|
211
|
-
// models/chat-models.ts
|
|
212
|
-
var ChatStatusActive = "active";
|
|
213
|
-
var ChatStatusDisconnected = "disconnected";
|
|
214
|
-
var ChatStatusAbandoned = "abandoned";
|
|
215
|
-
var ChatStatusClosed = "closed";
|
|
216
|
-
var ChatStatusArchived = "archived";
|
|
217
|
-
var ChatTypeCustomerSupport = "customer_support";
|
|
218
|
-
var ChatTypePublicRoom = "public_room";
|
|
219
|
-
var ChatTypePrivateRoom = "private_room";
|
|
220
|
-
var ChatTypeDirect = "direct";
|
|
221
|
-
var ChatTypeGroup = "group";
|
|
222
|
-
var ChatRoleUser = "user";
|
|
223
|
-
var ChatRoleAI = "ai";
|
|
224
|
-
var ChatRoleEvent = "event";
|
|
225
|
-
var ChatRoleHumanAgent = "humanAgent";
|
|
226
|
-
var ChatRoleObserver = "observer";
|
|
227
|
-
var ChatRoleDataQuery = "dataQuery";
|
|
228
|
-
var ChatRoleSystem = "system";
|
|
229
|
-
var ChatRoleTool = "tool";
|
|
230
|
-
var AgentStatusOnline = "online";
|
|
231
|
-
var AgentStatusAway = "away";
|
|
232
|
-
var AgentStatusBusy = "busy";
|
|
233
|
-
var AgentStatusOffline = "offline";
|
|
234
|
-
var ChatEventTypeUserJoined = "user_joined";
|
|
235
|
-
var ChatEventTypeUserLeft = "user_left";
|
|
236
|
-
var ChatEventTypeTyping = "typing";
|
|
237
|
-
var ChatEventTypeStoppedTyping = "stopped_typing";
|
|
238
|
-
var ChatEventTypeRead = "read";
|
|
239
|
-
var ChatEventTypeDelivered = "delivered";
|
|
240
|
-
var ChatEventTypeReconnected = "reconnected";
|
|
241
|
-
var ChatEventTypeError = "error";
|
|
242
|
-
var ChatEventTypeWaiting = "waiting";
|
|
243
|
-
var ChatEventTypeLoadChat = "load_chat";
|
|
244
|
-
var ChatEventTypeLoadChatResponse = "load_chat_response";
|
|
245
|
-
var ChatEventTypeMessage = "message";
|
|
246
|
-
var ChatEventTypeWaitingForAgent = "waiting_for_agent";
|
|
247
|
-
var ChatEventTypeMessageStatusUpdate = "message_status_update";
|
|
248
|
-
var ChatEventTypeHumanAgentJoined = "human_agent_joined";
|
|
249
|
-
var ChatEventTypeHumanAgentLeft = "human_agent_left";
|
|
250
|
-
var ChatEventTypeObserverJoined = "observer_joined";
|
|
251
|
-
var ChatEventTypeObserverLeft = "observer_left";
|
|
252
|
-
var ChatEventTypeListChats = "list_chats";
|
|
253
|
-
var ChatEventTypeChatUpdated = "chat_updated";
|
|
254
|
-
var ChatEventTypeChatRemoved = "chat_removed";
|
|
255
|
-
var ChatEventTypeSyncMetadata = "sync_metadata";
|
|
256
|
-
var ChatEventTypeSyncMetadataResponse = "sync_metadata_response";
|
|
257
|
-
var ChatEventTypeSyncUserSession = "sync_user_session";
|
|
258
|
-
var ChatEventTypeSyncUserSessionResponse = "sync_user_session_response";
|
|
259
|
-
var ChatEventTypeClientAction = "client_action";
|
|
260
|
-
var ChatEventTypeClientActionCallback = "client_action_callback";
|
|
261
|
-
var ChatEventTypeBlockUser = "block_user";
|
|
262
|
-
var ChatEventTypeCreateRoom = "create_room";
|
|
263
|
-
var ChatEventTypeRoomCreated = "room_created";
|
|
264
|
-
var ChatEventTypeJoinRoom = "join_room";
|
|
265
|
-
var ChatEventTypeLeaveRoom = "leave_room";
|
|
266
|
-
var ChatEventTypeDeleteRoom = "delete_room";
|
|
267
|
-
var ChatEventTypeRoomDeleted = "room_deleted";
|
|
268
|
-
var ChatEventTypeUpdateRoom = "update_room";
|
|
269
|
-
var ChatEventTypeRoomUpdated = "room_updated";
|
|
270
|
-
var ChatEventTypeInviteUser = "invite_user";
|
|
271
|
-
var ChatEventTypeUserInvited = "user_invited";
|
|
272
|
-
var ChatEventTypeRoomUserJoined = "room_user_joined";
|
|
273
|
-
var ChatEventTypeRoomUserLeft = "room_user_left";
|
|
274
|
-
var ChatEventTypeUserRemoved = "user_removed";
|
|
275
|
-
var ChatEventTypeListRooms = "list_rooms";
|
|
276
|
-
var ChatEventTypeRoomsResponse = "rooms_response";
|
|
277
|
-
var ChatEventTypeMessageEdited = "message_edited";
|
|
278
|
-
var ChatEventTypeMessageDeleted = "message_deleted";
|
|
279
|
-
var ChatEventTypeMessageReaction = "message_reaction";
|
|
280
|
-
var ChatEventTypeMessageReply = "message_reply";
|
|
281
|
-
var ChatEventTypeMentionUser = "mention_user";
|
|
282
|
-
var ChatEventTypeMessageEditedResponse = "message_edited_response";
|
|
283
|
-
var ChatEventTypeMessageDeletedResponse = "message_deleted_response";
|
|
284
|
-
var ChatEventTypeMessageReactionResponse = "message_reaction_response";
|
|
285
|
-
var ChatEventTypeUserPresenceStart = "user_presence_start";
|
|
286
|
-
var ChatEventTypeUserPresenceEnd = "user_presence_end";
|
|
287
|
-
var ChatEventTypeUserStatusChange = "user_status_change";
|
|
288
|
-
var ChatEventTypeUserActivity = "user_activity";
|
|
289
|
-
var ChatEventTypeUserPresenceChanged = "user_presence_changed";
|
|
290
|
-
var ChatEventTypeUserActivityUpdate = "user_activity_update";
|
|
291
|
-
var ChatEventTypeGetOnlineUsers = "get_online_users";
|
|
292
|
-
var ChatEventTypeOnlineUsersResponse = "online_users";
|
|
293
|
-
var ChatEventTypeEndChat = "end_chat";
|
|
294
|
-
var ChatEventTypeChatEnded = "chat_ended";
|
|
295
|
-
var ChatEventTypeAgentSessionStart = "agent_session_start";
|
|
296
|
-
var ChatEventTypeAgentSessionEnd = "agent_session_end";
|
|
297
|
-
var ChatEventTypeAgentStatusChange = "agent_status_change";
|
|
298
|
-
var ChatEventTypeAgentActivityPing = "agent_activity_ping";
|
|
299
|
-
var ChatEventTypeAgentChatAssigned = "agent_chat_assigned";
|
|
300
|
-
var ChatEventTypeAgentChatCompleted = "agent_chat_completed";
|
|
301
|
-
var ChatEventTypeGetAgents = "get_agents";
|
|
302
|
-
var ChatEventTypeGetAgentsResponse = "get_agents_response";
|
|
303
|
-
var ChatEventTypeCSATRequest = "csat_request";
|
|
304
|
-
var ChatEventTypeCSATSurvey = "show_csat_survey";
|
|
305
|
-
var ChatEventTypeCSATResponse = "csat_response";
|
|
306
|
-
var ChatEventTypeUserSuggestedActions = "user_suggested_actions";
|
|
307
|
-
var ChatEventTypeUserSuggestedActionSelected = "user_suggested_action_selected";
|
|
308
|
-
var ChatEventTypeSummaryUpdate = "summary_update";
|
|
309
|
-
var ChatEventTypeAgentContextUpdate = "agent_context_update";
|
|
310
|
-
var ChatEventTypeAgentExecutionStarted = "agent_execution_started";
|
|
311
|
-
var ChatEventTypeAgentExecutionEnded = "agent_execution_ended";
|
|
312
|
-
var ChatEventTypeLoadAgentContext = "load_agent_context";
|
|
313
|
-
var ChatEventTypeLoadAgentContextResponse = "load_agent_context_response";
|
|
314
|
-
var ChatEventTypePlanPendingApproval = "plan_pending_approval";
|
|
315
|
-
var ChatEventTypePlanApproved = "plan_approved";
|
|
316
|
-
var ChatEventTypePlanRejected = "plan_rejected";
|
|
317
|
-
var ChatEventTypePlanCompleted = "plan_completed";
|
|
318
|
-
var ChatEventTypeStepStarted = "step_started";
|
|
319
|
-
var ChatEventTypeStepCompleted = "step_completed";
|
|
320
|
-
var ChatEventTypeStepFailed = "step_failed";
|
|
321
|
-
var ChatEventTypeNewChat = "new_chat";
|
|
322
|
-
var ChatEventTypeNewChatCreated = "new_chat_created";
|
|
323
|
-
var ChatEventTypePing = "ping";
|
|
324
|
-
var ChatEventTypePong = "pong";
|
|
325
|
-
var MessageStatusSending = "sending";
|
|
326
|
-
var MessageStatusSent = "sent";
|
|
327
|
-
var MessageStatusDelivered = "delivered";
|
|
328
|
-
var MessageStatusRead = "read";
|
|
329
|
-
var MessageStatusFailed = "failed";
|
|
330
|
-
var AttachmentTypeDocument = "document";
|
|
331
|
-
var AttachmentTypeDocumentAnalysis = "document_analysis";
|
|
332
|
-
var AttachmentTypeImage = "image";
|
|
333
|
-
var AttachmentTypeAudio = "audio";
|
|
334
|
-
var AttachmentTypeVideo = "video";
|
|
335
|
-
var AttachmentTypeLocation = "location";
|
|
336
|
-
var AttachmentTypeReferences = "references";
|
|
337
|
-
var AttachmentTypeSubsections = "subsections";
|
|
338
|
-
var AttachmentTypeArticles = "articles";
|
|
339
|
-
var AttachmentTypeRecords = "records";
|
|
340
|
-
var AttachmentTypeActions = "actions";
|
|
341
|
-
var AttachmentTypeBullets = "bullets";
|
|
342
|
-
var AttachmentTypeSticker = "sticker";
|
|
343
|
-
var AttachmentTypeData = "data";
|
|
344
|
-
var AttachmentTypeKGNodes = "kgNodes";
|
|
345
|
-
var AttachmentTypeDocumentSources = "document_sources";
|
|
346
|
-
var ChatSessionStatusActive = "active";
|
|
347
|
-
var ChatSessionStatusIdle = "idle";
|
|
348
|
-
var ChatSessionStatusExpired = "expired";
|
|
349
|
-
var UserStatusOnline = "online";
|
|
350
|
-
var UserStatusAway = "away";
|
|
351
|
-
var UserStatusBusy = "busy";
|
|
352
|
-
var UserStatusOffline = "offline";
|
|
353
|
-
var QueueTypes = {
|
|
354
|
-
skill: { value: "skill", label: "Skill-based", description: "Route by agent expertise and skills" },
|
|
355
|
-
priority: { value: "priority", label: "Priority-based", description: "Route by customer tier and urgency level" },
|
|
356
|
-
department: { value: "department", label: "Department-based", description: "Route by business function alignment" },
|
|
357
|
-
complexity: { value: "complexity", label: "Complexity-based", description: "Route by issue difficulty assessment" }
|
|
358
|
-
};
|
|
359
|
-
var QueueTypeSkill = "skill";
|
|
360
|
-
var QueueTypePriority = "priority";
|
|
361
|
-
var QueueTypeDepartment = "department";
|
|
362
|
-
var QueueTypeComplexity = "complexity";
|
|
363
|
-
var GetWaitingForAgentChatCountSubject = "chat.get_waiting_for_agent_chat_count";
|
|
364
|
-
var GetActiveChatCountSubject = "chat.get_active_chat_count";
|
|
365
|
-
var GetWaitingForAgentChatsSubject = "chat.get_waiting_for_agent_chats";
|
|
366
|
-
var GetActiveChatsSubject = "chat.get_active_chats";
|
|
367
|
-
var GetUserChatsSubject = "chat.get_user_chats";
|
|
368
|
-
var GetChatSubject = "chat.get_chat";
|
|
369
|
-
var ChatArchiveSubjectPattern = "chat.archive.%s.server";
|
|
370
|
-
var StartAgentSessionSubject = "chat.agent_session.start";
|
|
371
|
-
var EndAgentSessionSubject = "chat.agent_session.end";
|
|
372
|
-
var UpdateAgentStatusSubject = "chat.agent_session.update_status";
|
|
373
|
-
var UpdateAgentLastActivitySubject = "chat.agent_session.update_last_activity";
|
|
374
|
-
var AssignChatToAgentSubject = "chat.agent_session.assign_chat";
|
|
375
|
-
var CompleteChatByAgentSubject = "chat.agent_session.complete_chat";
|
|
376
|
-
var GetAgentSessionSubject = "chat.agent_session.get";
|
|
377
|
-
var GetOnlineAgentsSubject = "chat.agent_session.get_online_agents";
|
|
378
|
-
var GetOnlineAgentCountSubject = "chat.agent_session.get_online_agent_count";
|
|
379
|
-
var CreateAgentQueueSubject = "chat.agent_queue.create";
|
|
380
|
-
var GetAgentQueuesSubject = "chat.agent_queue.get";
|
|
381
|
-
var UpdateAgentQueueSubject = "chat.agent_queue.update";
|
|
382
|
-
var DeleteAgentQueueSubject = "chat.agent_queue.delete";
|
|
383
|
-
var GetQueueChatsSubject = "chat.queue.get_chats";
|
|
384
|
-
var GetQueueChatCountSubject = "chat.queue.get_chat_count";
|
|
385
|
-
var GetDailyChatCountSubject = "chat.get_daily_chat_count";
|
|
386
|
-
var UpdateUserStatusSubject = "chat.user.status.update";
|
|
387
|
-
var GetOnlineUsersSubject = "chat.users.online.get";
|
|
388
|
-
var TriggerAnalyticsScanSubject = "chat.analytics.trigger-scan";
|
|
389
|
-
var SetupOrgSubject = "chat.org.setup";
|
|
390
|
-
|
|
391
|
-
// hooks/use-websocket-chat-base.ts
|
|
392
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
393
|
-
var createDefaultLogger = (debug) => ({
|
|
394
|
-
debug: debug ? console.log : () => {
|
|
395
|
-
},
|
|
396
|
-
info: console.info,
|
|
397
|
-
warn: console.warn,
|
|
398
|
-
error: console.error
|
|
399
|
-
});
|
|
400
|
-
var DEFAULT_RETRY_CONFIG = {
|
|
401
|
-
maxRetries: 10,
|
|
402
|
-
intervals: [1e3, 2e3, 5e3],
|
|
403
|
-
backoffMultiplier: 1.5,
|
|
404
|
-
maxBackoffTime: 3e4
|
|
405
|
-
};
|
|
406
|
-
var DEFAULT_QUEUE_CONFIG = {
|
|
407
|
-
maxSize: 100,
|
|
408
|
-
dropStrategy: "oldest"
|
|
409
|
-
};
|
|
410
|
-
var DEFAULT_HEARTBEAT_INTERVAL = 3e4;
|
|
411
|
-
var DEFAULT_HEARTBEAT_TIMEOUT = 5e3;
|
|
412
|
-
function isChatEvent(data) {
|
|
413
|
-
return data && typeof data === "object" && (typeof data.type === "string" || data.message);
|
|
414
|
-
}
|
|
415
|
-
var useWebSocketChatBase = ({
|
|
416
|
-
serverBaseUrl,
|
|
417
|
-
orgId,
|
|
418
|
-
clientType,
|
|
419
|
-
product,
|
|
420
|
-
onMessage,
|
|
421
|
-
retryConfig = DEFAULT_RETRY_CONFIG,
|
|
422
|
-
queueConfig = DEFAULT_QUEUE_CONFIG,
|
|
423
|
-
debug = false,
|
|
424
|
-
logger = createDefaultLogger(debug),
|
|
425
|
-
heartbeatInterval = DEFAULT_HEARTBEAT_INTERVAL,
|
|
426
|
-
heartbeatTimeout = DEFAULT_HEARTBEAT_TIMEOUT
|
|
427
|
-
}) => {
|
|
428
|
-
const [connectionState, setConnectionState] = useState("disconnected");
|
|
429
|
-
const [error, setError] = useState(void 0);
|
|
430
|
-
const [startTime, setStartTime] = useState(void 0);
|
|
431
|
-
const [metrics, setMetrics] = useState({
|
|
432
|
-
latency: 0,
|
|
433
|
-
messagesSent: 0,
|
|
434
|
-
messagesReceived: 0,
|
|
435
|
-
messagesQueued: 0,
|
|
436
|
-
reconnectCount: 0
|
|
437
|
-
});
|
|
438
|
-
const wsRef = useRef(void 0);
|
|
439
|
-
const reconnectTimeoutRef = useRef(void 0);
|
|
440
|
-
const retryCountRef = useRef(0);
|
|
441
|
-
const messageQueueRef = useRef([]);
|
|
442
|
-
const mountedRef = useRef(false);
|
|
443
|
-
const currentChatKeyRef = useRef(void 0);
|
|
444
|
-
const currentUserIdRef = useRef(void 0);
|
|
445
|
-
const intentionalDisconnectRef = useRef(false);
|
|
446
|
-
const eventHandlersRef = useRef(
|
|
447
|
-
/* @__PURE__ */ new Map()
|
|
448
|
-
);
|
|
449
|
-
const onMessageRef = useRef(onMessage);
|
|
450
|
-
const pendingMessagesRef = useRef(/* @__PURE__ */ new Map());
|
|
451
|
-
const heartbeatIntervalRef = useRef(void 0);
|
|
452
|
-
const heartbeatTimeoutRef = useRef(void 0);
|
|
453
|
-
const lastPongRef = useRef(Date.now());
|
|
454
|
-
const chatCreationPromiseRef = useRef(null);
|
|
455
|
-
const loadChatRetryMapRef = useRef(/* @__PURE__ */ new Map());
|
|
456
|
-
useEffect(() => {
|
|
457
|
-
onMessageRef.current = onMessage;
|
|
458
|
-
}, [onMessage]);
|
|
459
|
-
const isConnected = connectionState === "connected";
|
|
460
|
-
const on = useCallback((eventType, handler) => {
|
|
461
|
-
if (!eventHandlersRef.current.has(eventType)) {
|
|
462
|
-
eventHandlersRef.current.set(eventType, /* @__PURE__ */ new Set());
|
|
463
|
-
}
|
|
464
|
-
eventHandlersRef.current.get(eventType).add(handler);
|
|
465
|
-
return () => off(eventType, handler);
|
|
466
|
-
}, []);
|
|
467
|
-
const off = useCallback((eventType, handler) => {
|
|
468
|
-
const handlers = eventHandlersRef.current.get(eventType);
|
|
469
|
-
if (handlers) {
|
|
470
|
-
handlers.delete(handler);
|
|
471
|
-
if (handlers.size === 0) {
|
|
472
|
-
eventHandlersRef.current.delete(eventType);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}, []);
|
|
476
|
-
const emit = useCallback(
|
|
477
|
-
(eventType, data) => {
|
|
478
|
-
const handlers = eventHandlersRef.current.get(eventType);
|
|
479
|
-
if (handlers) {
|
|
480
|
-
handlers.forEach((handler) => {
|
|
481
|
-
try {
|
|
482
|
-
handler(data);
|
|
483
|
-
} catch (error2) {
|
|
484
|
-
logger.error(`Error in event handler for ${eventType}:`, error2);
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
},
|
|
489
|
-
[logger]
|
|
490
|
-
);
|
|
491
|
-
const updateMetrics = useCallback((updates) => {
|
|
492
|
-
setMetrics((prev) => ({ ...prev, ...updates }));
|
|
493
|
-
}, []);
|
|
494
|
-
const addToQueue = useCallback(
|
|
495
|
-
(event) => {
|
|
496
|
-
const currentQueueSize = messageQueueRef.current.length;
|
|
497
|
-
const maxSize = queueConfig.maxSize || DEFAULT_QUEUE_CONFIG.maxSize;
|
|
498
|
-
if (currentQueueSize >= maxSize) {
|
|
499
|
-
if (queueConfig.dropStrategy === "newest") {
|
|
500
|
-
logger.warn("Message queue full, dropping new message");
|
|
501
|
-
return false;
|
|
502
|
-
} else {
|
|
503
|
-
const dropped = messageQueueRef.current.shift();
|
|
504
|
-
logger.warn("Message queue full, dropped oldest message", dropped);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
messageQueueRef.current.push(event);
|
|
508
|
-
updateMetrics({ messagesQueued: messageQueueRef.current.length });
|
|
509
|
-
return true;
|
|
510
|
-
},
|
|
511
|
-
[queueConfig, logger, updateMetrics]
|
|
512
|
-
);
|
|
513
|
-
const calculateRetryInterval = useCallback(
|
|
514
|
-
(retryCount) => {
|
|
515
|
-
const config = { ...DEFAULT_RETRY_CONFIG, ...retryConfig };
|
|
516
|
-
const {
|
|
517
|
-
intervals = [],
|
|
518
|
-
backoffMultiplier = 1.5,
|
|
519
|
-
maxBackoffTime = 3e4
|
|
520
|
-
} = config;
|
|
521
|
-
if (retryCount < intervals.length) {
|
|
522
|
-
return intervals[retryCount];
|
|
523
|
-
}
|
|
524
|
-
const baseInterval = intervals[intervals.length - 1] || 5e3;
|
|
525
|
-
const backoffTime = baseInterval * Math.pow(backoffMultiplier, retryCount - intervals.length + 1);
|
|
526
|
-
return Math.min(backoffTime, maxBackoffTime);
|
|
527
|
-
},
|
|
528
|
-
[retryConfig]
|
|
529
|
-
);
|
|
530
|
-
const startHeartbeat = useCallback(() => {
|
|
531
|
-
if (!heartbeatInterval || heartbeatInterval <= 0) return;
|
|
532
|
-
const sendPing = () => {
|
|
533
|
-
if (wsRef.current?.readyState === WebSocket.OPEN) {
|
|
534
|
-
const pingTime = Date.now();
|
|
535
|
-
wsRef.current.send(
|
|
536
|
-
JSON.stringify({ type: "ping", timestamp: pingTime })
|
|
537
|
-
);
|
|
538
|
-
heartbeatTimeoutRef.current = setTimeout(() => {
|
|
539
|
-
logger.warn("Heartbeat timeout - no pong received");
|
|
540
|
-
if (wsRef.current) {
|
|
541
|
-
wsRef.current.close(4e3, "Heartbeat timeout");
|
|
542
|
-
}
|
|
543
|
-
}, heartbeatTimeout);
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
if (heartbeatIntervalRef.current) {
|
|
547
|
-
clearInterval(heartbeatIntervalRef.current);
|
|
548
|
-
}
|
|
549
|
-
heartbeatIntervalRef.current = setInterval(sendPing, heartbeatInterval);
|
|
550
|
-
logger.debug("Heartbeat started");
|
|
551
|
-
}, [heartbeatInterval, heartbeatTimeout, logger]);
|
|
552
|
-
const stopHeartbeat = useCallback(() => {
|
|
553
|
-
if (heartbeatIntervalRef.current) {
|
|
554
|
-
clearInterval(heartbeatIntervalRef.current);
|
|
555
|
-
heartbeatIntervalRef.current = void 0;
|
|
556
|
-
}
|
|
557
|
-
if (heartbeatTimeoutRef.current) {
|
|
558
|
-
clearTimeout(heartbeatTimeoutRef.current);
|
|
559
|
-
heartbeatTimeoutRef.current = void 0;
|
|
560
|
-
}
|
|
561
|
-
logger.debug("Heartbeat stopped");
|
|
562
|
-
}, [logger]);
|
|
563
|
-
const cleanup = useCallback(() => {
|
|
564
|
-
if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
|
|
565
|
-
wsRef.current.close(1e3, "Cleanup");
|
|
566
|
-
}
|
|
567
|
-
wsRef.current = void 0;
|
|
568
|
-
if (reconnectTimeoutRef.current) {
|
|
569
|
-
clearTimeout(reconnectTimeoutRef.current);
|
|
570
|
-
reconnectTimeoutRef.current = void 0;
|
|
571
|
-
}
|
|
572
|
-
stopHeartbeat();
|
|
573
|
-
pendingMessagesRef.current.forEach(({ reject, timeout }) => {
|
|
574
|
-
clearTimeout(timeout);
|
|
575
|
-
reject(new Error("Connection closed"));
|
|
576
|
-
});
|
|
577
|
-
pendingMessagesRef.current.clear();
|
|
578
|
-
loadChatRetryMapRef.current.forEach((retryState) => {
|
|
579
|
-
if (retryState.timeoutId) {
|
|
580
|
-
clearTimeout(retryState.timeoutId);
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
loadChatRetryMapRef.current.clear();
|
|
584
|
-
}, [stopHeartbeat]);
|
|
585
|
-
const connect = useCallback(
|
|
586
|
-
async (userId) => {
|
|
587
|
-
if (!mountedRef.current) {
|
|
588
|
-
mountedRef.current = true;
|
|
589
|
-
}
|
|
590
|
-
if (!orgId) {
|
|
591
|
-
const error2 = {
|
|
592
|
-
code: "CONNECTION_FAILED",
|
|
593
|
-
message: "Cannot connect: orgId is undefined",
|
|
594
|
-
retryable: false,
|
|
595
|
-
timestamp: Date.now()
|
|
596
|
-
};
|
|
597
|
-
logger.error("Cannot connect: orgId is undefined");
|
|
598
|
-
setError(error2);
|
|
599
|
-
return Promise.reject(error2);
|
|
600
|
-
}
|
|
601
|
-
if (wsRef.current?.readyState === WebSocket.OPEN) {
|
|
602
|
-
logger.debug("Already connected");
|
|
603
|
-
return Promise.resolve();
|
|
604
|
-
}
|
|
605
|
-
if (connectionState === "connecting" || connectionState === "reconnecting") {
|
|
606
|
-
logger.debug("Connection already in progress");
|
|
607
|
-
return Promise.resolve();
|
|
608
|
-
}
|
|
609
|
-
const maxRetries = retryConfig.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries;
|
|
610
|
-
if (retryCountRef.current >= maxRetries && !intentionalDisconnectRef.current) {
|
|
611
|
-
const error2 = {
|
|
612
|
-
code: "CONNECTION_FAILED",
|
|
613
|
-
message: `Max retries (${maxRetries}) exceeded`,
|
|
614
|
-
retryable: false,
|
|
615
|
-
timestamp: Date.now()
|
|
616
|
-
};
|
|
617
|
-
setError(error2);
|
|
618
|
-
updateMetrics({ lastError: error2 });
|
|
619
|
-
return Promise.reject(error2);
|
|
620
|
-
}
|
|
621
|
-
cleanup();
|
|
622
|
-
setConnectionState(
|
|
623
|
-
retryCountRef.current > 0 ? "reconnecting" : "connecting"
|
|
624
|
-
);
|
|
625
|
-
intentionalDisconnectRef.current = false;
|
|
626
|
-
return new Promise((resolve, reject) => {
|
|
627
|
-
try {
|
|
628
|
-
const wsUrl = `${serverBaseUrl}?orgId=${orgId}&userId=${userId}&clientType=${clientType}&product=${product}`;
|
|
629
|
-
const connectionStartTime = Date.now();
|
|
630
|
-
logger.debug("Connecting to WebSocket:", wsUrl);
|
|
631
|
-
console.log(`\u23F3 Initiating WebSocket connection to ${serverBaseUrl}...`);
|
|
632
|
-
const ws = new WebSocket(wsUrl);
|
|
633
|
-
ws.onopen = () => {
|
|
634
|
-
if (!mountedRef.current) {
|
|
635
|
-
ws.close(1e3, "Component unmounted");
|
|
636
|
-
reject(new Error("Component unmounted"));
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
639
|
-
const connectionTimeMs = Date.now() - connectionStartTime;
|
|
640
|
-
const connectionTimeSec = (connectionTimeMs / 1e3).toFixed(2);
|
|
641
|
-
logger.info("\u2705 WebSocket connected", {
|
|
642
|
-
userId,
|
|
643
|
-
retryCount: retryCountRef.current,
|
|
644
|
-
connectionTime: `${connectionTimeSec}s (${connectionTimeMs}ms)`
|
|
645
|
-
});
|
|
646
|
-
console.log(`\u{1F50C} WebSocket connection established in ${connectionTimeSec} seconds`);
|
|
647
|
-
setConnectionState("connected");
|
|
648
|
-
setError(void 0);
|
|
649
|
-
const wasReconnecting = retryCountRef.current > 0;
|
|
650
|
-
retryCountRef.current = 0;
|
|
651
|
-
updateMetrics({
|
|
652
|
-
connectedAt: Date.now(),
|
|
653
|
-
latency: connectionTimeMs,
|
|
654
|
-
reconnectCount: wasReconnecting ? metrics.reconnectCount + 1 : metrics.reconnectCount
|
|
655
|
-
});
|
|
656
|
-
while (messageQueueRef.current.length > 0 && ws.readyState === WebSocket.OPEN) {
|
|
657
|
-
const event = messageQueueRef.current.shift();
|
|
658
|
-
if (event) {
|
|
659
|
-
ws.send(JSON.stringify({ ...event, timestamp: Date.now() }));
|
|
660
|
-
updateMetrics({
|
|
661
|
-
messagesSent: metrics.messagesSent + 1,
|
|
662
|
-
messagesQueued: messageQueueRef.current.length
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
currentUserIdRef.current = userId;
|
|
667
|
-
if (currentChatKeyRef.current) {
|
|
668
|
-
if (!orgId) {
|
|
669
|
-
logger.error("Cannot resubscribe to chat: orgId is undefined");
|
|
670
|
-
} else {
|
|
671
|
-
logger.info(
|
|
672
|
-
"Resubscribing to chat after reconnection:",
|
|
673
|
-
currentChatKeyRef.current
|
|
674
|
-
);
|
|
675
|
-
const resubscribeEvent = {
|
|
676
|
-
type: "load_chat",
|
|
677
|
-
orgId,
|
|
678
|
-
chatKey: currentChatKeyRef.current,
|
|
679
|
-
userId,
|
|
680
|
-
timestamp: Date.now(),
|
|
681
|
-
data: {}
|
|
682
|
-
};
|
|
683
|
-
ws.send(JSON.stringify(resubscribeEvent));
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
startHeartbeat();
|
|
687
|
-
emit("connected", { userId, wasReconnecting });
|
|
688
|
-
resolve();
|
|
689
|
-
};
|
|
690
|
-
ws.onmessage = (event) => {
|
|
691
|
-
if (!mountedRef.current) return;
|
|
692
|
-
try {
|
|
693
|
-
const data = JSON.parse(event.data);
|
|
694
|
-
if (!isChatEvent(data)) {
|
|
695
|
-
logger.warn("Received invalid message format:", data);
|
|
696
|
-
return;
|
|
697
|
-
}
|
|
698
|
-
const chatEvent = data;
|
|
699
|
-
logger.debug("Message received:", chatEvent.type);
|
|
700
|
-
updateMetrics({
|
|
701
|
-
messagesReceived: metrics.messagesReceived + 1,
|
|
702
|
-
lastMessageAt: Date.now()
|
|
703
|
-
});
|
|
704
|
-
if (chatEvent.type === "pong") {
|
|
705
|
-
if (heartbeatTimeoutRef.current) {
|
|
706
|
-
clearTimeout(heartbeatTimeoutRef.current);
|
|
707
|
-
heartbeatTimeoutRef.current = void 0;
|
|
708
|
-
}
|
|
709
|
-
const latency = Date.now() - (chatEvent.timestamp || Date.now());
|
|
710
|
-
lastPongRef.current = Date.now();
|
|
711
|
-
updateMetrics({ latency });
|
|
712
|
-
return;
|
|
713
|
-
}
|
|
714
|
-
switch (chatEvent.type) {
|
|
715
|
-
case "new_chat_created":
|
|
716
|
-
const newChatKey = chatEvent.data?.chatKey;
|
|
717
|
-
if (newChatKey) {
|
|
718
|
-
logger.info("New chat created with key:", newChatKey);
|
|
719
|
-
currentChatKeyRef.current = newChatKey;
|
|
720
|
-
if (chatCreationPromiseRef.current) {
|
|
721
|
-
chatCreationPromiseRef.current.resolve(newChatKey);
|
|
722
|
-
chatCreationPromiseRef.current = null;
|
|
723
|
-
}
|
|
724
|
-
if (!orgId) {
|
|
725
|
-
logger.error("Cannot send load_chat: orgId is undefined");
|
|
726
|
-
return;
|
|
727
|
-
}
|
|
728
|
-
const loadChatEvent = {
|
|
729
|
-
type: "load_chat",
|
|
730
|
-
orgId,
|
|
731
|
-
chatKey: newChatKey,
|
|
732
|
-
userId: currentUserIdRef.current || userId,
|
|
733
|
-
timestamp: Date.now(),
|
|
734
|
-
data: {}
|
|
735
|
-
};
|
|
736
|
-
ws.send(JSON.stringify(loadChatEvent));
|
|
737
|
-
}
|
|
738
|
-
break;
|
|
739
|
-
case "load_chat_response":
|
|
740
|
-
const chat = chatEvent.data?.chat;
|
|
741
|
-
if (chat && chat.key) {
|
|
742
|
-
logger.info("Chat loaded with key:", chat.key);
|
|
743
|
-
currentChatKeyRef.current = chat.key;
|
|
744
|
-
const retryState = loadChatRetryMapRef.current.get(chat.key);
|
|
745
|
-
if (retryState) {
|
|
746
|
-
if (retryState.timeoutId) {
|
|
747
|
-
clearTimeout(retryState.timeoutId);
|
|
748
|
-
}
|
|
749
|
-
loadChatRetryMapRef.current.delete(chat.key);
|
|
750
|
-
}
|
|
751
|
-
} else if (!chat) {
|
|
752
|
-
logger.warn("Chat load failed, clearing key");
|
|
753
|
-
currentChatKeyRef.current = void 0;
|
|
754
|
-
}
|
|
755
|
-
break;
|
|
756
|
-
case "chat_ended":
|
|
757
|
-
logger.info("Chat ended, clearing key");
|
|
758
|
-
currentChatKeyRef.current = void 0;
|
|
759
|
-
break;
|
|
760
|
-
case "error":
|
|
761
|
-
const errorMessage = chatEvent.data?.message || "Unknown error";
|
|
762
|
-
logger.error("Received error from server:", errorMessage);
|
|
763
|
-
if (errorMessage.includes("nats: key not found") || errorMessage.includes("Failed to load chat")) {
|
|
764
|
-
const chatKeyFromError = currentChatKeyRef.current;
|
|
765
|
-
if (chatKeyFromError) {
|
|
766
|
-
const maxRetries2 = 5;
|
|
767
|
-
let retryState = loadChatRetryMapRef.current.get(chatKeyFromError);
|
|
768
|
-
if (!retryState) {
|
|
769
|
-
retryState = { retryCount: 0, timeoutId: null };
|
|
770
|
-
loadChatRetryMapRef.current.set(chatKeyFromError, retryState);
|
|
771
|
-
}
|
|
772
|
-
if (retryState.retryCount < maxRetries2) {
|
|
773
|
-
const delay = 200 * Math.pow(2, retryState.retryCount);
|
|
774
|
-
retryState.retryCount++;
|
|
775
|
-
logger.info(
|
|
776
|
-
`Chat load failed, retrying (${retryState.retryCount}/${maxRetries2}) in ${delay}ms...`,
|
|
777
|
-
chatKeyFromError
|
|
778
|
-
);
|
|
779
|
-
retryState.timeoutId = setTimeout(() => {
|
|
780
|
-
if (!wsRef.current || !mountedRef.current) return;
|
|
781
|
-
if (!orgId) {
|
|
782
|
-
logger.error("Cannot retry load_chat: orgId is undefined", chatKeyFromError);
|
|
783
|
-
loadChatRetryMapRef.current.delete(chatKeyFromError);
|
|
784
|
-
return;
|
|
785
|
-
}
|
|
786
|
-
logger.debug("Retrying load_chat:", chatKeyFromError);
|
|
787
|
-
const retryLoadEvent = {
|
|
788
|
-
type: "load_chat",
|
|
789
|
-
orgId,
|
|
790
|
-
chatKey: chatKeyFromError,
|
|
791
|
-
userId: currentUserIdRef.current || "",
|
|
792
|
-
timestamp: Date.now(),
|
|
793
|
-
data: {}
|
|
794
|
-
};
|
|
795
|
-
ws.send(JSON.stringify(retryLoadEvent));
|
|
796
|
-
}, delay);
|
|
797
|
-
} else {
|
|
798
|
-
logger.error("Max retries reached for loading chat:", chatKeyFromError);
|
|
799
|
-
loadChatRetryMapRef.current.delete(chatKeyFromError);
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
const wsError = {
|
|
804
|
-
code: "NETWORK_ERROR",
|
|
805
|
-
message: errorMessage,
|
|
806
|
-
retryable: true,
|
|
807
|
-
timestamp: Date.now()
|
|
808
|
-
};
|
|
809
|
-
setError(wsError);
|
|
810
|
-
updateMetrics({ lastError: wsError });
|
|
811
|
-
break;
|
|
812
|
-
}
|
|
813
|
-
emit(chatEvent.type || "message", chatEvent);
|
|
814
|
-
if (onMessageRef.current) {
|
|
815
|
-
onMessageRef.current(chatEvent);
|
|
816
|
-
}
|
|
817
|
-
} catch (error2) {
|
|
818
|
-
logger.error("Failed to parse WebSocket message:", error2);
|
|
819
|
-
const parseError = {
|
|
820
|
-
code: "PARSE_ERROR",
|
|
821
|
-
message: "Failed to parse message",
|
|
822
|
-
retryable: false,
|
|
823
|
-
timestamp: Date.now()
|
|
824
|
-
};
|
|
825
|
-
setError(parseError);
|
|
826
|
-
updateMetrics({ lastError: parseError });
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
ws.onclose = (event) => {
|
|
830
|
-
if (!mountedRef.current) return;
|
|
831
|
-
logger.info("WebSocket closed", {
|
|
832
|
-
code: event.code,
|
|
833
|
-
reason: event.reason
|
|
834
|
-
});
|
|
835
|
-
setConnectionState("disconnected");
|
|
836
|
-
wsRef.current = void 0;
|
|
837
|
-
stopHeartbeat();
|
|
838
|
-
emit("disconnected", { code: event.code, reason: event.reason });
|
|
839
|
-
if (event.code !== 1e3 && !intentionalDisconnectRef.current && mountedRef.current) {
|
|
840
|
-
const retryInterval = calculateRetryInterval(
|
|
841
|
-
retryCountRef.current
|
|
842
|
-
);
|
|
843
|
-
retryCountRef.current++;
|
|
844
|
-
logger.info(
|
|
845
|
-
`Reconnecting in ${retryInterval}ms (attempt ${retryCountRef.current})`
|
|
846
|
-
);
|
|
847
|
-
if (reconnectTimeoutRef.current) {
|
|
848
|
-
clearTimeout(reconnectTimeoutRef.current);
|
|
849
|
-
}
|
|
850
|
-
reconnectTimeoutRef.current = setTimeout(() => {
|
|
851
|
-
connect(userId);
|
|
852
|
-
}, retryInterval);
|
|
853
|
-
}
|
|
854
|
-
};
|
|
855
|
-
ws.onerror = (error2) => {
|
|
856
|
-
logger.error("WebSocket error:", error2);
|
|
857
|
-
if (!mountedRef.current) return;
|
|
858
|
-
const wsError = {
|
|
859
|
-
code: "CONNECTION_FAILED",
|
|
860
|
-
message: "WebSocket connection failed",
|
|
861
|
-
retryable: true,
|
|
862
|
-
timestamp: Date.now()
|
|
863
|
-
};
|
|
864
|
-
setError(wsError);
|
|
865
|
-
updateMetrics({ lastError: wsError });
|
|
866
|
-
reject(wsError);
|
|
867
|
-
};
|
|
868
|
-
wsRef.current = ws;
|
|
869
|
-
} catch (error2) {
|
|
870
|
-
logger.error("Failed to create WebSocket:", error2);
|
|
871
|
-
const wsError = {
|
|
872
|
-
code: "CONNECTION_FAILED",
|
|
873
|
-
message: error2 instanceof Error ? error2.message : "Failed to create connection",
|
|
874
|
-
retryable: true,
|
|
875
|
-
timestamp: Date.now()
|
|
876
|
-
};
|
|
877
|
-
setError(wsError);
|
|
878
|
-
updateMetrics({ lastError: wsError });
|
|
879
|
-
reject(wsError);
|
|
880
|
-
}
|
|
881
|
-
});
|
|
882
|
-
},
|
|
883
|
-
[
|
|
884
|
-
serverBaseUrl,
|
|
885
|
-
orgId,
|
|
886
|
-
clientType,
|
|
887
|
-
product,
|
|
888
|
-
connectionState,
|
|
889
|
-
logger,
|
|
890
|
-
retryConfig,
|
|
891
|
-
metrics,
|
|
892
|
-
updateMetrics,
|
|
893
|
-
cleanup,
|
|
894
|
-
calculateRetryInterval,
|
|
895
|
-
startHeartbeat,
|
|
896
|
-
emit
|
|
897
|
-
]
|
|
898
|
-
);
|
|
899
|
-
const sendMessage = useCallback(
|
|
900
|
-
(event, overrideUserId) => {
|
|
901
|
-
return new Promise((resolve, reject) => {
|
|
902
|
-
if (!mountedRef.current) {
|
|
903
|
-
reject(new Error("Component not mounted"));
|
|
904
|
-
return;
|
|
905
|
-
}
|
|
906
|
-
const fullEvent = {
|
|
907
|
-
...event,
|
|
908
|
-
timestamp: Date.now()
|
|
909
|
-
};
|
|
910
|
-
const messageId = `${fullEvent.type}_${fullEvent.timestamp}_${Math.random()}`;
|
|
911
|
-
logger.debug("Sending message:", fullEvent.type);
|
|
912
|
-
if (!wsRef.current || wsRef.current.readyState !== WebSocket.OPEN) {
|
|
913
|
-
if (addToQueue(fullEvent)) {
|
|
914
|
-
logger.debug("Message queued, attempting to connect");
|
|
915
|
-
if (connectionState === "disconnected" && overrideUserId) {
|
|
916
|
-
connect(overrideUserId).then(() => resolve()).catch(reject);
|
|
917
|
-
} else {
|
|
918
|
-
resolve();
|
|
919
|
-
}
|
|
920
|
-
} else {
|
|
921
|
-
reject(new Error("Message queue full"));
|
|
922
|
-
}
|
|
923
|
-
return;
|
|
924
|
-
}
|
|
925
|
-
try {
|
|
926
|
-
wsRef.current.send(JSON.stringify(fullEvent));
|
|
927
|
-
updateMetrics({ messagesSent: metrics.messagesSent + 1 });
|
|
928
|
-
logger.debug("Message sent successfully");
|
|
929
|
-
resolve();
|
|
930
|
-
} catch (error2) {
|
|
931
|
-
logger.error("Failed to send message:", error2);
|
|
932
|
-
if (addToQueue(fullEvent)) {
|
|
933
|
-
resolve();
|
|
934
|
-
} else {
|
|
935
|
-
const sendError = {
|
|
936
|
-
code: "SEND_FAILED",
|
|
937
|
-
message: error2 instanceof Error ? error2.message : "Failed to send message",
|
|
938
|
-
retryable: true,
|
|
939
|
-
timestamp: Date.now()
|
|
940
|
-
};
|
|
941
|
-
setError(sendError);
|
|
942
|
-
updateMetrics({ lastError: sendError });
|
|
943
|
-
reject(sendError);
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
});
|
|
947
|
-
},
|
|
948
|
-
[connectionState, connect, addToQueue, logger, metrics, updateMetrics]
|
|
949
|
-
);
|
|
950
|
-
const startNewChat = useCallback(
|
|
951
|
-
(userId, data) => {
|
|
952
|
-
return new Promise((resolve, reject) => {
|
|
953
|
-
if (!userId) {
|
|
954
|
-
reject(new Error("User ID is required"));
|
|
955
|
-
return;
|
|
956
|
-
}
|
|
957
|
-
logger.info("Requesting new chat from server with userId:", userId);
|
|
958
|
-
setStartTime(/* @__PURE__ */ new Date());
|
|
959
|
-
chatCreationPromiseRef.current = { resolve, reject };
|
|
960
|
-
sendMessage(
|
|
961
|
-
{
|
|
962
|
-
type: "new_chat",
|
|
963
|
-
orgId,
|
|
964
|
-
chatKey: "",
|
|
965
|
-
// Server will generate
|
|
966
|
-
userId,
|
|
967
|
-
data: data ?? {}
|
|
968
|
-
},
|
|
969
|
-
userId
|
|
970
|
-
).catch((error2) => {
|
|
971
|
-
chatCreationPromiseRef.current = null;
|
|
972
|
-
reject(error2);
|
|
973
|
-
});
|
|
974
|
-
setTimeout(() => {
|
|
975
|
-
if (chatCreationPromiseRef.current) {
|
|
976
|
-
chatCreationPromiseRef.current = null;
|
|
977
|
-
reject(new Error("Chat creation timed out"));
|
|
978
|
-
}
|
|
979
|
-
}, 3e4);
|
|
980
|
-
});
|
|
981
|
-
},
|
|
982
|
-
[sendMessage, orgId, logger]
|
|
983
|
-
);
|
|
984
|
-
const disconnect = useCallback(
|
|
985
|
-
(intentional = true) => {
|
|
986
|
-
logger.info("Disconnecting WebSocket", { intentional });
|
|
987
|
-
intentionalDisconnectRef.current = intentional;
|
|
988
|
-
cleanup();
|
|
989
|
-
setConnectionState("disconnected");
|
|
990
|
-
messageQueueRef.current = [];
|
|
991
|
-
retryCountRef.current = 0;
|
|
992
|
-
mountedRef.current = false;
|
|
993
|
-
currentChatKeyRef.current = void 0;
|
|
994
|
-
currentUserIdRef.current = void 0;
|
|
995
|
-
},
|
|
996
|
-
[cleanup, logger]
|
|
997
|
-
);
|
|
998
|
-
const clearError = useCallback(() => {
|
|
999
|
-
setError(void 0);
|
|
1000
|
-
}, []);
|
|
1001
|
-
useEffect(() => {
|
|
1002
|
-
mountedRef.current = true;
|
|
1003
|
-
return () => {
|
|
1004
|
-
mountedRef.current = false;
|
|
1005
|
-
disconnect(true);
|
|
1006
|
-
};
|
|
1007
|
-
}, []);
|
|
1008
|
-
return {
|
|
1009
|
-
connectionState,
|
|
1010
|
-
isConnected,
|
|
1011
|
-
sendMessage,
|
|
1012
|
-
error,
|
|
1013
|
-
connect,
|
|
1014
|
-
startNewChat,
|
|
1015
|
-
startTime,
|
|
1016
|
-
disconnect,
|
|
1017
|
-
metrics,
|
|
1018
|
-
on,
|
|
1019
|
-
off,
|
|
1020
|
-
clearError
|
|
1021
|
-
};
|
|
1022
|
-
};
|
|
1023
|
-
|
|
1024
|
-
// hooks/use-websocket-chat-admin.ts
|
|
1025
|
-
var useWebSocketChatAdmin = ({
|
|
1026
|
-
serverBaseUrl,
|
|
1027
|
-
orgId,
|
|
1028
|
-
product
|
|
1029
|
-
}) => {
|
|
1030
|
-
const [chats, setChats] = useState2(/* @__PURE__ */ new Map());
|
|
1031
|
-
const [selectedChat, setSelectedChat] = useState2(void 0);
|
|
1032
|
-
const handleMessage = useCallback2(
|
|
1033
|
-
(chatEvent) => {
|
|
1034
|
-
switch (chatEvent.type) {
|
|
1035
|
-
case "message":
|
|
1036
|
-
if (!selectedChat || !chatEvent.message) return;
|
|
1037
|
-
setChats((prev) => {
|
|
1038
|
-
const newMap = new Map(prev);
|
|
1039
|
-
newMap.set(selectedChat.key, {
|
|
1040
|
-
...selectedChat,
|
|
1041
|
-
messages: [...selectedChat.messages, chatEvent.message]
|
|
1042
|
-
});
|
|
1043
|
-
return newMap;
|
|
1044
|
-
});
|
|
1045
|
-
setSelectedChat((prev) => {
|
|
1046
|
-
if (!prev) return prev;
|
|
1047
|
-
return {
|
|
1048
|
-
...prev,
|
|
1049
|
-
messages: [...prev.messages, chatEvent.message]
|
|
1050
|
-
};
|
|
1051
|
-
});
|
|
1052
|
-
break;
|
|
1053
|
-
case "list_chats":
|
|
1054
|
-
const chatList = chatEvent.data?.chats;
|
|
1055
|
-
if (!chatList) return;
|
|
1056
|
-
setChats(new Map(chatList.map((chat) => [chat.key, chat])));
|
|
1057
|
-
break;
|
|
1058
|
-
case "chat_updated":
|
|
1059
|
-
const updatedChat = chatEvent.data?.chat?.value;
|
|
1060
|
-
if (updatedChat) {
|
|
1061
|
-
setChats((prev) => new Map(prev).set(updatedChat.key, updatedChat));
|
|
1062
|
-
}
|
|
1063
|
-
break;
|
|
1064
|
-
case "chat_removed":
|
|
1065
|
-
const chatKey = chatEvent.data?.chatKey?.value;
|
|
1066
|
-
if (chatKey) {
|
|
1067
|
-
setChats((prev) => {
|
|
1068
|
-
const newMap = new Map(prev);
|
|
1069
|
-
newMap.delete(chatKey);
|
|
1070
|
-
return newMap;
|
|
1071
|
-
});
|
|
1072
|
-
}
|
|
1073
|
-
break;
|
|
1074
|
-
case "load_chat":
|
|
1075
|
-
const history = chatEvent.data?.chat?.value;
|
|
1076
|
-
if (history) {
|
|
1077
|
-
setChats((prev) => {
|
|
1078
|
-
const existingChat = prev.get(history.key);
|
|
1079
|
-
if (!existingChat) return prev;
|
|
1080
|
-
return new Map(prev).set(history.key, {
|
|
1081
|
-
...existingChat,
|
|
1082
|
-
messages: history.messages
|
|
1083
|
-
});
|
|
1084
|
-
});
|
|
1085
|
-
}
|
|
1086
|
-
break;
|
|
1087
|
-
}
|
|
1088
|
-
},
|
|
1089
|
-
[selectedChat]
|
|
1090
|
-
);
|
|
1091
|
-
const base = useWebSocketChatBase({
|
|
1092
|
-
serverBaseUrl,
|
|
1093
|
-
orgId,
|
|
1094
|
-
clientType: "humanAgent",
|
|
1095
|
-
onMessage: handleMessage,
|
|
1096
|
-
product
|
|
1097
|
-
});
|
|
1098
|
-
const selectChat = useCallback2(
|
|
1099
|
-
(chatKey) => {
|
|
1100
|
-
const chat = chats.get(chatKey);
|
|
1101
|
-
if (!chat) {
|
|
1102
|
-
console.error("Unable to select chat", chatKey);
|
|
1103
|
-
return;
|
|
1104
|
-
}
|
|
1105
|
-
setSelectedChat(chat);
|
|
1106
|
-
},
|
|
1107
|
-
[chats, orgId, base.sendMessage]
|
|
1108
|
-
);
|
|
1109
|
-
const addUserToChat = useCallback2(
|
|
1110
|
-
(orgId2, chatKey, user) => {
|
|
1111
|
-
base.sendMessage({
|
|
1112
|
-
type: "human_agent_joined",
|
|
1113
|
-
orgId: orgId2,
|
|
1114
|
-
chatKey,
|
|
1115
|
-
userId: user.email,
|
|
1116
|
-
data: { user }
|
|
1117
|
-
});
|
|
1118
|
-
setChats((prev) => {
|
|
1119
|
-
const newMap = new Map(prev);
|
|
1120
|
-
const chat = newMap.get(chatKey);
|
|
1121
|
-
if (!chat) return prev;
|
|
1122
|
-
newMap.set(chatKey, {
|
|
1123
|
-
...chat,
|
|
1124
|
-
humanAgentEngaged: user.role === ChatRoleHumanAgent,
|
|
1125
|
-
users: [...chat?.users ?? [], user]
|
|
1126
|
-
});
|
|
1127
|
-
return newMap;
|
|
1128
|
-
});
|
|
1129
|
-
setSelectedChat((prev) => {
|
|
1130
|
-
if (!prev) return prev;
|
|
1131
|
-
return {
|
|
1132
|
-
...prev,
|
|
1133
|
-
humanAgentEngaged: user.role === ChatRoleHumanAgent,
|
|
1134
|
-
users: [...prev.users ?? [], user]
|
|
1135
|
-
};
|
|
1136
|
-
});
|
|
1137
|
-
},
|
|
1138
|
-
[base.sendMessage]
|
|
1139
|
-
);
|
|
1140
|
-
const removeUserFromChat = useCallback2(
|
|
1141
|
-
(orgId2, chatKey, userId) => {
|
|
1142
|
-
const chat = chats.get(chatKey);
|
|
1143
|
-
if (!chat) return;
|
|
1144
|
-
const user = chat.users?.find((u) => u.id === userId);
|
|
1145
|
-
if (!user) return;
|
|
1146
|
-
base.sendMessage({
|
|
1147
|
-
type: "human_agent_left",
|
|
1148
|
-
orgId: orgId2,
|
|
1149
|
-
chatKey,
|
|
1150
|
-
userId,
|
|
1151
|
-
data: { user }
|
|
1152
|
-
});
|
|
1153
|
-
setChats((prev) => {
|
|
1154
|
-
const newMap = new Map(prev);
|
|
1155
|
-
const chat2 = newMap.get(chatKey);
|
|
1156
|
-
if (!chat2) return prev;
|
|
1157
|
-
newMap.set(chatKey, {
|
|
1158
|
-
...chat2,
|
|
1159
|
-
humanAgentEngaged: false,
|
|
1160
|
-
users: chat2.users?.filter((u) => u.id !== userId)
|
|
1161
|
-
});
|
|
1162
|
-
return newMap;
|
|
1163
|
-
});
|
|
1164
|
-
},
|
|
1165
|
-
[chats, base.sendMessage]
|
|
1166
|
-
);
|
|
1167
|
-
const blockUser = useCallback2(
|
|
1168
|
-
(orgId2, chatKey, userId) => {
|
|
1169
|
-
base.sendMessage({
|
|
1170
|
-
type: "block_user",
|
|
1171
|
-
orgId: orgId2,
|
|
1172
|
-
chatKey,
|
|
1173
|
-
userId
|
|
1174
|
-
});
|
|
1175
|
-
},
|
|
1176
|
-
[base.sendMessage]
|
|
1177
|
-
);
|
|
1178
|
-
return {
|
|
1179
|
-
...base,
|
|
1180
|
-
chats,
|
|
1181
|
-
selectedChat,
|
|
1182
|
-
selectChat,
|
|
1183
|
-
addUserToChat,
|
|
1184
|
-
removeUserFromChat,
|
|
1185
|
-
blockUser
|
|
1186
|
-
};
|
|
1187
|
-
};
|
|
1188
|
-
|
|
1189
|
-
// hooks/use-websocket-chat-customer.ts
|
|
1190
|
-
import { useCallback as useCallback3, useState as useState3 } from "react";
|
|
1191
|
-
var useWebSocketChatCustomer = ({
|
|
1192
|
-
serverBaseUrl,
|
|
1193
|
-
orgId,
|
|
1194
|
-
chatKey,
|
|
1195
|
-
product
|
|
1196
|
-
}) => {
|
|
1197
|
-
const [currentChat, setCurrentChat] = useState3(void 0);
|
|
1198
|
-
const handleMessage = useCallback3((chatEvent) => {
|
|
1199
|
-
console.log("Received event:", chatEvent.type);
|
|
1200
|
-
switch (chatEvent.type) {
|
|
1201
|
-
case "message":
|
|
1202
|
-
if (!chatEvent.message) return;
|
|
1203
|
-
console.log(
|
|
1204
|
-
"got message:",
|
|
1205
|
-
chatEvent.message.role,
|
|
1206
|
-
":",
|
|
1207
|
-
chatEvent.message.content
|
|
1208
|
-
);
|
|
1209
|
-
setCurrentChat((prev) => {
|
|
1210
|
-
if (!prev) return prev;
|
|
1211
|
-
return {
|
|
1212
|
-
...prev,
|
|
1213
|
-
messages: [...prev.messages, chatEvent.message]
|
|
1214
|
-
};
|
|
1215
|
-
});
|
|
1216
|
-
break;
|
|
1217
|
-
case "chat_updated":
|
|
1218
|
-
const chat = chatEvent.data?.chat?.value;
|
|
1219
|
-
if (chat) {
|
|
1220
|
-
setCurrentChat(chat);
|
|
1221
|
-
}
|
|
1222
|
-
break;
|
|
1223
|
-
case "load_chat":
|
|
1224
|
-
const history = chatEvent.data?.chat;
|
|
1225
|
-
if (!history) return;
|
|
1226
|
-
setCurrentChat(history);
|
|
1227
|
-
break;
|
|
1228
|
-
default:
|
|
1229
|
-
break;
|
|
1230
|
-
}
|
|
1231
|
-
}, []);
|
|
1232
|
-
const base = useWebSocketChatBase({
|
|
1233
|
-
serverBaseUrl,
|
|
1234
|
-
orgId,
|
|
1235
|
-
clientType: "customer",
|
|
1236
|
-
onMessage: handleMessage,
|
|
1237
|
-
product
|
|
1238
|
-
});
|
|
1239
|
-
return {
|
|
1240
|
-
...base,
|
|
1241
|
-
chatKey,
|
|
1242
|
-
title: currentChat?.title,
|
|
1243
|
-
messages: currentChat?.messages ?? [],
|
|
1244
|
-
users: currentChat?.users ?? [],
|
|
1245
|
-
isWaiting: currentChat?.isWaiting ?? false,
|
|
1246
|
-
isWaitingForAgent: currentChat?.isWaitingForAgent ?? false,
|
|
1247
|
-
aiEngaged: currentChat?.aiEngaged ?? false,
|
|
1248
|
-
humanAgentEngaged: currentChat?.humanAgentEngaged ?? false,
|
|
1249
|
-
metadata: currentChat?.metadata ?? {},
|
|
1250
|
-
status: currentChat?.status
|
|
1251
|
-
};
|
|
1252
|
-
};
|
|
1253
|
-
|
|
1254
|
-
// context/websocket-chat-admin-context.tsx
|
|
1255
390
|
import { jsx } from "react/jsx-runtime";
|
|
1256
391
|
var WebSocketChatAdminContext = createContext(void 0);
|
|
1257
392
|
function WebSocketChatAdminProvider(props) {
|
|
@@ -1281,10 +416,10 @@ var AdminChatInput = ({
|
|
|
1281
416
|
}) => {
|
|
1282
417
|
const { sendMessage } = useWebSocketChatAdminContext();
|
|
1283
418
|
const { user, selectedOrgId } = useUserContext();
|
|
1284
|
-
const [input, setInput] =
|
|
1285
|
-
const [isUploading, setIsUploading] =
|
|
1286
|
-
const [isSending, setIsSending] =
|
|
1287
|
-
const fileInputRef =
|
|
419
|
+
const [input, setInput] = useState("");
|
|
420
|
+
const [isUploading, setIsUploading] = useState(false);
|
|
421
|
+
const [isSending, setIsSending] = useState(false);
|
|
422
|
+
const fileInputRef = useRef(null);
|
|
1288
423
|
const MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
1289
424
|
const handleSend = async () => {
|
|
1290
425
|
if (!input.trim() && !isUploading || isSending) return;
|
|
@@ -1664,15 +799,15 @@ var ChatHeader = () => {
|
|
|
1664
799
|
// components/customer/chat-input.tsx
|
|
1665
800
|
import { useUserContext as useUserContext3 } from "@elqnt/auth";
|
|
1666
801
|
import KSUID2 from "ksuid";
|
|
1667
|
-
import { useRef as
|
|
802
|
+
import { useRef as useRef2, useState as useState2 } from "react";
|
|
1668
803
|
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1669
804
|
var ChatInput = ({ onFileUpload }) => {
|
|
1670
805
|
const { sendMessage, chatKey } = useWebSocketChatCustomerContext();
|
|
1671
806
|
const { user, selectedOrgId } = useUserContext3();
|
|
1672
|
-
const [input, setInput] =
|
|
1673
|
-
const [isUploading, setIsUploading] =
|
|
1674
|
-
const [isSending, setIsSending] =
|
|
1675
|
-
const fileInputRef =
|
|
807
|
+
const [input, setInput] = useState2("");
|
|
808
|
+
const [isUploading, setIsUploading] = useState2(false);
|
|
809
|
+
const [isSending, setIsSending] = useState2(false);
|
|
810
|
+
const fileInputRef = useRef2(null);
|
|
1676
811
|
const MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
1677
812
|
const handleSend = async () => {
|
|
1678
813
|
if (!input.trim() && !isUploading || isSending) return;
|
|
@@ -1797,7 +932,7 @@ var ChatInput = ({ onFileUpload }) => {
|
|
|
1797
932
|
};
|
|
1798
933
|
|
|
1799
934
|
// components/customer/chat-messages.tsx
|
|
1800
|
-
import { useEffect
|
|
935
|
+
import { useEffect, useRef as useRef3 } from "react";
|
|
1801
936
|
|
|
1802
937
|
// ../../node_modules/date-fns/constants.js
|
|
1803
938
|
var daysInYear = 365.2425;
|
|
@@ -3494,11 +2629,11 @@ var ChatMessages = ({
|
|
|
3494
2629
|
onRetry,
|
|
3495
2630
|
messages
|
|
3496
2631
|
}) => {
|
|
3497
|
-
const messageEndRef =
|
|
2632
|
+
const messageEndRef = useRef3(null);
|
|
3498
2633
|
const scrollToBottom = () => {
|
|
3499
2634
|
messageEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
3500
2635
|
};
|
|
3501
|
-
|
|
2636
|
+
useEffect(() => {
|
|
3502
2637
|
scrollToBottom();
|
|
3503
2638
|
}, [messages]);
|
|
3504
2639
|
return /* @__PURE__ */ jsxs9(
|
|
@@ -3542,12 +2677,12 @@ var ChatTypingIndicator = ({
|
|
|
3542
2677
|
|
|
3543
2678
|
// components/customer/generic-chat-widget.tsx
|
|
3544
2679
|
import { Alert } from "@elqnt/react";
|
|
3545
|
-
import { useState as
|
|
2680
|
+
import { useState as useState3 } from "react";
|
|
3546
2681
|
import { jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
3547
2682
|
var GenericChatWidget = ({
|
|
3548
2683
|
onFileUpload
|
|
3549
2684
|
}) => {
|
|
3550
|
-
const [typingUsers] =
|
|
2685
|
+
const [typingUsers] = useState3(/* @__PURE__ */ new Set());
|
|
3551
2686
|
const { error, messages } = useWebSocketChatCustomerContext();
|
|
3552
2687
|
const handleRetry = (messageId) => {
|
|
3553
2688
|
};
|