@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/hooks/index.d.mts
CHANGED
|
@@ -50,8 +50,8 @@ interface UseChatReturn {
|
|
|
50
50
|
startChat: (metadata?: Record<string, unknown>) => Promise<string>;
|
|
51
51
|
/** Load an existing chat, returns the loaded chat */
|
|
52
52
|
loadChat: (chatKey: string) => Promise<Chat>;
|
|
53
|
-
/** Send a text message */
|
|
54
|
-
sendMessage: (content: string, attachments?: unknown[]) => Promise<void>;
|
|
53
|
+
/** Send a text message. Optional `data` is forwarded to the backend (e.g. { saveAttachments: true }). */
|
|
54
|
+
sendMessage: (content: string, attachments?: unknown[], data?: Record<string, unknown>) => Promise<void>;
|
|
55
55
|
/** Send a raw chat event (for custom event types) */
|
|
56
56
|
sendEvent: (event: Omit<ChatEvent, "timestamp">) => Promise<void>;
|
|
57
57
|
/** End the current chat */
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -50,8 +50,8 @@ interface UseChatReturn {
|
|
|
50
50
|
startChat: (metadata?: Record<string, unknown>) => Promise<string>;
|
|
51
51
|
/** Load an existing chat, returns the loaded chat */
|
|
52
52
|
loadChat: (chatKey: string) => Promise<Chat>;
|
|
53
|
-
/** Send a text message */
|
|
54
|
-
sendMessage: (content: string, attachments?: unknown[]) => Promise<void>;
|
|
53
|
+
/** Send a text message. Optional `data` is forwarded to the backend (e.g. { saveAttachments: true }). */
|
|
54
|
+
sendMessage: (content: string, attachments?: unknown[], data?: Record<string, unknown>) => Promise<void>;
|
|
55
55
|
/** Send a raw chat event (for custom event types) */
|
|
56
56
|
sendEvent: (event: Omit<ChatEvent, "timestamp">) => Promise<void>;
|
|
57
57
|
/** End the current chat */
|
package/dist/hooks/index.js
CHANGED
|
@@ -143,6 +143,7 @@ function createSSETransport(options = {}) {
|
|
|
143
143
|
function setupEventListeners(es) {
|
|
144
144
|
es.addEventListener("message", handleMessage);
|
|
145
145
|
const eventTypes = [
|
|
146
|
+
"error",
|
|
146
147
|
"reconnected",
|
|
147
148
|
"typing",
|
|
148
149
|
"stopped_typing",
|
|
@@ -152,21 +153,53 @@ function createSSETransport(options = {}) {
|
|
|
152
153
|
"human_agent_left",
|
|
153
154
|
"chat_ended",
|
|
154
155
|
"chat_updated",
|
|
156
|
+
"chat_removed",
|
|
155
157
|
"load_chat_response",
|
|
156
158
|
"new_chat_created",
|
|
157
159
|
"show_csat_survey",
|
|
158
160
|
"csat_response",
|
|
159
161
|
"user_suggested_actions",
|
|
162
|
+
"user_suggested_action_selected",
|
|
160
163
|
"agent_execution_started",
|
|
161
164
|
"agent_execution_ended",
|
|
162
165
|
"agent_context_update",
|
|
166
|
+
"load_agent_context_response",
|
|
163
167
|
"plan_pending_approval",
|
|
168
|
+
"plan_approved",
|
|
169
|
+
"plan_rejected",
|
|
164
170
|
"step_started",
|
|
165
171
|
"step_completed",
|
|
166
172
|
"step_failed",
|
|
167
173
|
"plan_completed",
|
|
168
174
|
"skills_changed",
|
|
169
|
-
"summary_update"
|
|
175
|
+
"summary_update",
|
|
176
|
+
"message_status_update",
|
|
177
|
+
"delivered",
|
|
178
|
+
"read",
|
|
179
|
+
"sync_metadata_response",
|
|
180
|
+
"sync_user_session_response",
|
|
181
|
+
"client_action",
|
|
182
|
+
"client_action_callback",
|
|
183
|
+
"attachment_processing_started",
|
|
184
|
+
"attachment_processing_progress",
|
|
185
|
+
"attachment_processing_complete",
|
|
186
|
+
"attachment_processing_error",
|
|
187
|
+
"observer_joined",
|
|
188
|
+
"observer_left",
|
|
189
|
+
"block_user",
|
|
190
|
+
"message_edited",
|
|
191
|
+
"message_deleted",
|
|
192
|
+
"message_reaction",
|
|
193
|
+
"user_presence_changed",
|
|
194
|
+
"online_users",
|
|
195
|
+
"get_agents_response",
|
|
196
|
+
"room_created",
|
|
197
|
+
"room_updated",
|
|
198
|
+
"room_deleted",
|
|
199
|
+
"rooms_response",
|
|
200
|
+
"room_user_joined",
|
|
201
|
+
"room_user_left",
|
|
202
|
+
"user_invited"
|
|
170
203
|
];
|
|
171
204
|
eventTypes.forEach((type) => {
|
|
172
205
|
es.addEventListener(type, handleMessage);
|
|
@@ -213,18 +246,34 @@ function createSSETransport(options = {}) {
|
|
|
213
246
|
state = retryCount > 0 ? "reconnecting" : "connecting";
|
|
214
247
|
return new Promise((resolve, reject) => {
|
|
215
248
|
const connectionStart = Date.now();
|
|
216
|
-
const
|
|
249
|
+
const streamParams = new URLSearchParams({
|
|
250
|
+
orgId: cfg.orgId,
|
|
251
|
+
userId: cfg.userId,
|
|
252
|
+
clientType: cfg.clientType
|
|
253
|
+
});
|
|
254
|
+
if (cfg.chatKey) streamParams.set("chatId", cfg.chatKey);
|
|
255
|
+
const url = `${cfg.baseUrl}/stream?${streamParams.toString()}`;
|
|
217
256
|
logger.debug("Connecting to:", url);
|
|
218
257
|
const es = new EventSource(url);
|
|
219
258
|
es.onopen = () => {
|
|
220
259
|
const connectionTime = Date.now() - connectionStart;
|
|
221
260
|
logger.info(`Connected in ${connectionTime}ms`);
|
|
261
|
+
const wasReconnect = retryCount > 0;
|
|
222
262
|
state = "connected";
|
|
223
263
|
error = void 0;
|
|
224
264
|
retryCount = 0;
|
|
225
265
|
metrics.connectedAt = Date.now();
|
|
226
266
|
metrics.latency = connectionTime;
|
|
227
267
|
setupEventListeners(es);
|
|
268
|
+
if (wasReconnect) {
|
|
269
|
+
emit({
|
|
270
|
+
type: "transport_reconnected",
|
|
271
|
+
orgId: cfg.orgId,
|
|
272
|
+
chatKey: cfg.chatKey || "",
|
|
273
|
+
userId: cfg.userId,
|
|
274
|
+
timestamp: Date.now()
|
|
275
|
+
});
|
|
276
|
+
}
|
|
228
277
|
resolve();
|
|
229
278
|
};
|
|
230
279
|
es.onerror = () => {
|
|
@@ -495,7 +544,13 @@ function createFetchSSETransport(options = {}) {
|
|
|
495
544
|
return events;
|
|
496
545
|
}
|
|
497
546
|
async function startStream(cfg) {
|
|
498
|
-
const
|
|
547
|
+
const streamParams = new URLSearchParams({
|
|
548
|
+
orgId: cfg.orgId,
|
|
549
|
+
userId: cfg.userId,
|
|
550
|
+
clientType: cfg.clientType
|
|
551
|
+
});
|
|
552
|
+
if (cfg.chatKey) streamParams.set("chatId", cfg.chatKey);
|
|
553
|
+
const url = `${cfg.baseUrl}/stream?${streamParams.toString()}`;
|
|
499
554
|
logger.debug("Connecting to:", url);
|
|
500
555
|
abortController = new AbortController();
|
|
501
556
|
const response = await customFetch(url, {
|
|
@@ -601,6 +656,7 @@ function createFetchSSETransport(options = {}) {
|
|
|
601
656
|
state = retryCount > 0 ? "reconnecting" : "connecting";
|
|
602
657
|
const connectionStart = Date.now();
|
|
603
658
|
try {
|
|
659
|
+
const wasReconnect = retryCount > 0;
|
|
604
660
|
await startStream(cfg);
|
|
605
661
|
const connectionTime = Date.now() - connectionStart;
|
|
606
662
|
logger.info(`Connected in ${connectionTime}ms`);
|
|
@@ -609,6 +665,15 @@ function createFetchSSETransport(options = {}) {
|
|
|
609
665
|
retryCount = 0;
|
|
610
666
|
metrics.connectedAt = Date.now();
|
|
611
667
|
metrics.latency = connectionTime;
|
|
668
|
+
if (wasReconnect) {
|
|
669
|
+
emit({
|
|
670
|
+
type: "transport_reconnected",
|
|
671
|
+
orgId: cfg.orgId,
|
|
672
|
+
chatKey: cfg.chatKey || "",
|
|
673
|
+
userId: cfg.userId,
|
|
674
|
+
timestamp: Date.now()
|
|
675
|
+
});
|
|
676
|
+
}
|
|
612
677
|
} catch (err) {
|
|
613
678
|
const connectError = {
|
|
614
679
|
code: "CONNECTION_FAILED",
|
|
@@ -650,7 +715,8 @@ function createFetchSSETransport(options = {}) {
|
|
|
650
715
|
orgId: event.orgId,
|
|
651
716
|
chatKey: event.chatKey,
|
|
652
717
|
userId: event.userId,
|
|
653
|
-
message: event.message
|
|
718
|
+
message: event.message,
|
|
719
|
+
...event.data ? { data: event.data } : {}
|
|
654
720
|
});
|
|
655
721
|
break;
|
|
656
722
|
case "typing":
|
|
@@ -970,7 +1036,7 @@ function useChat(options) {
|
|
|
970
1036
|
[orgId, userId]
|
|
971
1037
|
);
|
|
972
1038
|
const sendMessage = (0, import_react.useCallback)(
|
|
973
|
-
async (content, attachments) => {
|
|
1039
|
+
async (content, attachments, data) => {
|
|
974
1040
|
const transport = transportRef.current;
|
|
975
1041
|
if (!transport) {
|
|
976
1042
|
throw new Error("Transport not initialized");
|
|
@@ -995,7 +1061,8 @@ function useChat(options) {
|
|
|
995
1061
|
chatKey,
|
|
996
1062
|
userId,
|
|
997
1063
|
timestamp: Date.now(),
|
|
998
|
-
message
|
|
1064
|
+
message,
|
|
1065
|
+
...data ? { data } : {}
|
|
999
1066
|
});
|
|
1000
1067
|
setMetrics((prev) => ({
|
|
1001
1068
|
...prev,
|