@opencx/widget 3.0.32 → 3.0.33
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/designs.cjs +54 -54
- package/dist/designs.cjs.map +1 -1
- package/dist/designs.js +1954 -1934
- package/dist/designs.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +22 -16
- package/dist/react.js.map +1 -1
- package/dist/src/designs/react/components/custom-components/Handoff.component.d.ts +3 -0
- package/dist/src/designs/react/hooks/useWidgetContentHeight.d.ts +1 -1
- package/dist/src/headless/core/api.d.ts +1 -1
- package/dist/src/headless/core/context/contact.ctx.d.ts +6 -3
- package/dist/src/headless/core/context/message.ctx.d.ts +1 -1
- package/dist/src/headless/core/context/session.ctx.d.ts +2 -5
- package/dist/src/headless/core/context/storage.ctx.d.ts +12 -0
- package/dist/src/headless/core/context/widget.ctx.d.ts +6 -2
- package/dist/src/headless/core/index.d.ts +2 -1
- package/dist/src/headless/core/types/external-storage.d.ts +5 -0
- package/dist/src/headless/core/utils/Poller.d.ts +1 -1
- package/dist/src/headless/core/utils/PrimitiveState.d.ts +3 -35
- package/dist/src/headless/core/utils/PrimitiveState.spec.d.ts +1 -0
- package/dist/src/headless/react/ComponentRegistry.d.ts +1 -1
- package/dist/src/headless/react/WidgetProvider.d.ts +3 -2
- package/dist/src/headless/react/hooks/useSessions.d.ts +1 -0
- package/dist/{useUploadFiles-CeI1AbIE.js → useUploadFiles-BQllMoIx.js} +83 -83
- package/dist/useUploadFiles-BQllMoIx.js.map +1 -0
- package/dist/{useUploadFiles-Cr6lNjTS.cjs → useUploadFiles-Ckj8FegM.cjs} +2 -2
- package/dist/{useUploadFiles-CeI1AbIE.js.map → useUploadFiles-Ckj8FegM.cjs.map} +1 -1
- package/dist/{widget.ctx-OHYgtVi5.js → widget.ctx-D0ExFLNH.js} +141 -176
- package/dist/widget.ctx-D0ExFLNH.js.map +1 -0
- package/dist/widget.ctx-DnH2-LG7.cjs +2 -0
- package/dist/widget.ctx-DnH2-LG7.cjs.map +1 -0
- package/dist-embed/script.js +105 -105
- package/dist-embed/script.js.map +1 -1
- package/package.json +5 -4
- package/dist/useUploadFiles-Cr6lNjTS.cjs.map +0 -1
- package/dist/widget.ctx-DmyynT8O.cjs +0 -2
- package/dist/widget.ctx-DmyynT8O.cjs.map +0 -1
- package/dist/widget.ctx-OHYgtVi5.js.map +0 -1
- /package/dist/src/headless/core/types/{WidgetConfig.d.ts → widget-config.d.ts} +0 -0
- /package/dist/src/headless/core/utils/{PrimitiveState.test.d.ts → Poller.spec.d.ts} +0 -0
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
console.log(n.error);
|
|
14
|
-
}, q = (n) => {
|
|
15
|
-
const t = E({
|
|
16
|
-
baseUrl: n.baseUrl
|
|
1
|
+
var y = Object.defineProperty;
|
|
2
|
+
var A = (o, t, e) => t in o ? y(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
3
|
+
var s = (o, t, e) => A(o, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import k from "axios";
|
|
5
|
+
import U from "openapi-fetch";
|
|
6
|
+
import M from "lodash.isequal";
|
|
7
|
+
import { v4 as R } from "uuid";
|
|
8
|
+
const E = (o) => {
|
|
9
|
+
console.log(o.error);
|
|
10
|
+
}, F = (o) => {
|
|
11
|
+
const t = U({
|
|
12
|
+
baseUrl: o.baseUrl
|
|
17
13
|
}), e = {
|
|
18
|
-
onRequest:
|
|
19
|
-
onResponse:
|
|
20
|
-
onError:
|
|
14
|
+
onRequest: o.onRequest,
|
|
15
|
+
onResponse: o.onResponse,
|
|
16
|
+
onError: o.onError || E
|
|
21
17
|
};
|
|
22
18
|
return t.use(e), t;
|
|
23
19
|
};
|
|
24
|
-
class
|
|
20
|
+
class T {
|
|
25
21
|
constructor({
|
|
26
22
|
config: t
|
|
27
23
|
}) {
|
|
@@ -40,18 +36,18 @@ class H {
|
|
|
40
36
|
s(this, "createOpenAPIClient", ({
|
|
41
37
|
baseUrl: t,
|
|
42
38
|
headers: e
|
|
43
|
-
}) =>
|
|
39
|
+
}) => F({
|
|
44
40
|
baseUrl: t,
|
|
45
41
|
onRequest: ({ request: i }) => {
|
|
46
|
-
Object.entries(e).forEach(([a,
|
|
47
|
-
|
|
42
|
+
Object.entries(e).forEach(([a, n]) => {
|
|
43
|
+
n && i.headers.set(a, n);
|
|
48
44
|
});
|
|
49
45
|
}
|
|
50
46
|
}));
|
|
51
47
|
s(this, "createAxiosUploadClient", ({
|
|
52
48
|
baseUrl: t,
|
|
53
49
|
headers: e
|
|
54
|
-
}) =>
|
|
50
|
+
}) => k.create({
|
|
55
51
|
baseURL: `${t}/backend/widget/v2/upload`,
|
|
56
52
|
headers: e
|
|
57
53
|
}));
|
|
@@ -122,107 +118,57 @@ class H {
|
|
|
122
118
|
this.client = this.createOpenAPIClient({ baseUrl: e, headers: i }), this.uploadFileClient = this.createAxiosUploadClient({ baseUrl: e, headers: i });
|
|
123
119
|
}
|
|
124
120
|
}
|
|
125
|
-
|
|
126
|
-
class f {
|
|
121
|
+
class g {
|
|
127
122
|
constructor(t) {
|
|
128
123
|
s(this, "subscribers", /* @__PURE__ */ new Set());
|
|
129
|
-
|
|
124
|
+
s(this, "state");
|
|
130
125
|
s(this, "initialState");
|
|
131
|
-
|
|
132
|
-
s(this, "
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
r(a);
|
|
144
|
-
} catch {
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
126
|
+
s(this, "get", () => this.state);
|
|
127
|
+
s(this, "set", (t) => {
|
|
128
|
+
M(this.state, t) || (this.state = t, this.notifySubscribers(t));
|
|
129
|
+
});
|
|
130
|
+
s(this, "setPartial", (t) => {
|
|
131
|
+
if (t == null) return;
|
|
132
|
+
const e = { ...this.state, ...t };
|
|
133
|
+
this.set(e);
|
|
134
|
+
});
|
|
135
|
+
s(this, "reset", () => {
|
|
136
|
+
this.set(this.initialState);
|
|
148
137
|
});
|
|
149
138
|
s(this, "notifySubscribers", (t) => {
|
|
150
139
|
Array.from(this.subscribers).forEach((i) => {
|
|
151
140
|
try {
|
|
152
141
|
i(t);
|
|
153
142
|
} catch (a) {
|
|
154
|
-
|
|
143
|
+
console.error(a);
|
|
155
144
|
}
|
|
156
145
|
});
|
|
157
146
|
});
|
|
158
|
-
/**
|
|
159
|
-
* Subscribe to state changes
|
|
160
|
-
* @param callback Function to call when state changes
|
|
161
|
-
* @returns Unsubscribe function
|
|
162
|
-
*/
|
|
163
147
|
s(this, "subscribe", (t) => (this.subscribers.add(t), () => {
|
|
164
148
|
this.subscribers.delete(t);
|
|
165
149
|
}));
|
|
166
|
-
|
|
167
|
-
this.lifecycleListeners.has(t) || this.lifecycleListeners.set(t, /* @__PURE__ */ new Set());
|
|
168
|
-
const i = this.lifecycleListeners.get(t);
|
|
169
|
-
return i.add(e), () => {
|
|
170
|
-
i.delete(e), i.size === 0 && this.lifecycleListeners.delete(t);
|
|
171
|
-
};
|
|
172
|
-
});
|
|
173
|
-
/** Get the current state */
|
|
174
|
-
s(this, "get", () => h(this, c));
|
|
175
|
-
// TODO make this provide prev state
|
|
176
|
-
/**
|
|
177
|
-
* Set the state and notify subscribers if the state changes
|
|
178
|
-
* @param newState The new state to set
|
|
179
|
-
*/
|
|
180
|
-
s(this, "set", (t) => {
|
|
181
|
-
this.emitLifecycle("beforeUpdate", {
|
|
182
|
-
previousState: h(this, c),
|
|
183
|
-
nextState: t
|
|
184
|
-
}), D(h(this, c), t) || (p(this, c, t), p(this, u, Date.now()), this.emitLifecycle("stateChange", { state: t }), this.notifySubscribers(t)), this.emitLifecycle("afterUpdate", { state: t });
|
|
185
|
-
});
|
|
186
|
-
// TODO make this provide prev state
|
|
187
|
-
s(this, "setPartial", (t) => {
|
|
188
|
-
if (t == null) return;
|
|
189
|
-
const e = { ...h(this, c), ...t };
|
|
190
|
-
this.set(e);
|
|
191
|
-
});
|
|
192
|
-
/**
|
|
193
|
-
* Clear all subscriptions
|
|
194
|
-
*/
|
|
195
|
-
s(this, "clear", () => {
|
|
196
|
-
this.emitLifecycle(
|
|
197
|
-
"destroy"
|
|
198
|
-
/* DESTROY */
|
|
199
|
-
), this.subscribers = /* @__PURE__ */ new Set(), this.lifecycleListeners = /* @__PURE__ */ new Map();
|
|
200
|
-
});
|
|
201
|
-
s(this, "reset", () => {
|
|
202
|
-
this.set(this.initialState);
|
|
203
|
-
});
|
|
204
|
-
s(this, "lastUpdated", () => h(this, u));
|
|
205
|
-
p(this, c, t), this.initialState = t, p(this, u, Date.now()), this.emitLifecycle("init", { initialState: h(this, c) });
|
|
150
|
+
this.state = t, this.initialState = t;
|
|
206
151
|
}
|
|
207
152
|
}
|
|
208
|
-
|
|
209
|
-
class G {
|
|
153
|
+
class O {
|
|
210
154
|
constructor({
|
|
211
155
|
config: t,
|
|
212
|
-
api: e
|
|
156
|
+
api: e,
|
|
157
|
+
storageCtx: i
|
|
213
158
|
}) {
|
|
214
159
|
s(this, "config");
|
|
160
|
+
s(this, "storageCtx");
|
|
215
161
|
s(this, "api");
|
|
216
162
|
s(this, "state");
|
|
217
163
|
s(this, "shouldCollectData", () => {
|
|
218
164
|
var e;
|
|
219
165
|
return !!(!((e = this.state.get().contact) != null && e.token) && this.config.collectUserData);
|
|
220
166
|
});
|
|
221
|
-
s(this, "
|
|
222
|
-
var t, e, i, a;
|
|
223
|
-
await this.createUnverifiedContact({
|
|
224
|
-
name: ((
|
|
225
|
-
email: (
|
|
167
|
+
s(this, "autoCreateUnverifiedUserIfNotExists", async () => {
|
|
168
|
+
var t, e, i, a, n;
|
|
169
|
+
(t = this.config.user) != null && t.token || this.config.collectUserData || await this.createUnverifiedContact({
|
|
170
|
+
name: ((i = (e = this.config.user) == null ? void 0 : e.data) == null ? void 0 : i.name) || "Anonymous",
|
|
171
|
+
email: (n = (a = this.config.user) == null ? void 0 : a.data) == null ? void 0 : n.email
|
|
226
172
|
});
|
|
227
173
|
});
|
|
228
174
|
s(this, "createUnverifiedContact", async (t) => {
|
|
@@ -237,17 +183,17 @@ class G {
|
|
|
237
183
|
this.state.setPartial({ isCreatingUnverifiedContact: !1 });
|
|
238
184
|
}
|
|
239
185
|
});
|
|
240
|
-
var
|
|
241
|
-
this.config = t, this.api = e, this.state = new
|
|
242
|
-
contact: (
|
|
186
|
+
var a, n;
|
|
187
|
+
this.config = t, this.storageCtx = i, this.api = e, this.state = new g({
|
|
188
|
+
contact: (a = t.user) != null && a.token ? { token: (n = t.user) == null ? void 0 : n.token } : null,
|
|
243
189
|
isCreatingUnverifiedContact: !1,
|
|
244
190
|
isErrorCreatingUnverifiedContact: !1
|
|
245
|
-
}),
|
|
191
|
+
}), this.autoCreateUnverifiedUserIfNotExists();
|
|
246
192
|
}
|
|
247
193
|
}
|
|
248
|
-
class
|
|
194
|
+
class S {
|
|
249
195
|
constructor() {
|
|
250
|
-
s(this, "state", new
|
|
196
|
+
s(this, "state", new g({
|
|
251
197
|
isPolling: !1,
|
|
252
198
|
isError: !1
|
|
253
199
|
}));
|
|
@@ -263,10 +209,10 @@ class v {
|
|
|
263
209
|
this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
|
|
264
210
|
try {
|
|
265
211
|
await t(this.abortController.signal);
|
|
266
|
-
} catch (
|
|
212
|
+
} catch (n) {
|
|
267
213
|
if (this.abortController.signal.aborted)
|
|
268
214
|
return;
|
|
269
|
-
console.error("Failed to poll:",
|
|
215
|
+
console.error("Failed to poll:", n), this.state.setPartial({ isError: !0 });
|
|
270
216
|
} finally {
|
|
271
217
|
this.state.setPartial({ isPolling: !1 });
|
|
272
218
|
}
|
|
@@ -278,10 +224,10 @@ class v {
|
|
|
278
224
|
});
|
|
279
225
|
}
|
|
280
226
|
}
|
|
281
|
-
function
|
|
282
|
-
return
|
|
227
|
+
function p() {
|
|
228
|
+
return R();
|
|
283
229
|
}
|
|
284
|
-
class
|
|
230
|
+
class _ {
|
|
285
231
|
constructor({
|
|
286
232
|
config: t,
|
|
287
233
|
api: e,
|
|
@@ -290,13 +236,13 @@ class j {
|
|
|
290
236
|
s(this, "config");
|
|
291
237
|
s(this, "api");
|
|
292
238
|
s(this, "contactCtx");
|
|
293
|
-
s(this, "activeSessionPoller", new
|
|
294
|
-
s(this, "sessionsRefresher", new
|
|
295
|
-
s(this, "sessionState", new
|
|
239
|
+
s(this, "activeSessionPoller", new S());
|
|
240
|
+
s(this, "sessionsRefresher", new S());
|
|
241
|
+
s(this, "sessionState", new g({
|
|
296
242
|
session: null,
|
|
297
243
|
isCreatingSession: !1
|
|
298
244
|
}));
|
|
299
|
-
s(this, "sessionsState", new
|
|
245
|
+
s(this, "sessionsState", new g({
|
|
300
246
|
data: [],
|
|
301
247
|
cursor: void 0,
|
|
302
248
|
isLastPage: !1,
|
|
@@ -322,22 +268,21 @@ class j {
|
|
|
322
268
|
});
|
|
323
269
|
});
|
|
324
270
|
s(this, "registerInitialSessionsFetch", () => {
|
|
325
|
-
var
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
(e = this.contactCtx.state.get().contact) != null && e.token && !this.sessionsState.get().didStartInitialFetch && (t(), this.registerSessionsRefresher()), this.contactCtx.state.subscribe(({ contact: i }) => {
|
|
330
|
-
i != null && i.token && !this.sessionsState.get().didStartInitialFetch && (t(), this.registerSessionsRefresher());
|
|
271
|
+
var t;
|
|
272
|
+
// If the widget config was initially provided with a contact token, no state change would be triggered, so we just fetch
|
|
273
|
+
(t = this.contactCtx.state.get().contact) != null && t.token && !this.sessionsState.get().didStartInitialFetch ? this.registerSessionsRefresher() : this.contactCtx.state.subscribe(({ contact: e }) => {
|
|
274
|
+
e != null && e.token && !this.sessionsState.get().didStartInitialFetch && this.registerSessionsRefresher();
|
|
331
275
|
});
|
|
332
276
|
});
|
|
333
277
|
s(this, "registerSessionsRefresher", () => {
|
|
334
278
|
this.sessionsRefresher.startPolling(async () => {
|
|
279
|
+
this.sessionsState.get().didStartInitialFetch === !1 && this.sessionsState.setPartial({ didStartInitialFetch: !0 });
|
|
335
280
|
const { data: t } = await this.getSessions({ cursor: void 0 });
|
|
336
281
|
if (!t) return;
|
|
337
282
|
const e = [...t.items, ...this.sessionsState.get().data].filter(
|
|
338
|
-
(i, a,
|
|
283
|
+
(i, a, n) => a === n.findIndex((r) => i.id === r.id)
|
|
339
284
|
);
|
|
340
|
-
this.sessionsState.setPartial({ data: e });
|
|
285
|
+
this.sessionsState.setPartial({ data: e }), this.sessionsState.get().isInitialFetchLoading === !0 && this.sessionsState.setPartial({ isInitialFetchLoading: !1 });
|
|
341
286
|
}, 1e4);
|
|
342
287
|
});
|
|
343
288
|
s(this, "createSession", async () => {
|
|
@@ -350,9 +295,6 @@ class j {
|
|
|
350
295
|
});
|
|
351
296
|
return t ? (this.sessionState.setPartial({ session: t, isCreatingSession: !1 }), t) : (console.error("Failed to create session:", e), null);
|
|
352
297
|
});
|
|
353
|
-
/**
|
|
354
|
-
* Let's keep this private for now until we figure out how to do paginated fetching in tandem with the interval refreshing
|
|
355
|
-
*/
|
|
356
298
|
s(this, "loadMoreSessions", async () => {
|
|
357
299
|
if (this.sessionsState.get().isLastPage) return;
|
|
358
300
|
const { data: t } = await this.getSessions({
|
|
@@ -360,7 +302,7 @@ class j {
|
|
|
360
302
|
});
|
|
361
303
|
if (t) {
|
|
362
304
|
const i = [...this.sessionsState.get().data, ...t.items].filter(
|
|
363
|
-
(a,
|
|
305
|
+
(a, n, r) => n === r.findIndex((c) => a.id === c.id)
|
|
364
306
|
);
|
|
365
307
|
this.sessionsState.setPartial({
|
|
366
308
|
data: i,
|
|
@@ -381,7 +323,7 @@ class j {
|
|
|
381
323
|
this.config = t, this.api = e, this.contactCtx = i, this.registerActiveSessionPolling(), this.registerInitialSessionsFetch();
|
|
382
324
|
}
|
|
383
325
|
}
|
|
384
|
-
class
|
|
326
|
+
class L {
|
|
385
327
|
constructor({
|
|
386
328
|
config: t,
|
|
387
329
|
api: e,
|
|
@@ -390,8 +332,8 @@ class N {
|
|
|
390
332
|
s(this, "config");
|
|
391
333
|
s(this, "api");
|
|
392
334
|
s(this, "sessionCtx");
|
|
393
|
-
s(this, "poller", new
|
|
394
|
-
s(this, "state", new
|
|
335
|
+
s(this, "poller", new S());
|
|
336
|
+
s(this, "state", new g({
|
|
395
337
|
messages: [],
|
|
396
338
|
isSendingMessage: !1,
|
|
397
339
|
lastAIResMightSolveUserIssue: !1,
|
|
@@ -409,12 +351,12 @@ class N {
|
|
|
409
351
|
});
|
|
410
352
|
});
|
|
411
353
|
s(this, "sendMessage", async (t) => {
|
|
412
|
-
var
|
|
354
|
+
var n, r, c, d, u, m, x, b, v;
|
|
413
355
|
if (!t.content.trim() && (!t.attachments || t.attachments.length === 0)) {
|
|
414
356
|
console.warn("Cannot send an empty message of no content or attachments");
|
|
415
357
|
return;
|
|
416
358
|
}
|
|
417
|
-
const e = this.state.get().isSendingMessage, i = ((
|
|
359
|
+
const e = this.state.get().isSendingMessage, i = ((n = this.sessionCtx.sessionState.get().session) == null ? void 0 : n.assignee.kind) === "ai", a = this.state.get().messages.at(-1);
|
|
418
360
|
if (i && e || // If last message is from user, then bot response did not arrive yet
|
|
419
361
|
i && (a == null ? void 0 : a.type) === "FROM_USER") {
|
|
420
362
|
console.warn("Cannot send messages while awaiting AI response");
|
|
@@ -423,82 +365,82 @@ class N {
|
|
|
423
365
|
this.sendMessageAbortController = new AbortController(), this.state.setPartial({ lastAIResMightSolveUserIssue: !1 });
|
|
424
366
|
try {
|
|
425
367
|
this.state.setPartial({ isSendingMessage: !0 });
|
|
426
|
-
const
|
|
368
|
+
const f = this.toUserMessage(
|
|
427
369
|
t.content.trim(),
|
|
428
370
|
t.attachments || void 0
|
|
429
|
-
),
|
|
371
|
+
), P = this.state.get().messages;
|
|
430
372
|
if (this.state.setPartial({
|
|
431
|
-
messages: [...
|
|
432
|
-
}), !((
|
|
373
|
+
messages: [...P, f]
|
|
374
|
+
}), !((r = this.sessionCtx.sessionState.get().session) != null && r.id) && !await this.sessionCtx.createSession()) {
|
|
433
375
|
console.error("Failed to create session");
|
|
434
376
|
return;
|
|
435
377
|
}
|
|
436
|
-
const
|
|
437
|
-
if (!
|
|
378
|
+
const w = (c = this.sessionCtx.sessionState.get().session) == null ? void 0 : c.id;
|
|
379
|
+
if (!w) return;
|
|
438
380
|
const { data: l } = await this.api.sendMessage(
|
|
439
381
|
{
|
|
440
|
-
uuid:
|
|
382
|
+
uuid: f.id,
|
|
441
383
|
bot_token: this.config.token,
|
|
442
384
|
headers: this.config.headers,
|
|
443
385
|
query_params: this.config.queryParams,
|
|
444
|
-
session_id:
|
|
445
|
-
user: (
|
|
386
|
+
session_id: w,
|
|
387
|
+
user: (d = this.config.user) == null ? void 0 : d.data,
|
|
446
388
|
...t
|
|
447
389
|
},
|
|
448
390
|
this.sendMessageAbortController.signal
|
|
449
391
|
);
|
|
450
392
|
if (l != null && l.success) {
|
|
451
|
-
const
|
|
452
|
-
if (
|
|
453
|
-
const
|
|
454
|
-
if (!!
|
|
455
|
-
(
|
|
393
|
+
const h = this.toBotMessage(l);
|
|
394
|
+
if (h) {
|
|
395
|
+
const C = this.state.get().messages;
|
|
396
|
+
if (!!C.some(
|
|
397
|
+
(I) => I.id === h.id
|
|
456
398
|
)) {
|
|
457
399
|
this.state.setPartial({
|
|
458
|
-
lastAIResMightSolveUserIssue: ((
|
|
400
|
+
lastAIResMightSolveUserIssue: ((u = l.autopilotResponse) == null ? void 0 : u.mightSolveUserIssue) || ((m = l.uiResponse) == null ? void 0 : m.mightSolveUserIssue)
|
|
459
401
|
});
|
|
460
402
|
return;
|
|
461
403
|
}
|
|
462
404
|
this.state.setPartial({
|
|
463
|
-
messages: [...
|
|
464
|
-
lastAIResMightSolveUserIssue: ((x = l.autopilotResponse) == null ? void 0 : x.mightSolveUserIssue) || ((
|
|
405
|
+
messages: [...C, h],
|
|
406
|
+
lastAIResMightSolveUserIssue: ((x = l.autopilotResponse) == null ? void 0 : x.mightSolveUserIssue) || ((b = l.uiResponse) == null ? void 0 : b.mightSolveUserIssue)
|
|
465
407
|
});
|
|
466
408
|
}
|
|
467
409
|
} else {
|
|
468
|
-
const
|
|
469
|
-
((
|
|
470
|
-
),
|
|
410
|
+
const h = this.toBotErrorMessage(
|
|
411
|
+
((v = l == null ? void 0 : l.error) == null ? void 0 : v.message) || "Unknown error occurred"
|
|
412
|
+
), C = this.state.get().messages;
|
|
471
413
|
this.state.setPartial({
|
|
472
|
-
messages: [...
|
|
414
|
+
messages: [...C, h]
|
|
473
415
|
});
|
|
474
416
|
}
|
|
475
|
-
} catch (
|
|
476
|
-
this.sendMessageAbortController.signal.aborted || console.error("Failed to send message:",
|
|
417
|
+
} catch (f) {
|
|
418
|
+
this.sendMessageAbortController.signal.aborted || console.error("Failed to send message:", f);
|
|
477
419
|
} finally {
|
|
478
420
|
this.state.setPartial({ isSendingMessage: !1 });
|
|
479
421
|
}
|
|
480
422
|
});
|
|
481
423
|
s(this, "fetchAndSetHistory", async (t, e) => {
|
|
482
|
-
var
|
|
424
|
+
var n;
|
|
483
425
|
this.state.get().messages.length === 0 && this.state.setPartial({ isInitialFetchLoading: !0 });
|
|
484
|
-
const i = (
|
|
426
|
+
const i = (n = this.state.get().messages.at(-1)) == null ? void 0 : n.timestamp, { data: a } = await this.api.getSessionHistory({
|
|
485
427
|
sessionId: t,
|
|
486
428
|
lastMessageTimestamp: i,
|
|
487
429
|
abortSignal: e
|
|
488
430
|
});
|
|
489
431
|
if (a && a.length > 0) {
|
|
490
|
-
const
|
|
491
|
-
(
|
|
432
|
+
const r = this.state.get().messages, c = a.map(this.mapHistoryToMessage).filter(
|
|
433
|
+
(d) => !r.some((u) => u.id === d.id)
|
|
492
434
|
);
|
|
493
435
|
this.state.setPartial({
|
|
494
|
-
messages: [...
|
|
436
|
+
messages: [...r, ...c]
|
|
495
437
|
});
|
|
496
438
|
}
|
|
497
439
|
this.state.get().isInitialFetchLoading && this.state.setPartial({ isInitialFetchLoading: !1 });
|
|
498
440
|
});
|
|
499
441
|
/** Not the best name but whatever */
|
|
500
442
|
s(this, "mapHistoryToMessage", (t) => {
|
|
501
|
-
var a,
|
|
443
|
+
var a, n, r;
|
|
502
444
|
const e = {
|
|
503
445
|
id: t.publicId,
|
|
504
446
|
timestamp: t.sentAt || "",
|
|
@@ -533,9 +475,9 @@ class N {
|
|
|
533
475
|
component: "bot_message",
|
|
534
476
|
agent: {
|
|
535
477
|
id: null,
|
|
536
|
-
name: ((
|
|
478
|
+
name: ((n = this.config.bot) == null ? void 0 : n.name) || "",
|
|
537
479
|
isAi: !0,
|
|
538
|
-
avatar: ((
|
|
480
|
+
avatar: ((r = this.config.bot) == null ? void 0 : r.avatar) || ""
|
|
539
481
|
},
|
|
540
482
|
data: {
|
|
541
483
|
message: t.content.text || "",
|
|
@@ -544,7 +486,7 @@ class N {
|
|
|
544
486
|
};
|
|
545
487
|
});
|
|
546
488
|
s(this, "toUserMessage", (t, e) => ({
|
|
547
|
-
id:
|
|
489
|
+
id: p(),
|
|
548
490
|
type: "FROM_USER",
|
|
549
491
|
content: t,
|
|
550
492
|
deliveredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -555,7 +497,7 @@ class N {
|
|
|
555
497
|
var e;
|
|
556
498
|
return t.success && t.autopilotResponse ? {
|
|
557
499
|
type: "FROM_BOT",
|
|
558
|
-
id: t.autopilotResponse.id ||
|
|
500
|
+
id: t.autopilotResponse.id || p(),
|
|
559
501
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
560
502
|
component: "bot_message",
|
|
561
503
|
agent: this.config.bot ? {
|
|
@@ -575,7 +517,7 @@ class N {
|
|
|
575
517
|
});
|
|
576
518
|
s(this, "toBotErrorMessage", (t) => ({
|
|
577
519
|
type: "FROM_BOT",
|
|
578
|
-
id:
|
|
520
|
+
id: p(),
|
|
579
521
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
580
522
|
component: "TEXT",
|
|
581
523
|
data: {
|
|
@@ -587,7 +529,7 @@ class N {
|
|
|
587
529
|
this.config = t, this.api = e, this.sessionCtx = i, this.registerPolling();
|
|
588
530
|
}
|
|
589
531
|
}
|
|
590
|
-
class
|
|
532
|
+
class D {
|
|
591
533
|
constructor({
|
|
592
534
|
contactCtx: t,
|
|
593
535
|
sessionCtx: e,
|
|
@@ -616,34 +558,57 @@ class X {
|
|
|
616
558
|
}
|
|
617
559
|
this.state.setPartial({ screen: "chat" });
|
|
618
560
|
});
|
|
619
|
-
this.state = new
|
|
561
|
+
this.state = new g({
|
|
620
562
|
screen: t.shouldCollectData() ? "welcome" : "sessions"
|
|
621
563
|
}), this.contactCtx = t, this.sessionCtx = e, this.resetChat = i, this.registerRoutingListener();
|
|
622
564
|
}
|
|
623
565
|
}
|
|
624
|
-
class
|
|
625
|
-
constructor({
|
|
566
|
+
class B {
|
|
567
|
+
constructor({ storage: t }) {
|
|
568
|
+
s(this, "storage");
|
|
569
|
+
s(this, "KEYS", {
|
|
570
|
+
contactToken: "opencx__widget__contactToken",
|
|
571
|
+
externalContactId: "opencx__widget__externalContactId"
|
|
572
|
+
});
|
|
573
|
+
s(this, "setContactToken", async (t) => {
|
|
574
|
+
await this.storage.set(this.KEYS.contactToken, t);
|
|
575
|
+
});
|
|
576
|
+
s(this, "getContactToken", async () => this.storage.get(this.KEYS.contactToken));
|
|
577
|
+
s(this, "setExternalContactId", async (t) => {
|
|
578
|
+
await this.storage.set(this.KEYS.externalContactId, t);
|
|
579
|
+
});
|
|
580
|
+
s(this, "getExternalContactId", async () => this.storage.get(this.KEYS.externalContactId));
|
|
581
|
+
this.storage = t;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
class j {
|
|
585
|
+
constructor({
|
|
586
|
+
config: t,
|
|
587
|
+
storage: e
|
|
588
|
+
}) {
|
|
626
589
|
s(this, "config");
|
|
627
590
|
s(this, "api");
|
|
628
591
|
s(this, "contactCtx");
|
|
629
592
|
s(this, "sessionCtx");
|
|
630
593
|
s(this, "messageCtx");
|
|
631
594
|
s(this, "routerCtx");
|
|
595
|
+
s(this, "storageCtx");
|
|
632
596
|
s(this, "resetChat", () => {
|
|
633
597
|
this.sessionCtx.reset(), this.messageCtx.reset();
|
|
634
598
|
});
|
|
635
|
-
this.config = t, this.api = new
|
|
599
|
+
this.config = t, this.api = new T({ config: t }), this.storageCtx = e ? new B({ storage: e }) : void 0, this.contactCtx = new O({
|
|
636
600
|
api: this.api,
|
|
637
|
-
config: this.config
|
|
638
|
-
|
|
601
|
+
config: this.config,
|
|
602
|
+
storageCtx: this.storageCtx
|
|
603
|
+
}), this.sessionCtx = new _({
|
|
639
604
|
config: this.config,
|
|
640
605
|
api: this.api,
|
|
641
606
|
contactCtx: this.contactCtx
|
|
642
|
-
}), this.messageCtx = new
|
|
607
|
+
}), this.messageCtx = new L({
|
|
643
608
|
config: this.config,
|
|
644
609
|
api: this.api,
|
|
645
610
|
sessionCtx: this.sessionCtx
|
|
646
|
-
}), this.routerCtx = new
|
|
611
|
+
}), this.routerCtx = new D({
|
|
647
612
|
contactCtx: this.contactCtx,
|
|
648
613
|
sessionCtx: this.sessionCtx,
|
|
649
614
|
resetChat: this.resetChat
|
|
@@ -651,7 +616,7 @@ class V {
|
|
|
651
616
|
}
|
|
652
617
|
}
|
|
653
618
|
export {
|
|
654
|
-
|
|
655
|
-
|
|
619
|
+
g as P,
|
|
620
|
+
j as W
|
|
656
621
|
};
|
|
657
|
-
//# sourceMappingURL=widget.ctx-
|
|
622
|
+
//# sourceMappingURL=widget.ctx-D0ExFLNH.js.map
|