@opencx/widget 2.4.4-rn.0 → 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/index.d.ts +2 -0
- 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-Cjs7ckCU.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 +337 -282
- 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-BVoLVQCZ.cjs +0 -18
- package/dist/index-BVoLVQCZ.cjs.map +0 -1
- package/dist/index-Cjs7ckCU.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,22 +1,22 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var j = Object.defineProperty;
|
|
2
|
+
var D = (t) => {
|
|
3
3
|
throw TypeError(t);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
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
8
|
import H from "lodash.isequal";
|
|
9
|
-
import { g as
|
|
10
|
-
import {
|
|
11
|
-
var
|
|
12
|
-
class
|
|
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
|
+
class C {
|
|
13
13
|
constructor(e) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
S(this, "subscribers", /* @__PURE__ */ new Set());
|
|
15
|
+
M(this, y);
|
|
16
|
+
S(this, "initialState");
|
|
17
|
+
M(this, P);
|
|
18
|
+
S(this, "lifecycleListeners", /* @__PURE__ */ new Map());
|
|
19
|
+
S(this, "emitLifecycle", (e, s) => {
|
|
20
20
|
const o = this.lifecycleListeners.get(e);
|
|
21
21
|
if (o) {
|
|
22
22
|
const f = {
|
|
@@ -24,7 +24,7 @@ class v {
|
|
|
24
24
|
timestamp: Date.now(),
|
|
25
25
|
data: s
|
|
26
26
|
};
|
|
27
|
-
o.forEach((
|
|
27
|
+
o.forEach((n) => n(f));
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
/**
|
|
@@ -32,10 +32,10 @@ class v {
|
|
|
32
32
|
* @param callback Function to call when state changes
|
|
33
33
|
* @returns Unsubscribe function
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
S(this, "subscribe", (e) => (this.subscribers.add(e), e(h(this, y)), () => {
|
|
36
36
|
this.subscribers.delete(e);
|
|
37
37
|
}));
|
|
38
|
-
|
|
38
|
+
S(this, "onLifecycle", (e, s) => {
|
|
39
39
|
this.lifecycleListeners.has(e) || this.lifecycleListeners.set(e, /* @__PURE__ */ new Set());
|
|
40
40
|
const o = this.lifecycleListeners.get(e);
|
|
41
41
|
return o.add(s), () => {
|
|
@@ -45,16 +45,16 @@ class v {
|
|
|
45
45
|
/**
|
|
46
46
|
* Get the current state
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
S(this, "getState", () => h(this, y));
|
|
49
49
|
/**
|
|
50
50
|
* Set the state and notify subscribers if the state changes
|
|
51
51
|
* @param newState The new state to set
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
S(this, "setState", (e) => {
|
|
54
54
|
this.emitLifecycle("beforeUpdate", {
|
|
55
|
-
previousState:
|
|
55
|
+
previousState: h(this, y),
|
|
56
56
|
nextState: e
|
|
57
|
-
}), H(
|
|
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) {
|
|
@@ -62,66 +62,66 @@ class v {
|
|
|
62
62
|
}
|
|
63
63
|
})), this.emitLifecycle("afterUpdate", { state: e });
|
|
64
64
|
});
|
|
65
|
-
|
|
66
|
-
const s = { ...
|
|
65
|
+
S(this, "setStatePartial", (e) => {
|
|
66
|
+
const s = { ...h(this, y), ...e };
|
|
67
67
|
this.setState(s);
|
|
68
68
|
});
|
|
69
69
|
/**
|
|
70
70
|
* Clear all subscriptions
|
|
71
71
|
*/
|
|
72
|
-
|
|
72
|
+
S(this, "clear", () => {
|
|
73
73
|
this.emitLifecycle(
|
|
74
74
|
"destroy"
|
|
75
75
|
/* DESTROY */
|
|
76
76
|
), this.subscribers.clear(), this.lifecycleListeners.clear();
|
|
77
77
|
});
|
|
78
|
-
|
|
78
|
+
S(this, "reset", () => {
|
|
79
79
|
this.setState(this.initialState);
|
|
80
80
|
});
|
|
81
|
-
|
|
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
|
|
87
|
-
return new
|
|
85
|
+
y = new WeakMap(), P = new WeakMap();
|
|
86
|
+
function ee(t) {
|
|
87
|
+
return new C(t);
|
|
88
88
|
}
|
|
89
|
-
class
|
|
89
|
+
class v extends Error {
|
|
90
90
|
constructor(e) {
|
|
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,28 +171,28 @@ function k(t) {
|
|
|
171
171
|
}
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
|
-
function
|
|
175
|
-
async function o(
|
|
174
|
+
function X(t, e, s) {
|
|
175
|
+
async function o(i) {
|
|
176
176
|
const l = e.getState().messages;
|
|
177
177
|
if (l.length === 0) {
|
|
178
|
-
s == null || s.debug("No messages yet, fetching all history", { sessionId:
|
|
179
|
-
const g = await t.getSessionHistory(
|
|
178
|
+
s == null || s.debug("No messages yet, fetching all history", { sessionId: i.id });
|
|
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
|
|
186
|
-
|
|
187
|
-
const
|
|
185
|
+
const c = l[l.length - 1], r = new Date(c.timestamp);
|
|
186
|
+
r.setSeconds(r.getSeconds() + 1);
|
|
187
|
+
const u = r.toISOString();
|
|
188
188
|
s == null || s.debug("Fetching history messages after timestamp", {
|
|
189
|
-
sessionId:
|
|
190
|
-
lastMessageTimestamp:
|
|
189
|
+
sessionId: i.id,
|
|
190
|
+
lastMessageTimestamp: u,
|
|
191
191
|
currentMessageCount: l.length
|
|
192
192
|
});
|
|
193
|
-
const E = await t.getSessionHistory(
|
|
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),
|
|
@@ -202,32 +202,32 @@ function G(t, e, s) {
|
|
|
202
202
|
}));
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
-
function f(
|
|
205
|
+
function f(i, l) {
|
|
206
206
|
return {
|
|
207
|
-
id:
|
|
207
|
+
id: O(),
|
|
208
208
|
type: "FROM_USER",
|
|
209
|
-
content:
|
|
209
|
+
content: i,
|
|
210
210
|
deliveredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
211
211
|
attachments: l,
|
|
212
212
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
213
213
|
};
|
|
214
214
|
}
|
|
215
|
-
function
|
|
216
|
-
if (
|
|
215
|
+
function n(i) {
|
|
216
|
+
if (i.success && i.autopilotResponse)
|
|
217
217
|
return {
|
|
218
218
|
type: "FROM_BOT",
|
|
219
|
-
id:
|
|
219
|
+
id: i.autopilotResponse.id || O(),
|
|
220
220
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
221
221
|
component: "TEXT",
|
|
222
222
|
data: {
|
|
223
|
-
message:
|
|
223
|
+
message: i.autopilotResponse.value.content
|
|
224
224
|
}
|
|
225
225
|
};
|
|
226
|
-
if (
|
|
227
|
-
const l =
|
|
226
|
+
if (i.success && i.uiResponse) {
|
|
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
232
|
component: l.name,
|
|
233
233
|
data: l.request_response
|
|
@@ -235,14 +235,14 @@ function G(t, e, s) {
|
|
|
235
235
|
}
|
|
236
236
|
return null;
|
|
237
237
|
}
|
|
238
|
-
function
|
|
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: {
|
|
245
|
-
message:
|
|
245
|
+
message: i,
|
|
246
246
|
variant: "error"
|
|
247
247
|
}
|
|
248
248
|
};
|
|
@@ -250,34 +250,34 @@ function G(t, e, s) {
|
|
|
250
250
|
return {
|
|
251
251
|
fetchHistoryMessages: o,
|
|
252
252
|
addUserMessage: f,
|
|
253
|
-
addBotMessage:
|
|
254
|
-
addErrorMessage:
|
|
253
|
+
addBotMessage: n,
|
|
254
|
+
addErrorMessage: a
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
|
-
function
|
|
258
|
-
var
|
|
259
|
-
const
|
|
260
|
-
let
|
|
261
|
-
const l = (
|
|
262
|
-
async function
|
|
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
|
+
let i = null;
|
|
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
|
+
async function u() {
|
|
263
263
|
if (l)
|
|
264
264
|
try {
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
if (
|
|
268
|
-
const m = JSON.parse(
|
|
269
|
-
|
|
265
|
+
a == null || a.debug("Attempting to restore session from storage");
|
|
266
|
+
const d = await l.getItem(c);
|
|
267
|
+
if (d) {
|
|
268
|
+
const m = JSON.parse(d);
|
|
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
|
-
|
|
271
|
+
} catch (d) {
|
|
272
|
+
a == null || a.error("Error restoring session from storage:", d);
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
function E() {
|
|
276
|
-
l && (
|
|
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: {
|
|
282
282
|
hasError: !0,
|
|
283
283
|
message: m instanceof Error ? m.message : "Failed to persist session",
|
|
@@ -288,10 +288,10 @@ function J(t, e, s, o, f, a) {
|
|
|
288
288
|
}));
|
|
289
289
|
}
|
|
290
290
|
function g() {
|
|
291
|
-
if (
|
|
292
|
-
|
|
293
|
-
const
|
|
294
|
-
|
|
291
|
+
if (i) return;
|
|
292
|
+
a == null || a.debug("Starting polling");
|
|
293
|
+
const d = [];
|
|
294
|
+
d.push(
|
|
295
295
|
setInterval(async () => {
|
|
296
296
|
const m = e.getState();
|
|
297
297
|
if (m != null && m.id)
|
|
@@ -299,36 +299,36 @@ function J(t, e, s, o, f, a) {
|
|
|
299
299
|
const w = await t.getSession(m.id);
|
|
300
300
|
w && e.setState(w);
|
|
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)
|
|
309
309
|
try {
|
|
310
310
|
await o.fetchHistoryMessages(m);
|
|
311
311
|
} catch (w) {
|
|
312
|
-
|
|
312
|
+
a == null || a.error("Error polling messages:", w);
|
|
313
313
|
}
|
|
314
|
-
},
|
|
315
|
-
),
|
|
316
|
-
|
|
314
|
+
}, k.MESSAGES)
|
|
315
|
+
), i = () => {
|
|
316
|
+
a == null || a.debug("Stopping polling"), d.forEach(clearInterval);
|
|
317
317
|
};
|
|
318
318
|
}
|
|
319
319
|
async function p() {
|
|
320
320
|
try {
|
|
321
|
-
|
|
321
|
+
a == null || a.info("Creating new session"), s.setStatePartial({
|
|
322
322
|
loading: { isLoading: !0, reason: "creating_session" },
|
|
323
323
|
error: { hasError: !1 }
|
|
324
324
|
});
|
|
325
|
-
const
|
|
326
|
-
return
|
|
327
|
-
} catch (
|
|
328
|
-
|
|
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;
|
|
@@ -338,17 +338,17 @@ function J(t, e, s, o, f, a) {
|
|
|
338
338
|
});
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
|
-
async function
|
|
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
|
-
|
|
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 },
|
|
350
350
|
error: { hasError: !1 }
|
|
351
|
-
}), (m =
|
|
351
|
+
}), (m = n.onSessionDestroy) == null || m.call(n);
|
|
352
352
|
} catch (w) {
|
|
353
353
|
console.error("Error clearing session:", w), s.setStatePartial({
|
|
354
354
|
error: {
|
|
@@ -359,41 +359,52 @@ function J(t, e, s, o, f, a) {
|
|
|
359
359
|
});
|
|
360
360
|
}
|
|
361
361
|
}
|
|
362
|
-
function
|
|
362
|
+
function T() {
|
|
363
363
|
try {
|
|
364
|
-
|
|
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
|
-
clearSession:
|
|
383
|
-
cleanup:
|
|
384
|
-
startPolling: g
|
|
391
|
+
clearSession: I,
|
|
392
|
+
cleanup: T,
|
|
393
|
+
startPolling: g,
|
|
394
|
+
fetchSession: F,
|
|
395
|
+
refetchSession: q
|
|
385
396
|
};
|
|
386
397
|
}
|
|
387
|
-
function
|
|
388
|
-
var
|
|
389
|
-
const e = (
|
|
398
|
+
function oe(t) {
|
|
399
|
+
var i;
|
|
400
|
+
const e = (i = t.platform) == null ? void 0 : i.logger;
|
|
390
401
|
e == null || e.info("Initializing chat");
|
|
391
|
-
const s = new
|
|
402
|
+
const s = new C({
|
|
392
403
|
messages: [],
|
|
393
404
|
keyboard: null,
|
|
394
405
|
loading: { isLoading: !1 },
|
|
395
406
|
error: { hasError: !1 }
|
|
396
|
-
}), o = new
|
|
407
|
+
}), o = new C(null), f = X(t.api, s, e), n = z(
|
|
397
408
|
t.api,
|
|
398
409
|
o,
|
|
399
410
|
s,
|
|
@@ -401,49 +412,53 @@ function ae(t) {
|
|
|
401
412
|
t.config,
|
|
402
413
|
t
|
|
403
414
|
);
|
|
404
|
-
async function
|
|
405
|
-
var
|
|
406
|
-
let
|
|
407
|
-
if (!(
|
|
415
|
+
async function a(l) {
|
|
416
|
+
var r;
|
|
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
|
|
429
|
+
const u = f.addUserMessage(l.content, l.attachments || void 0), E = s.getState().messages;
|
|
415
430
|
s.setStatePartial({
|
|
416
|
-
messages: [...E,
|
|
431
|
+
messages: [...E, u]
|
|
417
432
|
});
|
|
418
433
|
const g = t.config.getConfig(), p = await t.api.handleMessage({
|
|
419
434
|
bot_token: g.token,
|
|
420
435
|
headers: g.headers,
|
|
421
436
|
query_params: g.queryParams,
|
|
422
|
-
session_id:
|
|
437
|
+
session_id: c.id,
|
|
423
438
|
...l
|
|
424
439
|
});
|
|
425
440
|
if (p.success) {
|
|
426
441
|
e == null || e.debug("Message sent successfully");
|
|
427
|
-
const
|
|
428
|
-
if (
|
|
429
|
-
const
|
|
442
|
+
const I = f.addBotMessage(p);
|
|
443
|
+
if (I) {
|
|
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
|
|
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;
|
|
442
|
-
} catch (
|
|
443
|
-
return e == null || e.error("Error sending message:",
|
|
457
|
+
} catch (u) {
|
|
458
|
+
return e == null || e.error("Error sending message:", u), s.setStatePartial({
|
|
444
459
|
error: {
|
|
445
460
|
hasError: !0,
|
|
446
|
-
message:
|
|
461
|
+
message: u instanceof Error ? u.message : "Failed to send message",
|
|
447
462
|
code: "MESSAGE_SEND_FAILED"
|
|
448
463
|
}
|
|
449
464
|
}), !1;
|
|
@@ -456,187 +471,186 @@ function ae(t) {
|
|
|
456
471
|
return {
|
|
457
472
|
chatState: s,
|
|
458
473
|
sessionState: o,
|
|
459
|
-
sendMessage:
|
|
460
|
-
createSession:
|
|
461
|
-
clearSession:
|
|
462
|
-
cleanup:
|
|
474
|
+
sendMessage: a,
|
|
475
|
+
createSession: n.createSession,
|
|
476
|
+
clearSession: n.clearSession,
|
|
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 =
|
|
483
|
+
const s = `${e.token}:contact:${e.user.external_id}`, o = L(t.platform.storage) ? t.platform.storage : void 0;
|
|
469
484
|
let f = null;
|
|
470
|
-
o &&
|
|
485
|
+
o && A(
|
|
471
486
|
async () => {
|
|
472
|
-
const
|
|
473
|
-
return
|
|
487
|
+
const r = await o.getItem(s);
|
|
488
|
+
return r ? JSON.parse(r) : null;
|
|
474
489
|
},
|
|
475
490
|
"Error loading contact from storage"
|
|
476
|
-
).then((
|
|
477
|
-
|
|
491
|
+
).then((r) => {
|
|
492
|
+
r.success && (f = r.result);
|
|
478
493
|
});
|
|
479
|
-
const
|
|
494
|
+
const n = new C({
|
|
480
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
|
},
|
|
489
504
|
"Error persisting contact state"
|
|
490
|
-
).then((
|
|
491
|
-
|
|
505
|
+
).then((u) => {
|
|
506
|
+
u.success || n.setStatePartial({
|
|
492
507
|
error: {
|
|
493
508
|
hasError: !0,
|
|
494
|
-
message:
|
|
509
|
+
message: u.error.message,
|
|
495
510
|
code: "CONTACT_PERSISTENCE_FAILED"
|
|
496
511
|
}
|
|
497
512
|
});
|
|
498
513
|
});
|
|
499
514
|
});
|
|
500
|
-
async function
|
|
515
|
+
async function a() {
|
|
501
516
|
try {
|
|
502
|
-
if (
|
|
517
|
+
if (n.setStatePartial({
|
|
503
518
|
loading: { isLoading: !0, reason: "loading_contact" },
|
|
504
519
|
error: { hasError: !1 }
|
|
505
520
|
}), o) {
|
|
506
|
-
const
|
|
521
|
+
const r = await A(
|
|
507
522
|
async () => {
|
|
508
|
-
const
|
|
509
|
-
return
|
|
523
|
+
const u = await o.getItem(s);
|
|
524
|
+
return u ? JSON.parse(u) : null;
|
|
510
525
|
},
|
|
511
526
|
"Error loading contact"
|
|
512
527
|
);
|
|
513
|
-
if (!
|
|
514
|
-
throw
|
|
515
|
-
return
|
|
516
|
-
contact:
|
|
528
|
+
if (!r.success)
|
|
529
|
+
throw r.error;
|
|
530
|
+
return n.setStatePartial({
|
|
531
|
+
contact: r.result,
|
|
517
532
|
error: { hasError: !1 }
|
|
518
|
-
}),
|
|
533
|
+
}), r.result;
|
|
519
534
|
}
|
|
520
|
-
return
|
|
521
|
-
} catch (
|
|
522
|
-
return
|
|
535
|
+
return n.getState().contact;
|
|
536
|
+
} catch (r) {
|
|
537
|
+
return n.setStatePartial({
|
|
523
538
|
error: {
|
|
524
539
|
hasError: !0,
|
|
525
|
-
message:
|
|
540
|
+
message: r instanceof Error ? r.message : "Failed to load contact",
|
|
526
541
|
code: "CONTACT_LOAD_FAILED"
|
|
527
542
|
}
|
|
528
543
|
}), null;
|
|
529
544
|
} finally {
|
|
530
|
-
|
|
545
|
+
n.setStatePartial({
|
|
531
546
|
loading: { isLoading: !1, reason: null }
|
|
532
547
|
});
|
|
533
548
|
}
|
|
534
549
|
}
|
|
535
|
-
async function
|
|
550
|
+
async function i(r) {
|
|
536
551
|
try {
|
|
537
|
-
|
|
552
|
+
n.setStatePartial({
|
|
538
553
|
loading: { isLoading: !0, reason: "saving_contact" },
|
|
539
554
|
error: { hasError: !1 }
|
|
540
555
|
});
|
|
541
|
-
const
|
|
542
|
-
id:
|
|
543
|
-
name:
|
|
544
|
-
created_at:
|
|
545
|
-
avatar_url:
|
|
546
|
-
email:
|
|
556
|
+
const u = n.getState().contact, E = {
|
|
557
|
+
id: r.id || (u == null ? void 0 : u.id) || "",
|
|
558
|
+
name: r.name ?? (u == null ? void 0 : u.name) ?? null,
|
|
559
|
+
created_at: r.created_at || (u == null ? void 0 : u.created_at) || (/* @__PURE__ */ new Date()).toISOString(),
|
|
560
|
+
avatar_url: r.avatar_url ?? (u == null ? void 0 : u.avatar_url) ?? null,
|
|
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
|
);
|
|
553
568
|
if (!g.success)
|
|
554
569
|
throw g.error;
|
|
555
570
|
}
|
|
556
|
-
return
|
|
571
|
+
return n.setStatePartial({
|
|
557
572
|
contact: E,
|
|
558
573
|
error: { hasError: !1 }
|
|
559
574
|
}), E;
|
|
560
|
-
} catch (
|
|
561
|
-
return
|
|
575
|
+
} catch (u) {
|
|
576
|
+
return n.setStatePartial({
|
|
562
577
|
error: {
|
|
563
578
|
hasError: !0,
|
|
564
|
-
message:
|
|
579
|
+
message: u instanceof Error ? u.message : "Failed to save contact",
|
|
565
580
|
code: "CONTACT_SAVE_FAILED"
|
|
566
581
|
}
|
|
567
582
|
}), null;
|
|
568
583
|
} finally {
|
|
569
|
-
|
|
584
|
+
n.setStatePartial({
|
|
570
585
|
loading: { isLoading: !1, reason: null }
|
|
571
586
|
});
|
|
572
587
|
}
|
|
573
588
|
}
|
|
574
589
|
function l() {
|
|
575
|
-
var
|
|
576
|
-
return !((
|
|
590
|
+
var u;
|
|
591
|
+
return !((u = n.getState().contact) != null && u.id) && e.collectUserData ? {
|
|
577
592
|
should: !0,
|
|
578
593
|
reason: "No contact id and collectUserData is true"
|
|
579
594
|
} : {
|
|
580
595
|
should: !1
|
|
581
596
|
};
|
|
582
597
|
}
|
|
583
|
-
async function
|
|
598
|
+
async function c() {
|
|
584
599
|
try {
|
|
585
|
-
if (
|
|
600
|
+
if (n.setStatePartial({
|
|
586
601
|
loading: { isLoading: !0, reason: "cleaning_up" },
|
|
587
602
|
error: { hasError: !1 }
|
|
588
603
|
}), o) {
|
|
589
|
-
const
|
|
604
|
+
const r = await A(
|
|
590
605
|
() => o.removeItem(s),
|
|
591
606
|
"Error removing contact data"
|
|
592
607
|
);
|
|
593
|
-
if (!
|
|
594
|
-
throw
|
|
608
|
+
if (!r.success)
|
|
609
|
+
throw r.error;
|
|
595
610
|
}
|
|
596
|
-
|
|
611
|
+
n.setState({
|
|
597
612
|
contact: null,
|
|
598
613
|
loading: { isLoading: !1 },
|
|
599
614
|
error: { hasError: !1 }
|
|
600
|
-
}),
|
|
601
|
-
} catch (
|
|
602
|
-
console.error("Error cleaning up contact:",
|
|
615
|
+
}), n.clear();
|
|
616
|
+
} catch (r) {
|
|
617
|
+
console.error("Error cleaning up contact:", r), n.setStatePartial({
|
|
603
618
|
error: {
|
|
604
619
|
hasError: !0,
|
|
605
|
-
message:
|
|
620
|
+
message: r instanceof Error ? r.message : "Failed to cleanup contact data",
|
|
606
621
|
code: "CONTACT_CLEANUP_FAILED"
|
|
607
622
|
}
|
|
608
623
|
});
|
|
609
624
|
} finally {
|
|
610
|
-
|
|
625
|
+
n.setStatePartial({
|
|
611
626
|
loading: { isLoading: !1, reason: null }
|
|
612
627
|
});
|
|
613
628
|
}
|
|
614
629
|
}
|
|
615
630
|
return {
|
|
616
|
-
contactState:
|
|
631
|
+
contactState: n,
|
|
617
632
|
shouldCollectData: l,
|
|
618
|
-
loadContact:
|
|
619
|
-
saveContact:
|
|
620
|
-
cleanup:
|
|
633
|
+
loadContact: a,
|
|
634
|
+
saveContact: i,
|
|
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, f,
|
|
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 ?? {},
|
|
@@ -645,22 +659,22 @@ function oe(t) {
|
|
|
645
659
|
name: ((s = t.bot) == null ? void 0 : s.name) ?? "Bot",
|
|
646
660
|
avatarUrl: (o = t.bot) == null ? void 0 : o.avatarUrl,
|
|
647
661
|
id: ((f = t.bot) == null ? void 0 : f.id) ?? null,
|
|
648
|
-
is_ai: ((
|
|
662
|
+
is_ai: ((n = t.bot) == null ? void 0 : n.is_ai) ?? !0
|
|
649
663
|
},
|
|
650
664
|
contactToken: t.contactToken,
|
|
651
665
|
debug: t.debug ?? !1,
|
|
652
666
|
language: t.language ?? "en",
|
|
653
667
|
user: t.user ?? {},
|
|
654
668
|
soundEffectFiles: {
|
|
655
|
-
messageArrived: ((
|
|
669
|
+
messageArrived: ((a = t.soundEffectFiles) == null ? void 0 : a.messageArrived) ?? V.messageArrived
|
|
656
670
|
},
|
|
657
671
|
theme: {
|
|
658
|
-
primaryColor: ((
|
|
659
|
-
triggerOffset: ((l = t.theme) == null ? void 0 : l.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: ((
|
|
663
|
-
useSoundEffects: ((
|
|
676
|
+
persistSession: ((c = t.settings) == null ? void 0 : c.persistSession) ?? !1,
|
|
677
|
+
useSoundEffects: ((r = t.settings) == null ? void 0 : r.useSoundEffects) ?? !1
|
|
664
678
|
}
|
|
665
679
|
};
|
|
666
680
|
return {
|
|
@@ -681,50 +695,50 @@ function oe(t) {
|
|
|
681
695
|
getDebugMode: () => e.debug
|
|
682
696
|
};
|
|
683
697
|
}
|
|
684
|
-
function
|
|
685
|
-
const e = [], s = [], o = [], f = async (
|
|
686
|
-
let
|
|
698
|
+
function Y(t = {}) {
|
|
699
|
+
const e = [], s = [], o = [], f = async (n, a = {}) => {
|
|
700
|
+
let i = {
|
|
687
701
|
...t,
|
|
688
|
-
...
|
|
702
|
+
...a,
|
|
689
703
|
headers: {
|
|
690
704
|
...t.headers,
|
|
691
|
-
...
|
|
705
|
+
...a.headers
|
|
692
706
|
}
|
|
693
707
|
};
|
|
694
708
|
try {
|
|
695
|
-
for (const
|
|
696
|
-
|
|
697
|
-
const l =
|
|
698
|
-
let
|
|
699
|
-
for (const
|
|
700
|
-
|
|
701
|
-
return
|
|
709
|
+
for (const u of e)
|
|
710
|
+
i = await u(i);
|
|
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);
|
|
713
|
+
for (const u of s)
|
|
714
|
+
r = await u(r);
|
|
715
|
+
return r;
|
|
702
716
|
} catch (l) {
|
|
703
|
-
let
|
|
704
|
-
for (const
|
|
705
|
-
|
|
706
|
-
throw
|
|
717
|
+
let c = l;
|
|
718
|
+
for (const r of o)
|
|
719
|
+
c = await r(c);
|
|
720
|
+
throw c;
|
|
707
721
|
}
|
|
708
722
|
};
|
|
709
723
|
return f.interceptors = {
|
|
710
724
|
request: {
|
|
711
|
-
use: (
|
|
712
|
-
eject: (
|
|
713
|
-
e.splice(
|
|
725
|
+
use: (n) => (e.push(n), e.length - 1),
|
|
726
|
+
eject: (n) => {
|
|
727
|
+
e.splice(n, 1);
|
|
714
728
|
}
|
|
715
729
|
},
|
|
716
730
|
response: {
|
|
717
|
-
use: (
|
|
718
|
-
eject: (
|
|
719
|
-
s.splice(
|
|
731
|
+
use: (n, a) => (s.push(n), a && o.push(a), s.length - 1),
|
|
732
|
+
eject: (n) => {
|
|
733
|
+
s.splice(n, 1), o.splice(n, 1);
|
|
720
734
|
}
|
|
721
735
|
}
|
|
722
736
|
}, f;
|
|
723
737
|
}
|
|
724
|
-
var
|
|
725
|
-
class
|
|
738
|
+
var b;
|
|
739
|
+
class le {
|
|
726
740
|
constructor(e) {
|
|
727
|
-
|
|
741
|
+
M(this, b);
|
|
728
742
|
this.options = e;
|
|
729
743
|
const s = this.options.config.user, o = {
|
|
730
744
|
claim: "",
|
|
@@ -737,19 +751,19 @@ class ie {
|
|
|
737
751
|
"Content-Type": "application/json",
|
|
738
752
|
Accept: "application/json"
|
|
739
753
|
};
|
|
740
|
-
this.options.config.contactToken && (f.Authorization = `Bearer ${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
756
|
headers: f
|
|
743
757
|
}));
|
|
744
758
|
}
|
|
745
759
|
async me() {
|
|
746
|
-
return (await
|
|
760
|
+
return (await h(this, b).call(this, "/me")).json();
|
|
747
761
|
}
|
|
748
762
|
async widgetPrelude() {
|
|
749
|
-
return (await
|
|
763
|
+
return (await h(this, b).call(this, "/prelude")).json();
|
|
750
764
|
}
|
|
751
765
|
async handleMessage(e) {
|
|
752
|
-
return (await
|
|
766
|
+
return (await h(this, b).call(this, "/chat/send", {
|
|
753
767
|
method: "POST",
|
|
754
768
|
body: JSON.stringify(e)
|
|
755
769
|
})).json();
|
|
@@ -758,54 +772,95 @@ class ie {
|
|
|
758
772
|
const o = new URLSearchParams({
|
|
759
773
|
lastMessageTimestamp: s || ""
|
|
760
774
|
}), f = `/session/history/${e}?${o.toString()}`;
|
|
761
|
-
return (await
|
|
775
|
+
return (await h(this, b).call(this, f, {
|
|
762
776
|
method: "GET"
|
|
763
777
|
})).json();
|
|
764
778
|
}
|
|
765
779
|
async createSession() {
|
|
766
|
-
return (await
|
|
780
|
+
return (await h(this, b).call(this, "/create-session", {
|
|
767
781
|
method: "POST"
|
|
768
782
|
})).json();
|
|
769
783
|
}
|
|
770
784
|
async getSession(e) {
|
|
771
|
-
return (await
|
|
785
|
+
return (await h(this, b).call(this, `/session/${e}`, {
|
|
772
786
|
method: "GET"
|
|
773
787
|
})).json();
|
|
774
788
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
789
|
+
}
|
|
790
|
+
b = new WeakMap();
|
|
791
|
+
function ue(t = {}) {
|
|
792
|
+
const {
|
|
793
|
+
level: e = "info",
|
|
794
|
+
prefix: s = "[openCx]",
|
|
795
|
+
enabled: o = !0
|
|
796
|
+
} = t;
|
|
797
|
+
let f = e;
|
|
798
|
+
const n = {
|
|
799
|
+
debug: 0,
|
|
800
|
+
info: 1,
|
|
801
|
+
warn: 2,
|
|
802
|
+
error: 3
|
|
803
|
+
};
|
|
804
|
+
function a(c) {
|
|
805
|
+
return o && n[c] >= n[f];
|
|
806
|
+
}
|
|
807
|
+
function i(c) {
|
|
808
|
+
return `${s} ${c}`;
|
|
809
|
+
}
|
|
810
|
+
function l(c) {
|
|
811
|
+
return c.map((r) => {
|
|
812
|
+
if (r instanceof Error)
|
|
813
|
+
return {
|
|
814
|
+
name: r.name,
|
|
815
|
+
message: r.message,
|
|
816
|
+
stack: r.stack
|
|
817
|
+
};
|
|
818
|
+
if (typeof r == "object")
|
|
819
|
+
try {
|
|
820
|
+
return JSON.stringify(r, null, 2);
|
|
821
|
+
} catch {
|
|
822
|
+
return r;
|
|
823
|
+
}
|
|
824
|
+
return r;
|
|
825
|
+
});
|
|
780
826
|
}
|
|
827
|
+
return {
|
|
828
|
+
debug(c, ...r) {
|
|
829
|
+
a("debug") && console.debug(i(c), ...l(r));
|
|
830
|
+
},
|
|
831
|
+
info(c, ...r) {
|
|
832
|
+
a("info") && console.info(i(c), ...l(r));
|
|
833
|
+
},
|
|
834
|
+
warn(c, ...r) {
|
|
835
|
+
a("warn") && console.warn(i(c), ...l(r));
|
|
836
|
+
},
|
|
837
|
+
error(c, ...r) {
|
|
838
|
+
a("error") && console.error(i(c), ...l(r));
|
|
839
|
+
},
|
|
840
|
+
setLevel(c) {
|
|
841
|
+
f = c;
|
|
842
|
+
}
|
|
843
|
+
};
|
|
781
844
|
}
|
|
782
|
-
I = new WeakMap();
|
|
783
845
|
export {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
ae as createChat,
|
|
804
|
-
oe as createConfig,
|
|
805
|
-
ne as createContact,
|
|
806
|
-
W as createPubSub,
|
|
807
|
-
T as isStorageAvailable,
|
|
808
|
-
O as safeStorageOperation,
|
|
809
|
-
ye as structuredSocketMessageSchema
|
|
846
|
+
le as ApiCaller,
|
|
847
|
+
se as AuthenticationError,
|
|
848
|
+
te as ConnectionError,
|
|
849
|
+
ne as FileUploadError,
|
|
850
|
+
G as LifecycleEvent,
|
|
851
|
+
me as MessageTypeEnum,
|
|
852
|
+
v as OpenCXError,
|
|
853
|
+
C as PubSub,
|
|
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
|
|
810
865
|
};
|
|
811
866
|
//# sourceMappingURL=index.js.map
|