@opencx/widget 2.4.4-rn.1 → 2.4.4-rn.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/basic.cjs +31 -31
- package/dist/basic.cjs.map +1 -1
- package/dist/basic.js +37 -38
- package/dist/basic.js.map +1 -1
- package/dist/core/client/api.d.ts +6 -15
- package/dist/core/client/chat.d.ts +10 -10
- package/dist/core/client/contact.d.ts +2 -2
- package/dist/core/types/helpers.d.ts +1 -1
- package/dist/core/types/index.d.ts +2 -3
- package/dist/core/types/schemas-v2.d.ts +92 -91
- package/dist/core/types/schemas.d.ts +123 -69
- package/dist/{index-ENMg5VOh.js → index-B-VyJuQ9.js} +964 -864
- package/dist/index-B-VyJuQ9.js.map +1 -0
- package/dist/index-D2PGs8oF.cjs +18 -0
- package/dist/index-D2PGs8oF.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +189 -189
- package/dist/index.js.map +1 -1
- package/dist/package.json.d.ts +1 -1
- package/dist/react-web/hooks/useAbstractChat.d.ts +22 -21
- package/dist/react-web/hooks/useAxiosInstance.d.ts +35 -23
- package/dist/react-web/hooks/useUploadFiles.d.ts +1 -1
- package/dist/react-web/providers/ChatProvider.d.ts +24 -24
- package/dist/react-web/providers/ContactProvider.d.ts +4 -4
- package/dist/react.cjs +1 -1
- package/dist/react.js +1 -1
- package/dist/schemas-v2-BiJWHypc.cjs +2 -0
- package/dist/schemas-v2-BiJWHypc.cjs.map +1 -0
- package/dist/schemas-v2-DZ3nwfID.js +138 -0
- package/dist/schemas-v2-DZ3nwfID.js.map +1 -0
- package/dist/src/components/RenderFile.d.ts +1 -1
- package/dist/src/components/dialog.d.ts +2 -2
- package/dist-embed/script.js +107 -107
- package/dist-embed/script.js.map +1 -1
- package/package.json +1 -1
- package/dist/index-Bx4hrNc7.cjs +0 -18
- package/dist/index-Bx4hrNc7.cjs.map +0 -1
- package/dist/index-ENMg5VOh.js.map +0 -1
- package/dist/schemas-BBAV6Sd_.js +0 -122
- package/dist/schemas-BBAV6Sd_.js.map +0 -1
- package/dist/schemas-wky4fpbc.cjs +0 -2
- package/dist/schemas-wky4fpbc.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var j = Object.defineProperty;
|
|
2
|
+
var D = (t) => {
|
|
3
3
|
throw TypeError(t);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var S = (t, e, s) =>
|
|
7
|
-
var h = (t, e, s) => (
|
|
8
|
-
import
|
|
9
|
-
import { g as
|
|
10
|
-
import {
|
|
11
|
-
var
|
|
5
|
+
var B = (t, e, s) => e in t ? j(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
|
|
6
|
+
var S = (t, e, s) => B(t, typeof e != "symbol" ? e + "" : e, s), R = (t, e, s) => e.has(t) || D("Cannot " + s);
|
|
7
|
+
var h = (t, e, s) => (R(t, e, "read from private field"), s ? s.call(t) : e.get(t)), M = (t, e, s) => e.has(t) ? D("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, s), _ = (t, e, s, o) => (R(t, e, "write to private field"), o ? o.call(t, s) : e.set(t, s), s);
|
|
8
|
+
import H from "lodash.isequal";
|
|
9
|
+
import { g as O } from "./schemas-v2-DZ3nwfID.js";
|
|
10
|
+
import { M as me, c as ge } from "./schemas-v2-DZ3nwfID.js";
|
|
11
|
+
var G = /* @__PURE__ */ ((t) => (t.INIT = "init", t.STATE_CHANGE = "stateChange", t.BEFORE_UPDATE = "beforeUpdate", t.AFTER_UPDATE = "afterUpdate", t.DESTROY = "destroy", t.ERROR = "error", t))(G || {}), y, P;
|
|
12
12
|
class C {
|
|
13
13
|
constructor(e) {
|
|
14
14
|
S(this, "subscribers", /* @__PURE__ */ new Set());
|
|
15
15
|
M(this, y);
|
|
16
16
|
S(this, "initialState");
|
|
17
|
-
M(this,
|
|
17
|
+
M(this, P);
|
|
18
18
|
S(this, "lifecycleListeners", /* @__PURE__ */ new Map());
|
|
19
19
|
S(this, "emitLifecycle", (e, s) => {
|
|
20
20
|
const o = this.lifecycleListeners.get(e);
|
|
21
21
|
if (o) {
|
|
22
|
-
const
|
|
22
|
+
const f = {
|
|
23
23
|
type: e,
|
|
24
24
|
timestamp: Date.now(),
|
|
25
25
|
data: s
|
|
26
26
|
};
|
|
27
|
-
o.forEach((n) => n(
|
|
27
|
+
o.forEach((n) => n(f));
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
/**
|
|
@@ -54,7 +54,7 @@ class C {
|
|
|
54
54
|
this.emitLifecycle("beforeUpdate", {
|
|
55
55
|
previousState: h(this, y),
|
|
56
56
|
nextState: e
|
|
57
|
-
}),
|
|
57
|
+
}), H(h(this, y), e) || (_(this, y, e), _(this, P, Date.now()), this.emitLifecycle("stateChange", { state: e }), this.subscribers.forEach((s) => {
|
|
58
58
|
try {
|
|
59
59
|
s(e);
|
|
60
60
|
} catch (o) {
|
|
@@ -78,12 +78,12 @@ class C {
|
|
|
78
78
|
S(this, "reset", () => {
|
|
79
79
|
this.setState(this.initialState);
|
|
80
80
|
});
|
|
81
|
-
S(this, "lastUpdated", () => h(this,
|
|
82
|
-
|
|
81
|
+
S(this, "lastUpdated", () => h(this, P));
|
|
82
|
+
_(this, y, e), this.initialState = e, _(this, P, Date.now()), this.emitLifecycle("init", { initialState: h(this, y) });
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
y = new WeakMap(),
|
|
86
|
-
function
|
|
85
|
+
y = new WeakMap(), P = new WeakMap();
|
|
86
|
+
function ee(t) {
|
|
87
87
|
return new C(t);
|
|
88
88
|
}
|
|
89
89
|
class v extends Error {
|
|
@@ -91,37 +91,37 @@ class v extends Error {
|
|
|
91
91
|
super(e), this.name = "OpenCXError";
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
class
|
|
94
|
+
class te extends v {
|
|
95
95
|
constructor(e = "Connection failed") {
|
|
96
96
|
super(e), this.name = "ConnectionError";
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
class
|
|
99
|
+
class se extends v {
|
|
100
100
|
constructor(e = "Authentication failed") {
|
|
101
101
|
super(e), this.name = "AuthenticationError";
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
class
|
|
104
|
+
class J extends v {
|
|
105
105
|
constructor(e = "Session error occurred") {
|
|
106
106
|
super(e), this.name = "SessionError";
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
class
|
|
109
|
+
class re extends J {
|
|
110
110
|
constructor(e = "Session not defined") {
|
|
111
111
|
super(e), this.name = "SessionNotDefinedError";
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
class
|
|
114
|
+
class ae extends v {
|
|
115
115
|
constructor(e = "Transport error occurred") {
|
|
116
116
|
super(e), this.name = "TransportError";
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
class
|
|
119
|
+
class ne extends v {
|
|
120
120
|
constructor(e = "File upload failed") {
|
|
121
121
|
super(e), this.name = "FileUploadError";
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
function
|
|
124
|
+
function L(t) {
|
|
125
125
|
if (!t) return !1;
|
|
126
126
|
try {
|
|
127
127
|
return typeof t.isAvailable == "function" ? t.isAvailable() : !0;
|
|
@@ -129,7 +129,7 @@ function T(t) {
|
|
|
129
129
|
return !1;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
async function
|
|
132
|
+
async function A(t, e) {
|
|
133
133
|
try {
|
|
134
134
|
return { success: !0, result: await t() };
|
|
135
135
|
} catch (s) {
|
|
@@ -139,15 +139,15 @@ async function O(t, e) {
|
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
const
|
|
142
|
+
const k = {
|
|
143
143
|
SESSION: 1e4,
|
|
144
144
|
// every 10 seconds
|
|
145
145
|
MESSAGES: 5e3
|
|
146
146
|
// every 5 seconds
|
|
147
147
|
};
|
|
148
|
-
function
|
|
148
|
+
function $(t) {
|
|
149
149
|
const e = {
|
|
150
|
-
id: t.publicId ||
|
|
150
|
+
id: t.publicId || O(),
|
|
151
151
|
timestamp: t.sentAt || "",
|
|
152
152
|
attachments: t.attachments || void 0
|
|
153
153
|
};
|
|
@@ -171,44 +171,44 @@ function k(t) {
|
|
|
171
171
|
}
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function X(t, e, s) {
|
|
175
175
|
async function o(i) {
|
|
176
|
-
const
|
|
177
|
-
if (
|
|
176
|
+
const l = e.getState().messages;
|
|
177
|
+
if (l.length === 0) {
|
|
178
178
|
s == null || s.debug("No messages yet, fetching all history", { sessionId: i.id });
|
|
179
179
|
const g = await t.getSessionHistory(i.id, "");
|
|
180
180
|
g && g.length > 0 && e.setStatePartial({
|
|
181
|
-
messages: g.map(
|
|
181
|
+
messages: g.map($)
|
|
182
182
|
});
|
|
183
183
|
return;
|
|
184
184
|
}
|
|
185
|
-
const
|
|
185
|
+
const c = l[l.length - 1], r = new Date(c.timestamp);
|
|
186
186
|
r.setSeconds(r.getSeconds() + 1);
|
|
187
187
|
const u = r.toISOString();
|
|
188
188
|
s == null || s.debug("Fetching history messages after timestamp", {
|
|
189
189
|
sessionId: i.id,
|
|
190
190
|
lastMessageTimestamp: u,
|
|
191
|
-
currentMessageCount:
|
|
191
|
+
currentMessageCount: l.length
|
|
192
192
|
});
|
|
193
193
|
const E = await t.getSessionHistory(i.id, u);
|
|
194
194
|
if (E && E.length > 0) {
|
|
195
|
-
const g = E.map(
|
|
195
|
+
const g = E.map($).filter((p) => !l.some((I) => I.id === p.id));
|
|
196
196
|
g.length > 0 && (s == null || s.debug("Adding new messages to state", {
|
|
197
197
|
count: g.length,
|
|
198
198
|
messageIds: g.map((p) => p.id),
|
|
199
199
|
messageTypes: g.map((p) => p.type)
|
|
200
200
|
}), e.setStatePartial({
|
|
201
|
-
messages: [...
|
|
201
|
+
messages: [...l, ...g]
|
|
202
202
|
}));
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function f(i, l) {
|
|
206
206
|
return {
|
|
207
|
-
id:
|
|
207
|
+
id: O(),
|
|
208
208
|
type: "FROM_USER",
|
|
209
209
|
content: i,
|
|
210
210
|
deliveredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
211
|
-
attachments:
|
|
211
|
+
attachments: l,
|
|
212
212
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
213
213
|
};
|
|
214
214
|
}
|
|
@@ -216,7 +216,7 @@ function J(t, e, s) {
|
|
|
216
216
|
if (i.success && i.autopilotResponse)
|
|
217
217
|
return {
|
|
218
218
|
type: "FROM_BOT",
|
|
219
|
-
id: i.autopilotResponse.id ||
|
|
219
|
+
id: i.autopilotResponse.id || O(),
|
|
220
220
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
221
221
|
component: "TEXT",
|
|
222
222
|
data: {
|
|
@@ -224,13 +224,13 @@ function J(t, e, s) {
|
|
|
224
224
|
}
|
|
225
225
|
};
|
|
226
226
|
if (i.success && i.uiResponse) {
|
|
227
|
-
const
|
|
227
|
+
const l = i.uiResponse.value;
|
|
228
228
|
return {
|
|
229
229
|
type: "FROM_BOT",
|
|
230
|
-
id:
|
|
230
|
+
id: O(),
|
|
231
231
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
232
|
-
component:
|
|
233
|
-
data:
|
|
232
|
+
component: l.name,
|
|
233
|
+
data: l.request_response
|
|
234
234
|
};
|
|
235
235
|
}
|
|
236
236
|
return null;
|
|
@@ -238,7 +238,7 @@ function J(t, e, s) {
|
|
|
238
238
|
function a(i) {
|
|
239
239
|
return {
|
|
240
240
|
type: "FROM_BOT",
|
|
241
|
-
id:
|
|
241
|
+
id: O(),
|
|
242
242
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
243
243
|
component: "TEXT",
|
|
244
244
|
data: {
|
|
@@ -249,33 +249,33 @@ function J(t, e, s) {
|
|
|
249
249
|
}
|
|
250
250
|
return {
|
|
251
251
|
fetchHistoryMessages: o,
|
|
252
|
-
addUserMessage:
|
|
252
|
+
addUserMessage: f,
|
|
253
253
|
addBotMessage: n,
|
|
254
254
|
addErrorMessage: a
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
|
-
function
|
|
258
|
-
var
|
|
259
|
-
const a = (
|
|
257
|
+
function z(t, e, s, o, f, n) {
|
|
258
|
+
var U, N;
|
|
259
|
+
const a = (U = n.platform) == null ? void 0 : U.logger;
|
|
260
260
|
let i = null;
|
|
261
|
-
const
|
|
261
|
+
const l = (N = n.platform) == null ? void 0 : N.storage, c = `${f.getConfig().user.external_id}:${f.getConfig().token}:session`, r = n.config.getSettings().persistSession;
|
|
262
262
|
async function u() {
|
|
263
|
-
if (
|
|
263
|
+
if (l)
|
|
264
264
|
try {
|
|
265
265
|
a == null || a.debug("Attempting to restore session from storage");
|
|
266
|
-
const
|
|
267
|
-
if (
|
|
268
|
-
const m = JSON.parse(
|
|
266
|
+
const d = await l.getItem(c);
|
|
267
|
+
if (d) {
|
|
268
|
+
const m = JSON.parse(d);
|
|
269
269
|
a == null || a.info("Session restored from storage", { sessionId: m.id }), e.setState(m), await o.fetchHistoryMessages(m), g();
|
|
270
270
|
}
|
|
271
|
-
} catch (
|
|
272
|
-
a == null || a.error("Error restoring session from storage:",
|
|
271
|
+
} catch (d) {
|
|
272
|
+
a == null || a.error("Error restoring session from storage:", d);
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
function E() {
|
|
276
|
-
|
|
276
|
+
l && (a == null || a.debug("Setting up session persistence"), e.subscribe(async (d) => {
|
|
277
277
|
try {
|
|
278
|
-
|
|
278
|
+
d ? (await l.setItem(c, JSON.stringify(d)), a == null || a.debug("Session persisted to storage", { sessionId: d.id })) : (await l.removeItem(c), a == null || a.debug("Session removed from storage"));
|
|
279
279
|
} catch (m) {
|
|
280
280
|
a == null || a.error("Error persisting session:", m), s.setStatePartial({
|
|
281
281
|
error: {
|
|
@@ -290,8 +290,8 @@ function G(t, e, s, o, d, n) {
|
|
|
290
290
|
function g() {
|
|
291
291
|
if (i) return;
|
|
292
292
|
a == null || a.debug("Starting polling");
|
|
293
|
-
const
|
|
294
|
-
|
|
293
|
+
const d = [];
|
|
294
|
+
d.push(
|
|
295
295
|
setInterval(async () => {
|
|
296
296
|
const m = e.getState();
|
|
297
297
|
if (m != null && m.id)
|
|
@@ -301,8 +301,8 @@ function G(t, e, s, o, d, n) {
|
|
|
301
301
|
} catch (w) {
|
|
302
302
|
a == null || a.error("Error polling session:", w);
|
|
303
303
|
}
|
|
304
|
-
},
|
|
305
|
-
),
|
|
304
|
+
}, k.SESSION)
|
|
305
|
+
), d.push(
|
|
306
306
|
setInterval(async () => {
|
|
307
307
|
const m = e.getState();
|
|
308
308
|
if (m != null && m.id)
|
|
@@ -311,9 +311,9 @@ function G(t, e, s, o, d, n) {
|
|
|
311
311
|
} catch (w) {
|
|
312
312
|
a == null || a.error("Error polling messages:", w);
|
|
313
313
|
}
|
|
314
|
-
},
|
|
314
|
+
}, k.MESSAGES)
|
|
315
315
|
), i = () => {
|
|
316
|
-
a == null || a.debug("Stopping polling"),
|
|
316
|
+
a == null || a.debug("Stopping polling"), d.forEach(clearInterval);
|
|
317
317
|
};
|
|
318
318
|
}
|
|
319
319
|
async function p() {
|
|
@@ -322,13 +322,13 @@ function G(t, e, s, o, d, n) {
|
|
|
322
322
|
loading: { isLoading: !0, reason: "creating_session" },
|
|
323
323
|
error: { hasError: !1 }
|
|
324
324
|
});
|
|
325
|
-
const
|
|
326
|
-
return a == null || a.info("Session created successfully", { sessionId:
|
|
327
|
-
} catch (
|
|
328
|
-
a == null || a.error("Failed to create session:",
|
|
325
|
+
const d = await t.createSession();
|
|
326
|
+
return a == null || a.info("Session created successfully", { sessionId: d.id }), e.setState(d), g(), d;
|
|
327
|
+
} catch (d) {
|
|
328
|
+
a == null || a.error("Failed to create session:", d);
|
|
329
329
|
const m = {
|
|
330
330
|
hasError: !0,
|
|
331
|
-
message:
|
|
331
|
+
message: d instanceof Error ? d.message : "Failed to create session",
|
|
332
332
|
code: "SESSION_CREATION_FAILED"
|
|
333
333
|
};
|
|
334
334
|
return s.setStatePartial({ error: m }), null;
|
|
@@ -340,10 +340,10 @@ function G(t, e, s, o, d, n) {
|
|
|
340
340
|
}
|
|
341
341
|
async function I() {
|
|
342
342
|
var m;
|
|
343
|
-
const
|
|
344
|
-
if (
|
|
343
|
+
const d = e.getState();
|
|
344
|
+
if (d != null && d.id)
|
|
345
345
|
try {
|
|
346
|
-
i && (i(), i = null), e.setState(null), r &&
|
|
346
|
+
i && (i(), i = null), e.setState(null), r && l && L(l) && l.removeItem(c), s.setState({
|
|
347
347
|
messages: [],
|
|
348
348
|
keyboard: null,
|
|
349
349
|
loading: { isLoading: !1 },
|
|
@@ -359,32 +359,43 @@ function G(t, e, s, o, d, n) {
|
|
|
359
359
|
});
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
|
-
function
|
|
362
|
+
function T() {
|
|
363
363
|
try {
|
|
364
|
-
i && (i(), i = null), r &&
|
|
364
|
+
i && (i(), i = null), r && l && L(l) && l.removeItem(c), s.setState({
|
|
365
365
|
messages: [],
|
|
366
366
|
keyboard: null,
|
|
367
367
|
loading: { isLoading: !1 },
|
|
368
368
|
error: { hasError: !1 }
|
|
369
369
|
}), e.setState(null), s.clear(), e.clear();
|
|
370
|
-
} catch (
|
|
371
|
-
console.error("Error in cleanup:",
|
|
370
|
+
} catch (d) {
|
|
371
|
+
console.error("Error in cleanup:", d), s.setStatePartial({
|
|
372
372
|
error: {
|
|
373
373
|
hasError: !0,
|
|
374
|
-
message:
|
|
374
|
+
message: d instanceof Error ? d.message : "Failed to cleanup",
|
|
375
375
|
code: "SESSION_CLEAR_FAILED"
|
|
376
376
|
}
|
|
377
377
|
});
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
|
-
|
|
380
|
+
async function F(d) {
|
|
381
|
+
return t.getSession(d);
|
|
382
|
+
}
|
|
383
|
+
async function q() {
|
|
384
|
+
const d = e.getState();
|
|
385
|
+
if (!(d != null && d.id)) return;
|
|
386
|
+
const m = await F(d.id);
|
|
387
|
+
return m && e.setState(m), m;
|
|
388
|
+
}
|
|
389
|
+
return r && L(l) && (u(), E()), {
|
|
381
390
|
createSession: p,
|
|
382
391
|
clearSession: I,
|
|
383
|
-
cleanup:
|
|
384
|
-
startPolling: g
|
|
392
|
+
cleanup: T,
|
|
393
|
+
startPolling: g,
|
|
394
|
+
fetchSession: F,
|
|
395
|
+
refetchSession: q
|
|
385
396
|
};
|
|
386
397
|
}
|
|
387
|
-
function
|
|
398
|
+
function oe(t) {
|
|
388
399
|
var i;
|
|
389
400
|
const e = (i = t.platform) == null ? void 0 : i.logger;
|
|
390
401
|
e == null || e.info("Initializing chat");
|
|
@@ -393,25 +404,29 @@ function ae(t) {
|
|
|
393
404
|
keyboard: null,
|
|
394
405
|
loading: { isLoading: !1 },
|
|
395
406
|
error: { hasError: !1 }
|
|
396
|
-
}), o = new C(null),
|
|
407
|
+
}), o = new C(null), f = X(t.api, s, e), n = z(
|
|
397
408
|
t.api,
|
|
398
409
|
o,
|
|
399
410
|
s,
|
|
400
|
-
|
|
411
|
+
f,
|
|
401
412
|
t.config,
|
|
402
413
|
t
|
|
403
414
|
);
|
|
404
|
-
async function a(
|
|
415
|
+
async function a(l) {
|
|
405
416
|
var r;
|
|
406
|
-
let
|
|
407
|
-
if (!(
|
|
417
|
+
let c = o.getState();
|
|
418
|
+
if (!(c != null && c.id) && (e == null || e.debug("No active session, creating new session"), c = await n.createSession(), !c))
|
|
408
419
|
return !1;
|
|
420
|
+
c.assignee.kind === "ai" && (c = await n.refetchSession() || c);
|
|
409
421
|
try {
|
|
410
|
-
e == null || e.debug("Sending message", { sessionId:
|
|
411
|
-
loading: { isLoading: !0, reason: "
|
|
422
|
+
e == null || e.debug("Sending message", { sessionId: c.id }), c.assignee.kind === "ai" ? s.setStatePartial({
|
|
423
|
+
loading: { isLoading: !0, reason: "sending_message_to_agent" },
|
|
424
|
+
error: { hasError: !1 }
|
|
425
|
+
}) : s.setStatePartial({
|
|
426
|
+
loading: { isLoading: !0, reason: "sending_message_to_bot" },
|
|
412
427
|
error: { hasError: !1 }
|
|
413
428
|
});
|
|
414
|
-
const u =
|
|
429
|
+
const u = f.addUserMessage(l.content, l.attachments || void 0), E = s.getState().messages;
|
|
415
430
|
s.setStatePartial({
|
|
416
431
|
messages: [...E, u]
|
|
417
432
|
});
|
|
@@ -419,23 +434,23 @@ function ae(t) {
|
|
|
419
434
|
bot_token: g.token,
|
|
420
435
|
headers: g.headers,
|
|
421
436
|
query_params: g.queryParams,
|
|
422
|
-
session_id:
|
|
423
|
-
...
|
|
437
|
+
session_id: c.id,
|
|
438
|
+
...l
|
|
424
439
|
});
|
|
425
440
|
if (p.success) {
|
|
426
441
|
e == null || e.debug("Message sent successfully");
|
|
427
|
-
const I =
|
|
442
|
+
const I = f.addBotMessage(p);
|
|
428
443
|
if (I) {
|
|
429
|
-
const
|
|
444
|
+
const T = s.getState().messages;
|
|
430
445
|
s.setStatePartial({
|
|
431
|
-
messages: [...
|
|
446
|
+
messages: [...T, I]
|
|
432
447
|
});
|
|
433
448
|
}
|
|
434
449
|
} else {
|
|
435
450
|
e == null || e.warn("Message send failed", p.error);
|
|
436
|
-
const I =
|
|
451
|
+
const I = f.addErrorMessage(((r = p.error) == null ? void 0 : r.message) || "Unknown error occurred"), T = s.getState().messages;
|
|
437
452
|
s.setStatePartial({
|
|
438
|
-
messages: [...
|
|
453
|
+
messages: [...T, I]
|
|
439
454
|
});
|
|
440
455
|
}
|
|
441
456
|
return !0;
|
|
@@ -462,27 +477,27 @@ function ae(t) {
|
|
|
462
477
|
cleanup: n.cleanup
|
|
463
478
|
};
|
|
464
479
|
}
|
|
465
|
-
function
|
|
480
|
+
function ie(t) {
|
|
466
481
|
const e = t.config.getConfig();
|
|
467
482
|
t.config.getConfig;
|
|
468
|
-
const s = `${e.token}:contact:${e.user.external_id}`, o =
|
|
469
|
-
let
|
|
470
|
-
o &&
|
|
483
|
+
const s = `${e.token}:contact:${e.user.external_id}`, o = L(t.platform.storage) ? t.platform.storage : void 0;
|
|
484
|
+
let f = null;
|
|
485
|
+
o && A(
|
|
471
486
|
async () => {
|
|
472
487
|
const r = await o.getItem(s);
|
|
473
488
|
return r ? JSON.parse(r) : null;
|
|
474
489
|
},
|
|
475
490
|
"Error loading contact from storage"
|
|
476
491
|
).then((r) => {
|
|
477
|
-
r.success && (
|
|
492
|
+
r.success && (f = r.result);
|
|
478
493
|
});
|
|
479
494
|
const n = new C({
|
|
480
|
-
contact:
|
|
495
|
+
contact: f,
|
|
481
496
|
loading: { isLoading: !1 },
|
|
482
497
|
error: { hasError: !1 }
|
|
483
498
|
});
|
|
484
|
-
|
|
485
|
-
|
|
499
|
+
L(o) && n.subscribe((r) => {
|
|
500
|
+
A(
|
|
486
501
|
async () => {
|
|
487
502
|
r.contact ? await o.setItem(s, JSON.stringify(r.contact)) : o.removeItem(s);
|
|
488
503
|
},
|
|
@@ -503,7 +518,7 @@ function ne(t) {
|
|
|
503
518
|
loading: { isLoading: !0, reason: "loading_contact" },
|
|
504
519
|
error: { hasError: !1 }
|
|
505
520
|
}), o) {
|
|
506
|
-
const r = await
|
|
521
|
+
const r = await A(
|
|
507
522
|
async () => {
|
|
508
523
|
const u = await o.getItem(s);
|
|
509
524
|
return u ? JSON.parse(u) : null;
|
|
@@ -545,8 +560,8 @@ function ne(t) {
|
|
|
545
560
|
avatar_url: r.avatar_url ?? (u == null ? void 0 : u.avatar_url) ?? null,
|
|
546
561
|
email: r.email ?? (u == null ? void 0 : u.email) ?? null
|
|
547
562
|
};
|
|
548
|
-
if (
|
|
549
|
-
const g = await
|
|
563
|
+
if (L(o)) {
|
|
564
|
+
const g = await A(
|
|
550
565
|
() => o.setItem(s, JSON.stringify(E)),
|
|
551
566
|
"Error saving contact"
|
|
552
567
|
);
|
|
@@ -571,7 +586,7 @@ function ne(t) {
|
|
|
571
586
|
});
|
|
572
587
|
}
|
|
573
588
|
}
|
|
574
|
-
function
|
|
589
|
+
function l() {
|
|
575
590
|
var u;
|
|
576
591
|
return !((u = n.getState().contact) != null && u.id) && e.collectUserData ? {
|
|
577
592
|
should: !0,
|
|
@@ -580,13 +595,13 @@ function ne(t) {
|
|
|
580
595
|
should: !1
|
|
581
596
|
};
|
|
582
597
|
}
|
|
583
|
-
async function
|
|
598
|
+
async function c() {
|
|
584
599
|
try {
|
|
585
600
|
if (n.setStatePartial({
|
|
586
601
|
loading: { isLoading: !0, reason: "cleaning_up" },
|
|
587
602
|
error: { hasError: !1 }
|
|
588
603
|
}), o) {
|
|
589
|
-
const r = await
|
|
604
|
+
const r = await A(
|
|
590
605
|
() => o.removeItem(s),
|
|
591
606
|
"Error removing contact data"
|
|
592
607
|
);
|
|
@@ -614,29 +629,28 @@ function ne(t) {
|
|
|
614
629
|
}
|
|
615
630
|
return {
|
|
616
631
|
contactState: n,
|
|
617
|
-
shouldCollectData:
|
|
632
|
+
shouldCollectData: l,
|
|
618
633
|
loadContact: a,
|
|
619
634
|
saveContact: i,
|
|
620
|
-
cleanup:
|
|
635
|
+
cleanup: c
|
|
621
636
|
};
|
|
622
637
|
}
|
|
623
|
-
const
|
|
638
|
+
const V = {
|
|
624
639
|
messageArrived: "https://cloud.opencopilot.so/sfx/notification3.mp3"
|
|
625
|
-
},
|
|
640
|
+
}, x = {
|
|
626
641
|
primaryColor: "hsl(211,65%,59%)",
|
|
627
642
|
triggerOffset: "20px"
|
|
628
|
-
},
|
|
629
|
-
function
|
|
630
|
-
var s, o,
|
|
643
|
+
}, K = 1e3 * 3;
|
|
644
|
+
function ce(t) {
|
|
645
|
+
var s, o, f, n, a, i, l, c, r;
|
|
631
646
|
if (!t.token)
|
|
632
647
|
throw new Error("Token is required");
|
|
633
|
-
if (t.pollingInterval && t.pollingInterval <
|
|
648
|
+
if (t.pollingInterval && t.pollingInterval < K)
|
|
634
649
|
throw new Error("Polling interval must be at least 3 seconds");
|
|
635
650
|
const e = {
|
|
636
651
|
...t,
|
|
637
652
|
collectUserData: t.collectUserData ?? !1,
|
|
638
653
|
apiUrl: t.apiUrl ?? "https://api-v2.opencopilot.so/backend",
|
|
639
|
-
socketUrl: t.socketUrl ?? "https://api-v2.opencopilot.so",
|
|
640
654
|
pollingInterval: t.pollingInterval ?? 3e3,
|
|
641
655
|
headers: t.headers ?? {},
|
|
642
656
|
queryParams: t.queryParams ?? {},
|
|
@@ -644,7 +658,7 @@ function oe(t) {
|
|
|
644
658
|
bot: {
|
|
645
659
|
name: ((s = t.bot) == null ? void 0 : s.name) ?? "Bot",
|
|
646
660
|
avatarUrl: (o = t.bot) == null ? void 0 : o.avatarUrl,
|
|
647
|
-
id: ((
|
|
661
|
+
id: ((f = t.bot) == null ? void 0 : f.id) ?? null,
|
|
648
662
|
is_ai: ((n = t.bot) == null ? void 0 : n.is_ai) ?? !0
|
|
649
663
|
},
|
|
650
664
|
contactToken: t.contactToken,
|
|
@@ -652,14 +666,14 @@ function oe(t) {
|
|
|
652
666
|
language: t.language ?? "en",
|
|
653
667
|
user: t.user ?? {},
|
|
654
668
|
soundEffectFiles: {
|
|
655
|
-
messageArrived: ((a = t.soundEffectFiles) == null ? void 0 : a.messageArrived) ??
|
|
669
|
+
messageArrived: ((a = t.soundEffectFiles) == null ? void 0 : a.messageArrived) ?? V.messageArrived
|
|
656
670
|
},
|
|
657
671
|
theme: {
|
|
658
|
-
primaryColor: ((i = t.theme) == null ? void 0 : i.primaryColor) ??
|
|
659
|
-
triggerOffset: ((
|
|
672
|
+
primaryColor: ((i = t.theme) == null ? void 0 : i.primaryColor) ?? x.primaryColor,
|
|
673
|
+
triggerOffset: ((l = t.theme) == null ? void 0 : l.triggerOffset) ?? x.triggerOffset
|
|
660
674
|
},
|
|
661
675
|
settings: {
|
|
662
|
-
persistSession: ((
|
|
676
|
+
persistSession: ((c = t.settings) == null ? void 0 : c.persistSession) ?? !1,
|
|
663
677
|
useSoundEffects: ((r = t.settings) == null ? void 0 : r.useSoundEffects) ?? !1
|
|
664
678
|
}
|
|
665
679
|
};
|
|
@@ -681,8 +695,8 @@ function oe(t) {
|
|
|
681
695
|
getDebugMode: () => e.debug
|
|
682
696
|
};
|
|
683
697
|
}
|
|
684
|
-
function
|
|
685
|
-
const e = [], s = [], o = [],
|
|
698
|
+
function Y(t = {}) {
|
|
699
|
+
const e = [], s = [], o = [], f = async (n, a = {}) => {
|
|
686
700
|
let i = {
|
|
687
701
|
...t,
|
|
688
702
|
...a,
|
|
@@ -694,19 +708,19 @@ function V(t = {}) {
|
|
|
694
708
|
try {
|
|
695
709
|
for (const u of e)
|
|
696
710
|
i = await u(i);
|
|
697
|
-
const
|
|
698
|
-
let r = await fetch(
|
|
711
|
+
const l = i.params ? "?" + new URLSearchParams(i.params).toString() : "", c = i.baseURL ? `${i.baseURL}${n}${l}`.replace(/([^:]\/)\/+/g, "$1") : `${n}${l}`;
|
|
712
|
+
let r = await fetch(c, i);
|
|
699
713
|
for (const u of s)
|
|
700
714
|
r = await u(r);
|
|
701
715
|
return r;
|
|
702
|
-
} catch (
|
|
703
|
-
let
|
|
716
|
+
} catch (l) {
|
|
717
|
+
let c = l;
|
|
704
718
|
for (const r of o)
|
|
705
|
-
|
|
706
|
-
throw
|
|
719
|
+
c = await r(c);
|
|
720
|
+
throw c;
|
|
707
721
|
}
|
|
708
722
|
};
|
|
709
|
-
return
|
|
723
|
+
return f.interceptors = {
|
|
710
724
|
request: {
|
|
711
725
|
use: (n) => (e.push(n), e.length - 1),
|
|
712
726
|
eject: (n) => {
|
|
@@ -719,10 +733,10 @@ function V(t = {}) {
|
|
|
719
733
|
s.splice(n, 1), o.splice(n, 1);
|
|
720
734
|
}
|
|
721
735
|
}
|
|
722
|
-
},
|
|
736
|
+
}, f;
|
|
723
737
|
}
|
|
724
738
|
var b;
|
|
725
|
-
class
|
|
739
|
+
class le {
|
|
726
740
|
constructor(e) {
|
|
727
741
|
M(this, b);
|
|
728
742
|
this.options = e;
|
|
@@ -731,15 +745,15 @@ class ie {
|
|
|
731
745
|
value: ""
|
|
732
746
|
};
|
|
733
747
|
s != null && s.email ? (o.claim = "email", o.value = s.email) : s != null && s.phone && (o.claim = "phone", o.value = s.phone);
|
|
734
|
-
const
|
|
748
|
+
const f = {
|
|
735
749
|
"X-Bot-Token": this.options.config.token,
|
|
736
750
|
"X-Consumer-Id": `${o.claim}:${o.value}`,
|
|
737
751
|
"Content-Type": "application/json",
|
|
738
752
|
Accept: "application/json"
|
|
739
753
|
};
|
|
740
|
-
this.options.config.contactToken && (
|
|
754
|
+
this.options.config.contactToken && (f.Authorization = `Bearer ${this.options.config.contactToken}`), _(this, b, Y({
|
|
741
755
|
baseURL: `${this.options.config.apiUrl}/widget/v2`,
|
|
742
|
-
headers:
|
|
756
|
+
headers: f
|
|
743
757
|
}));
|
|
744
758
|
}
|
|
745
759
|
async me() {
|
|
@@ -757,8 +771,8 @@ class ie {
|
|
|
757
771
|
async getSessionHistory(e, s) {
|
|
758
772
|
const o = new URLSearchParams({
|
|
759
773
|
lastMessageTimestamp: s || ""
|
|
760
|
-
}),
|
|
761
|
-
return (await h(this, b).call(this,
|
|
774
|
+
}), f = `/session/history/${e}?${o.toString()}`;
|
|
775
|
+
return (await h(this, b).call(this, f, {
|
|
762
776
|
method: "GET"
|
|
763
777
|
})).json();
|
|
764
778
|
}
|
|
@@ -772,35 +786,29 @@ class ie {
|
|
|
772
786
|
method: "GET"
|
|
773
787
|
})).json();
|
|
774
788
|
}
|
|
775
|
-
async createContact(e) {
|
|
776
|
-
return (await h(this, b).call(this, "/contact/upsert", {
|
|
777
|
-
method: "POST",
|
|
778
|
-
body: JSON.stringify(e)
|
|
779
|
-
})).json();
|
|
780
|
-
}
|
|
781
789
|
}
|
|
782
790
|
b = new WeakMap();
|
|
783
|
-
function
|
|
791
|
+
function ue(t = {}) {
|
|
784
792
|
const {
|
|
785
793
|
level: e = "info",
|
|
786
794
|
prefix: s = "[openCx]",
|
|
787
795
|
enabled: o = !0
|
|
788
796
|
} = t;
|
|
789
|
-
let
|
|
797
|
+
let f = e;
|
|
790
798
|
const n = {
|
|
791
799
|
debug: 0,
|
|
792
800
|
info: 1,
|
|
793
801
|
warn: 2,
|
|
794
802
|
error: 3
|
|
795
803
|
};
|
|
796
|
-
function a(
|
|
797
|
-
return o && n[
|
|
804
|
+
function a(c) {
|
|
805
|
+
return o && n[c] >= n[f];
|
|
798
806
|
}
|
|
799
|
-
function i(
|
|
800
|
-
return `${s} ${
|
|
807
|
+
function i(c) {
|
|
808
|
+
return `${s} ${c}`;
|
|
801
809
|
}
|
|
802
|
-
function c
|
|
803
|
-
return
|
|
810
|
+
function l(c) {
|
|
811
|
+
return c.map((r) => {
|
|
804
812
|
if (r instanceof Error)
|
|
805
813
|
return {
|
|
806
814
|
name: r.name,
|
|
@@ -817,50 +825,42 @@ function ce(t = {}) {
|
|
|
817
825
|
});
|
|
818
826
|
}
|
|
819
827
|
return {
|
|
820
|
-
debug(
|
|
821
|
-
a("debug") && console.debug(i(
|
|
828
|
+
debug(c, ...r) {
|
|
829
|
+
a("debug") && console.debug(i(c), ...l(r));
|
|
822
830
|
},
|
|
823
|
-
info(
|
|
824
|
-
a("info") && console.info(i(
|
|
831
|
+
info(c, ...r) {
|
|
832
|
+
a("info") && console.info(i(c), ...l(r));
|
|
825
833
|
},
|
|
826
|
-
warn(
|
|
827
|
-
a("warn") && console.warn(i(
|
|
834
|
+
warn(c, ...r) {
|
|
835
|
+
a("warn") && console.warn(i(c), ...l(r));
|
|
828
836
|
},
|
|
829
|
-
error(
|
|
830
|
-
a("error") && console.error(i(
|
|
837
|
+
error(c, ...r) {
|
|
838
|
+
a("error") && console.error(i(c), ...l(r));
|
|
831
839
|
},
|
|
832
|
-
setLevel(
|
|
833
|
-
|
|
840
|
+
setLevel(c) {
|
|
841
|
+
f = c;
|
|
834
842
|
}
|
|
835
843
|
};
|
|
836
844
|
}
|
|
837
845
|
export {
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
fe as MessageTypeEnum,
|
|
846
|
+
le as ApiCaller,
|
|
847
|
+
se as AuthenticationError,
|
|
848
|
+
te as ConnectionError,
|
|
849
|
+
ne as FileUploadError,
|
|
850
|
+
G as LifecycleEvent,
|
|
851
|
+
me as MessageTypeEnum,
|
|
845
852
|
v as OpenCXError,
|
|
846
853
|
C as PubSub,
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
oe as createConfig,
|
|
859
|
-
ne as createContact,
|
|
860
|
-
ce as createLogger,
|
|
861
|
-
W as createPubSub,
|
|
862
|
-
T as isStorageAvailable,
|
|
863
|
-
O as safeStorageOperation,
|
|
864
|
-
be as structuredSocketMessageSchema
|
|
854
|
+
J as SessionError,
|
|
855
|
+
re as SessionNotDefinedError,
|
|
856
|
+
ae as TransportError,
|
|
857
|
+
ge as chatAttachmentSchema,
|
|
858
|
+
oe as createChat,
|
|
859
|
+
ce as createConfig,
|
|
860
|
+
ie as createContact,
|
|
861
|
+
ue as createLogger,
|
|
862
|
+
ee as createPubSub,
|
|
863
|
+
L as isStorageAvailable,
|
|
864
|
+
A as safeStorageOperation
|
|
865
865
|
};
|
|
866
866
|
//# sourceMappingURL=index.js.map
|