@opencx/widget 2.4.4-rn.1 → 2.4.4-rn.3
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-BWogWLb5.js} +964 -864
- package/dist/index-BWogWLb5.js.map +1 -0
- package/dist/index-D-1u4USy.cjs +18 -0
- package/dist/index-D-1u4USy.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +190 -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_bot" },
|
|
424
|
+
error: { hasError: !1 }
|
|
425
|
+
}) : s.setStatePartial({
|
|
426
|
+
loading: { isLoading: !0, reason: "sending_message_to_agent" },
|
|
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,24 @@ 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
|
+
user: g.user,
|
|
439
|
+
...l
|
|
424
440
|
});
|
|
425
441
|
if (p.success) {
|
|
426
442
|
e == null || e.debug("Message sent successfully");
|
|
427
|
-
const I =
|
|
443
|
+
const I = f.addBotMessage(p);
|
|
428
444
|
if (I) {
|
|
429
|
-
const
|
|
445
|
+
const T = s.getState().messages;
|
|
430
446
|
s.setStatePartial({
|
|
431
|
-
messages: [...
|
|
447
|
+
messages: [...T, I]
|
|
432
448
|
});
|
|
433
449
|
}
|
|
434
450
|
} else {
|
|
435
451
|
e == null || e.warn("Message send failed", p.error);
|
|
436
|
-
const I =
|
|
452
|
+
const I = f.addErrorMessage(((r = p.error) == null ? void 0 : r.message) || "Unknown error occurred"), T = s.getState().messages;
|
|
437
453
|
s.setStatePartial({
|
|
438
|
-
messages: [...
|
|
454
|
+
messages: [...T, I]
|
|
439
455
|
});
|
|
440
456
|
}
|
|
441
457
|
return !0;
|
|
@@ -462,27 +478,27 @@ function ae(t) {
|
|
|
462
478
|
cleanup: n.cleanup
|
|
463
479
|
};
|
|
464
480
|
}
|
|
465
|
-
function
|
|
481
|
+
function ie(t) {
|
|
466
482
|
const e = t.config.getConfig();
|
|
467
483
|
t.config.getConfig;
|
|
468
|
-
const s = `${e.token}:contact:${e.user.external_id}`, o =
|
|
469
|
-
let
|
|
470
|
-
o &&
|
|
484
|
+
const s = `${e.token}:contact:${e.user.external_id}`, o = L(t.platform.storage) ? t.platform.storage : void 0;
|
|
485
|
+
let f = null;
|
|
486
|
+
o && A(
|
|
471
487
|
async () => {
|
|
472
488
|
const r = await o.getItem(s);
|
|
473
489
|
return r ? JSON.parse(r) : null;
|
|
474
490
|
},
|
|
475
491
|
"Error loading contact from storage"
|
|
476
492
|
).then((r) => {
|
|
477
|
-
r.success && (
|
|
493
|
+
r.success && (f = r.result);
|
|
478
494
|
});
|
|
479
495
|
const n = new C({
|
|
480
|
-
contact:
|
|
496
|
+
contact: f,
|
|
481
497
|
loading: { isLoading: !1 },
|
|
482
498
|
error: { hasError: !1 }
|
|
483
499
|
});
|
|
484
|
-
|
|
485
|
-
|
|
500
|
+
L(o) && n.subscribe((r) => {
|
|
501
|
+
A(
|
|
486
502
|
async () => {
|
|
487
503
|
r.contact ? await o.setItem(s, JSON.stringify(r.contact)) : o.removeItem(s);
|
|
488
504
|
},
|
|
@@ -503,7 +519,7 @@ function ne(t) {
|
|
|
503
519
|
loading: { isLoading: !0, reason: "loading_contact" },
|
|
504
520
|
error: { hasError: !1 }
|
|
505
521
|
}), o) {
|
|
506
|
-
const r = await
|
|
522
|
+
const r = await A(
|
|
507
523
|
async () => {
|
|
508
524
|
const u = await o.getItem(s);
|
|
509
525
|
return u ? JSON.parse(u) : null;
|
|
@@ -545,8 +561,8 @@ function ne(t) {
|
|
|
545
561
|
avatar_url: r.avatar_url ?? (u == null ? void 0 : u.avatar_url) ?? null,
|
|
546
562
|
email: r.email ?? (u == null ? void 0 : u.email) ?? null
|
|
547
563
|
};
|
|
548
|
-
if (
|
|
549
|
-
const g = await
|
|
564
|
+
if (L(o)) {
|
|
565
|
+
const g = await A(
|
|
550
566
|
() => o.setItem(s, JSON.stringify(E)),
|
|
551
567
|
"Error saving contact"
|
|
552
568
|
);
|
|
@@ -571,7 +587,7 @@ function ne(t) {
|
|
|
571
587
|
});
|
|
572
588
|
}
|
|
573
589
|
}
|
|
574
|
-
function
|
|
590
|
+
function l() {
|
|
575
591
|
var u;
|
|
576
592
|
return !((u = n.getState().contact) != null && u.id) && e.collectUserData ? {
|
|
577
593
|
should: !0,
|
|
@@ -580,13 +596,13 @@ function ne(t) {
|
|
|
580
596
|
should: !1
|
|
581
597
|
};
|
|
582
598
|
}
|
|
583
|
-
async function
|
|
599
|
+
async function c() {
|
|
584
600
|
try {
|
|
585
601
|
if (n.setStatePartial({
|
|
586
602
|
loading: { isLoading: !0, reason: "cleaning_up" },
|
|
587
603
|
error: { hasError: !1 }
|
|
588
604
|
}), o) {
|
|
589
|
-
const r = await
|
|
605
|
+
const r = await A(
|
|
590
606
|
() => o.removeItem(s),
|
|
591
607
|
"Error removing contact data"
|
|
592
608
|
);
|
|
@@ -614,29 +630,28 @@ function ne(t) {
|
|
|
614
630
|
}
|
|
615
631
|
return {
|
|
616
632
|
contactState: n,
|
|
617
|
-
shouldCollectData:
|
|
633
|
+
shouldCollectData: l,
|
|
618
634
|
loadContact: a,
|
|
619
635
|
saveContact: i,
|
|
620
|
-
cleanup:
|
|
636
|
+
cleanup: c
|
|
621
637
|
};
|
|
622
638
|
}
|
|
623
|
-
const
|
|
639
|
+
const V = {
|
|
624
640
|
messageArrived: "https://cloud.opencopilot.so/sfx/notification3.mp3"
|
|
625
|
-
},
|
|
641
|
+
}, x = {
|
|
626
642
|
primaryColor: "hsl(211,65%,59%)",
|
|
627
643
|
triggerOffset: "20px"
|
|
628
|
-
},
|
|
629
|
-
function
|
|
630
|
-
var s, o,
|
|
644
|
+
}, K = 1e3 * 3;
|
|
645
|
+
function ce(t) {
|
|
646
|
+
var s, o, f, n, a, i, l, c, r;
|
|
631
647
|
if (!t.token)
|
|
632
648
|
throw new Error("Token is required");
|
|
633
|
-
if (t.pollingInterval && t.pollingInterval <
|
|
649
|
+
if (t.pollingInterval && t.pollingInterval < K)
|
|
634
650
|
throw new Error("Polling interval must be at least 3 seconds");
|
|
635
651
|
const e = {
|
|
636
652
|
...t,
|
|
637
653
|
collectUserData: t.collectUserData ?? !1,
|
|
638
654
|
apiUrl: t.apiUrl ?? "https://api-v2.opencopilot.so/backend",
|
|
639
|
-
socketUrl: t.socketUrl ?? "https://api-v2.opencopilot.so",
|
|
640
655
|
pollingInterval: t.pollingInterval ?? 3e3,
|
|
641
656
|
headers: t.headers ?? {},
|
|
642
657
|
queryParams: t.queryParams ?? {},
|
|
@@ -644,7 +659,7 @@ function oe(t) {
|
|
|
644
659
|
bot: {
|
|
645
660
|
name: ((s = t.bot) == null ? void 0 : s.name) ?? "Bot",
|
|
646
661
|
avatarUrl: (o = t.bot) == null ? void 0 : o.avatarUrl,
|
|
647
|
-
id: ((
|
|
662
|
+
id: ((f = t.bot) == null ? void 0 : f.id) ?? null,
|
|
648
663
|
is_ai: ((n = t.bot) == null ? void 0 : n.is_ai) ?? !0
|
|
649
664
|
},
|
|
650
665
|
contactToken: t.contactToken,
|
|
@@ -652,14 +667,14 @@ function oe(t) {
|
|
|
652
667
|
language: t.language ?? "en",
|
|
653
668
|
user: t.user ?? {},
|
|
654
669
|
soundEffectFiles: {
|
|
655
|
-
messageArrived: ((a = t.soundEffectFiles) == null ? void 0 : a.messageArrived) ??
|
|
670
|
+
messageArrived: ((a = t.soundEffectFiles) == null ? void 0 : a.messageArrived) ?? V.messageArrived
|
|
656
671
|
},
|
|
657
672
|
theme: {
|
|
658
|
-
primaryColor: ((i = t.theme) == null ? void 0 : i.primaryColor) ??
|
|
659
|
-
triggerOffset: ((
|
|
673
|
+
primaryColor: ((i = t.theme) == null ? void 0 : i.primaryColor) ?? x.primaryColor,
|
|
674
|
+
triggerOffset: ((l = t.theme) == null ? void 0 : l.triggerOffset) ?? x.triggerOffset
|
|
660
675
|
},
|
|
661
676
|
settings: {
|
|
662
|
-
persistSession: ((
|
|
677
|
+
persistSession: ((c = t.settings) == null ? void 0 : c.persistSession) ?? !1,
|
|
663
678
|
useSoundEffects: ((r = t.settings) == null ? void 0 : r.useSoundEffects) ?? !1
|
|
664
679
|
}
|
|
665
680
|
};
|
|
@@ -681,8 +696,8 @@ function oe(t) {
|
|
|
681
696
|
getDebugMode: () => e.debug
|
|
682
697
|
};
|
|
683
698
|
}
|
|
684
|
-
function
|
|
685
|
-
const e = [], s = [], o = [],
|
|
699
|
+
function Y(t = {}) {
|
|
700
|
+
const e = [], s = [], o = [], f = async (n, a = {}) => {
|
|
686
701
|
let i = {
|
|
687
702
|
...t,
|
|
688
703
|
...a,
|
|
@@ -694,19 +709,19 @@ function V(t = {}) {
|
|
|
694
709
|
try {
|
|
695
710
|
for (const u of e)
|
|
696
711
|
i = await u(i);
|
|
697
|
-
const
|
|
698
|
-
let r = await fetch(
|
|
712
|
+
const l = i.params ? "?" + new URLSearchParams(i.params).toString() : "", c = i.baseURL ? `${i.baseURL}${n}${l}`.replace(/([^:]\/)\/+/g, "$1") : `${n}${l}`;
|
|
713
|
+
let r = await fetch(c, i);
|
|
699
714
|
for (const u of s)
|
|
700
715
|
r = await u(r);
|
|
701
716
|
return r;
|
|
702
|
-
} catch (
|
|
703
|
-
let
|
|
717
|
+
} catch (l) {
|
|
718
|
+
let c = l;
|
|
704
719
|
for (const r of o)
|
|
705
|
-
|
|
706
|
-
throw
|
|
720
|
+
c = await r(c);
|
|
721
|
+
throw c;
|
|
707
722
|
}
|
|
708
723
|
};
|
|
709
|
-
return
|
|
724
|
+
return f.interceptors = {
|
|
710
725
|
request: {
|
|
711
726
|
use: (n) => (e.push(n), e.length - 1),
|
|
712
727
|
eject: (n) => {
|
|
@@ -719,10 +734,10 @@ function V(t = {}) {
|
|
|
719
734
|
s.splice(n, 1), o.splice(n, 1);
|
|
720
735
|
}
|
|
721
736
|
}
|
|
722
|
-
},
|
|
737
|
+
}, f;
|
|
723
738
|
}
|
|
724
739
|
var b;
|
|
725
|
-
class
|
|
740
|
+
class le {
|
|
726
741
|
constructor(e) {
|
|
727
742
|
M(this, b);
|
|
728
743
|
this.options = e;
|
|
@@ -731,15 +746,15 @@ class ie {
|
|
|
731
746
|
value: ""
|
|
732
747
|
};
|
|
733
748
|
s != null && s.email ? (o.claim = "email", o.value = s.email) : s != null && s.phone && (o.claim = "phone", o.value = s.phone);
|
|
734
|
-
const
|
|
749
|
+
const f = {
|
|
735
750
|
"X-Bot-Token": this.options.config.token,
|
|
736
751
|
"X-Consumer-Id": `${o.claim}:${o.value}`,
|
|
737
752
|
"Content-Type": "application/json",
|
|
738
753
|
Accept: "application/json"
|
|
739
754
|
};
|
|
740
|
-
this.options.config.contactToken && (
|
|
755
|
+
this.options.config.contactToken && (f.Authorization = `Bearer ${this.options.config.contactToken}`), _(this, b, Y({
|
|
741
756
|
baseURL: `${this.options.config.apiUrl}/widget/v2`,
|
|
742
|
-
headers:
|
|
757
|
+
headers: f
|
|
743
758
|
}));
|
|
744
759
|
}
|
|
745
760
|
async me() {
|
|
@@ -757,8 +772,8 @@ class ie {
|
|
|
757
772
|
async getSessionHistory(e, s) {
|
|
758
773
|
const o = new URLSearchParams({
|
|
759
774
|
lastMessageTimestamp: s || ""
|
|
760
|
-
}),
|
|
761
|
-
return (await h(this, b).call(this,
|
|
775
|
+
}), f = `/session/history/${e}?${o.toString()}`;
|
|
776
|
+
return (await h(this, b).call(this, f, {
|
|
762
777
|
method: "GET"
|
|
763
778
|
})).json();
|
|
764
779
|
}
|
|
@@ -772,35 +787,29 @@ class ie {
|
|
|
772
787
|
method: "GET"
|
|
773
788
|
})).json();
|
|
774
789
|
}
|
|
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
790
|
}
|
|
782
791
|
b = new WeakMap();
|
|
783
|
-
function
|
|
792
|
+
function ue(t = {}) {
|
|
784
793
|
const {
|
|
785
794
|
level: e = "info",
|
|
786
795
|
prefix: s = "[openCx]",
|
|
787
796
|
enabled: o = !0
|
|
788
797
|
} = t;
|
|
789
|
-
let
|
|
798
|
+
let f = e;
|
|
790
799
|
const n = {
|
|
791
800
|
debug: 0,
|
|
792
801
|
info: 1,
|
|
793
802
|
warn: 2,
|
|
794
803
|
error: 3
|
|
795
804
|
};
|
|
796
|
-
function a(
|
|
797
|
-
return o && n[
|
|
805
|
+
function a(c) {
|
|
806
|
+
return o && n[c] >= n[f];
|
|
798
807
|
}
|
|
799
|
-
function i(
|
|
800
|
-
return `${s} ${
|
|
808
|
+
function i(c) {
|
|
809
|
+
return `${s} ${c}`;
|
|
801
810
|
}
|
|
802
|
-
function c
|
|
803
|
-
return
|
|
811
|
+
function l(c) {
|
|
812
|
+
return c.map((r) => {
|
|
804
813
|
if (r instanceof Error)
|
|
805
814
|
return {
|
|
806
815
|
name: r.name,
|
|
@@ -817,50 +826,42 @@ function ce(t = {}) {
|
|
|
817
826
|
});
|
|
818
827
|
}
|
|
819
828
|
return {
|
|
820
|
-
debug(
|
|
821
|
-
a("debug") && console.debug(i(
|
|
829
|
+
debug(c, ...r) {
|
|
830
|
+
a("debug") && console.debug(i(c), ...l(r));
|
|
822
831
|
},
|
|
823
|
-
info(
|
|
824
|
-
a("info") && console.info(i(
|
|
832
|
+
info(c, ...r) {
|
|
833
|
+
a("info") && console.info(i(c), ...l(r));
|
|
825
834
|
},
|
|
826
|
-
warn(
|
|
827
|
-
a("warn") && console.warn(i(
|
|
835
|
+
warn(c, ...r) {
|
|
836
|
+
a("warn") && console.warn(i(c), ...l(r));
|
|
828
837
|
},
|
|
829
|
-
error(
|
|
830
|
-
a("error") && console.error(i(
|
|
838
|
+
error(c, ...r) {
|
|
839
|
+
a("error") && console.error(i(c), ...l(r));
|
|
831
840
|
},
|
|
832
|
-
setLevel(
|
|
833
|
-
|
|
841
|
+
setLevel(c) {
|
|
842
|
+
f = c;
|
|
834
843
|
}
|
|
835
844
|
};
|
|
836
845
|
}
|
|
837
846
|
export {
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
fe as MessageTypeEnum,
|
|
847
|
+
le as ApiCaller,
|
|
848
|
+
se as AuthenticationError,
|
|
849
|
+
te as ConnectionError,
|
|
850
|
+
ne as FileUploadError,
|
|
851
|
+
G as LifecycleEvent,
|
|
852
|
+
me as MessageTypeEnum,
|
|
845
853
|
v as OpenCXError,
|
|
846
854
|
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
|
|
855
|
+
J as SessionError,
|
|
856
|
+
re as SessionNotDefinedError,
|
|
857
|
+
ae as TransportError,
|
|
858
|
+
ge as chatAttachmentSchema,
|
|
859
|
+
oe as createChat,
|
|
860
|
+
ce as createConfig,
|
|
861
|
+
ie as createContact,
|
|
862
|
+
ue as createLogger,
|
|
863
|
+
ee as createPubSub,
|
|
864
|
+
L as isStorageAvailable,
|
|
865
|
+
A as safeStorageOperation
|
|
865
866
|
};
|
|
866
867
|
//# sourceMappingURL=index.js.map
|