@opencx/widget 3.0.18 → 3.0.20
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 +69 -69
- package/dist/designs.cjs.map +1 -1
- package/dist/designs.js +36084 -36102
- 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.js +2 -2
- package/dist/src/designs/react/components/BotOrAgentMessage.d.ts +2 -8
- package/dist/src/designs/react/components/{Text.component.d.ts → BotOrAgentTextResponse.d.ts} +1 -2
- package/dist/src/headless/core/context/message.ctx.d.ts +1 -1
- package/dist/src/headless/core/context/session.ctx.d.ts +9 -3
- package/dist/src/headless/core/index.d.ts +1 -1
- package/dist/src/headless/core/sdk/schema.d.ts +2 -6
- package/dist/src/headless/core/types/messages.d.ts +15 -8
- package/dist/src/headless/react/ComponentRegistry.d.ts +1 -2
- package/dist/src/headless/react/hooks/useSessions.d.ts +0 -1
- package/dist/src/headless/react/types/components.d.ts +1 -1
- package/dist/{useUploadFiles-DnInAFaL.cjs → useUploadFiles-B_VNoYPj.cjs} +3 -3
- package/dist/{useUploadFiles-DnInAFaL.cjs.map → useUploadFiles-B_VNoYPj.cjs.map} +1 -1
- package/dist/{useUploadFiles-Bw5PXhkI.js → useUploadFiles-CwIcQTwm.js} +89 -97
- package/dist/{useUploadFiles-Bw5PXhkI.js.map → useUploadFiles-CwIcQTwm.js.map} +1 -1
- package/dist/widget.ctx-DoLfq9VQ.cjs +2 -0
- package/dist/widget.ctx-DoLfq9VQ.cjs.map +1 -0
- package/dist/{widget.ctx-m7KQtnuH.js → widget.ctx-naCIXuET.js} +153 -133
- package/dist/widget.ctx-naCIXuET.js.map +1 -0
- package/dist-embed/script.js +113 -113
- package/dist-embed/script.js.map +1 -1
- package/package.json +1 -1
- package/dist/widget.ctx-BXzbhG8U.cjs +0 -2
- package/dist/widget.ctx-BXzbhG8U.cjs.map +0 -1
- package/dist/widget.ctx-m7KQtnuH.js.map +0 -1
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
throw TypeError(
|
|
1
|
+
var L = Object.defineProperty;
|
|
2
|
+
var M = (n) => {
|
|
3
|
+
throw TypeError(n);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var s = (
|
|
7
|
-
var h = (
|
|
5
|
+
var O = (n, t, e) => t in n ? L(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
6
|
+
var s = (n, t, e) => O(n, typeof t != "symbol" ? t + "" : t, e), R = (n, t, e) => t.has(n) || M("Cannot " + e);
|
|
7
|
+
var h = (n, t, e) => (R(n, t, "read from private field"), e ? e.call(n) : t.get(n)), P = (n, t, e) => t.has(n) ? M("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(n) : t.set(n, e), C = (n, t, e, i) => (R(n, t, "write to private field"), i ? i.call(n, e) : t.set(n, e), e);
|
|
8
8
|
import T from "axios";
|
|
9
9
|
import E from "openapi-fetch";
|
|
10
10
|
import D from "lodash.isequal";
|
|
11
|
-
import { v4 as
|
|
12
|
-
const q = (
|
|
13
|
-
console.log(
|
|
14
|
-
},
|
|
11
|
+
import { v4 as B } from "uuid";
|
|
12
|
+
const q = (n) => {
|
|
13
|
+
console.log(n.error);
|
|
14
|
+
}, _ = (n) => {
|
|
15
15
|
const t = E({
|
|
16
|
-
baseUrl:
|
|
16
|
+
baseUrl: n.baseUrl
|
|
17
17
|
}), e = {
|
|
18
|
-
onRequest:
|
|
19
|
-
onResponse:
|
|
20
|
-
onError:
|
|
18
|
+
onRequest: n.onRequest,
|
|
19
|
+
onResponse: n.onResponse,
|
|
20
|
+
onError: n.onError || q
|
|
21
21
|
};
|
|
22
22
|
return t.use(e), t;
|
|
23
23
|
};
|
|
@@ -40,11 +40,11 @@ class H {
|
|
|
40
40
|
s(this, "createOpenAPIClient", ({
|
|
41
41
|
baseUrl: t,
|
|
42
42
|
headers: e
|
|
43
|
-
}) =>
|
|
43
|
+
}) => _({
|
|
44
44
|
baseUrl: t,
|
|
45
45
|
onRequest: ({ request: i }) => {
|
|
46
|
-
Object.entries(e).forEach(([
|
|
47
|
-
r && i.headers.set(
|
|
46
|
+
Object.entries(e).forEach(([a, r]) => {
|
|
47
|
+
r && i.headers.set(a, r);
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
}));
|
|
@@ -71,10 +71,10 @@ class H {
|
|
|
71
71
|
lastMessageTimestamp: e,
|
|
72
72
|
abortSignal: i
|
|
73
73
|
}) => {
|
|
74
|
-
const
|
|
74
|
+
const a = e ? { lastMessageTimestamp: e } : void 0;
|
|
75
75
|
return await this.client.GET(
|
|
76
76
|
"/backend/widget/v2/session/history/{sessionId}",
|
|
77
|
-
{ params: { path: { sessionId: t }, query:
|
|
77
|
+
{ params: { path: { sessionId: t }, query: a }, signal: i }
|
|
78
78
|
);
|
|
79
79
|
});
|
|
80
80
|
s(this, "createUnverifiedContact", async (t) => await this.client.POST(
|
|
@@ -105,42 +105,42 @@ class H {
|
|
|
105
105
|
s(this, "uploadFile", async (t, e = {}) => {
|
|
106
106
|
const i = new FormData();
|
|
107
107
|
i.append("file", t.file);
|
|
108
|
-
const { data:
|
|
108
|
+
const { data: a } = await this.uploadFileClient.post("", i, {
|
|
109
109
|
headers: {
|
|
110
110
|
"Content-Type": "multipart/form-data"
|
|
111
111
|
},
|
|
112
112
|
...e
|
|
113
113
|
});
|
|
114
|
-
return
|
|
114
|
+
return a;
|
|
115
115
|
});
|
|
116
116
|
s(this, "vote", async (t) => await this.client.POST("/backend/widget/v2/chat/vote", { body: t }));
|
|
117
|
-
var
|
|
117
|
+
var a;
|
|
118
118
|
this.config = t;
|
|
119
119
|
const { baseUrl: e, headers: i } = this.constructClientOptions(
|
|
120
|
-
(
|
|
120
|
+
(a = t.user) == null ? void 0 : a.token
|
|
121
121
|
);
|
|
122
122
|
this.client = this.createOpenAPIClient({ baseUrl: e, headers: i }), this.uploadFileClient = this.createAxiosUploadClient({ baseUrl: e, headers: i });
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
var l,
|
|
126
|
-
class
|
|
125
|
+
var l, f;
|
|
126
|
+
class p {
|
|
127
127
|
constructor(t) {
|
|
128
128
|
s(this, "subscribers", /* @__PURE__ */ new Set());
|
|
129
129
|
P(this, l);
|
|
130
130
|
s(this, "initialState");
|
|
131
|
-
P(this,
|
|
131
|
+
P(this, f);
|
|
132
132
|
s(this, "lifecycleListeners", /* @__PURE__ */ new Map());
|
|
133
133
|
s(this, "emitLifecycle", (t, e) => {
|
|
134
134
|
const i = this.lifecycleListeners.get(t);
|
|
135
135
|
if (i) {
|
|
136
|
-
const
|
|
136
|
+
const a = {
|
|
137
137
|
type: t,
|
|
138
138
|
timestamp: Date.now(),
|
|
139
139
|
data: e
|
|
140
140
|
};
|
|
141
141
|
i.forEach((r) => {
|
|
142
142
|
try {
|
|
143
|
-
r(
|
|
143
|
+
r(a);
|
|
144
144
|
} catch {
|
|
145
145
|
}
|
|
146
146
|
});
|
|
@@ -150,8 +150,8 @@ class m {
|
|
|
150
150
|
Array.from(this.subscribers).forEach((i) => {
|
|
151
151
|
try {
|
|
152
152
|
i(t);
|
|
153
|
-
} catch (
|
|
154
|
-
this.emitLifecycle("error", { error:
|
|
153
|
+
} catch (a) {
|
|
154
|
+
this.emitLifecycle("error", { error: a });
|
|
155
155
|
}
|
|
156
156
|
});
|
|
157
157
|
});
|
|
@@ -181,7 +181,7 @@ class m {
|
|
|
181
181
|
this.emitLifecycle("beforeUpdate", {
|
|
182
182
|
previousState: h(this, l),
|
|
183
183
|
nextState: t
|
|
184
|
-
}), D(h(this, l), t) || (
|
|
184
|
+
}), D(h(this, l), t) || (C(this, l, t), C(this, f, Date.now()), this.emitLifecycle("stateChange", { state: t }), this.notifySubscribers(t)), this.emitLifecycle("afterUpdate", { state: t });
|
|
185
185
|
});
|
|
186
186
|
// TODO make this provide prev state
|
|
187
187
|
s(this, "setPartial", (t) => {
|
|
@@ -201,11 +201,11 @@ class m {
|
|
|
201
201
|
s(this, "reset", () => {
|
|
202
202
|
this.set(this.initialState);
|
|
203
203
|
});
|
|
204
|
-
s(this, "lastUpdated", () => h(this,
|
|
205
|
-
|
|
204
|
+
s(this, "lastUpdated", () => h(this, f));
|
|
205
|
+
C(this, l, t), this.initialState = t, C(this, f, Date.now()), this.emitLifecycle("init", { initialState: h(this, l) });
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
-
l = new WeakMap(),
|
|
208
|
+
l = new WeakMap(), f = new WeakMap();
|
|
209
209
|
class G {
|
|
210
210
|
constructor({
|
|
211
211
|
config: t,
|
|
@@ -219,10 +219,10 @@ class G {
|
|
|
219
219
|
return !!(!((e = this.state.get().contact) != null && e.token) && this.config.collectUserData);
|
|
220
220
|
});
|
|
221
221
|
s(this, "autoCreateUnverifiedUser", async () => {
|
|
222
|
-
var t, e, i,
|
|
222
|
+
var t, e, i, a;
|
|
223
223
|
await this.createUnverifiedContact({
|
|
224
224
|
name: ((e = (t = this.config.user) == null ? void 0 : t.data) == null ? void 0 : e.name) || "Anonymous",
|
|
225
|
-
email: (
|
|
225
|
+
email: (a = (i = this.config.user) == null ? void 0 : i.data) == null ? void 0 : a.email
|
|
226
226
|
});
|
|
227
227
|
});
|
|
228
228
|
s(this, "createUnverifiedContact", async (t) => {
|
|
@@ -237,17 +237,17 @@ class G {
|
|
|
237
237
|
this.state.setPartial({ isCreatingUnverifiedContact: !1 });
|
|
238
238
|
}
|
|
239
239
|
});
|
|
240
|
-
var i,
|
|
241
|
-
this.config = t, this.api = e, this.state = new
|
|
242
|
-
contact: (i = t.user) != null && i.token ? { token: (
|
|
240
|
+
var i, a, r;
|
|
241
|
+
this.config = t, this.api = e, this.state = new p({
|
|
242
|
+
contact: (i = t.user) != null && i.token ? { token: (a = t.user) == null ? void 0 : a.token } : null,
|
|
243
243
|
isCreatingUnverifiedContact: !1,
|
|
244
244
|
isErrorCreatingUnverifiedContact: !1
|
|
245
245
|
}), !((r = t.user) != null && r.token) && !t.collectUserData && this.autoCreateUnverifiedUser();
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
|
-
class
|
|
248
|
+
class v {
|
|
249
249
|
constructor() {
|
|
250
|
-
s(this, "state", new
|
|
250
|
+
s(this, "state", new p({
|
|
251
251
|
isPolling: !1,
|
|
252
252
|
isError: !1
|
|
253
253
|
}));
|
|
@@ -259,7 +259,7 @@ class k {
|
|
|
259
259
|
s(this, "stopPolling", null);
|
|
260
260
|
s(this, "startPolling", (t, e) => {
|
|
261
261
|
if (this.stopPolling) return;
|
|
262
|
-
const i = [],
|
|
262
|
+
const i = [], a = async () => {
|
|
263
263
|
this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
|
|
264
264
|
try {
|
|
265
265
|
await t(this.abortController.signal);
|
|
@@ -270,16 +270,16 @@ class k {
|
|
|
270
270
|
} finally {
|
|
271
271
|
this.state.setPartial({ isPolling: !1 });
|
|
272
272
|
}
|
|
273
|
-
this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") : i.push(setTimeout(
|
|
273
|
+
this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") : i.push(setTimeout(a, e));
|
|
274
274
|
};
|
|
275
|
-
|
|
275
|
+
a(), this.stopPolling = () => {
|
|
276
276
|
i.forEach(clearTimeout), this.state.reset();
|
|
277
277
|
};
|
|
278
278
|
});
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
function y() {
|
|
282
|
-
return
|
|
282
|
+
return B();
|
|
283
283
|
}
|
|
284
284
|
class j {
|
|
285
285
|
constructor({
|
|
@@ -290,12 +290,13 @@ class j {
|
|
|
290
290
|
s(this, "config");
|
|
291
291
|
s(this, "api");
|
|
292
292
|
s(this, "contactCtx");
|
|
293
|
-
s(this, "
|
|
294
|
-
s(this, "
|
|
293
|
+
s(this, "activeSessionPoller", new v());
|
|
294
|
+
s(this, "sessionsRefresher", new v());
|
|
295
|
+
s(this, "sessionState", new p({
|
|
295
296
|
session: null,
|
|
296
297
|
isCreatingSession: !1
|
|
297
298
|
}));
|
|
298
|
-
s(this, "sessionsState", new
|
|
299
|
+
s(this, "sessionsState", new p({
|
|
299
300
|
data: [],
|
|
300
301
|
cursor: void 0,
|
|
301
302
|
isLastPage: !1,
|
|
@@ -307,17 +308,17 @@ class j {
|
|
|
307
308
|
}));
|
|
308
309
|
/** Clears the session and stops polling */
|
|
309
310
|
s(this, "reset", async () => {
|
|
310
|
-
this.sessionState.reset(), this.
|
|
311
|
+
this.sessionState.reset(), this.activeSessionPoller.reset();
|
|
311
312
|
});
|
|
312
|
-
s(this, "
|
|
313
|
+
s(this, "registerActiveSessionPolling", () => {
|
|
313
314
|
this.sessionState.subscribe(({ session: t }) => {
|
|
314
|
-
t != null && t.id ? this.
|
|
315
|
+
t != null && t.id ? this.activeSessionPoller.startPolling(async (e) => {
|
|
315
316
|
const { data: i } = await this.api.getSession({
|
|
316
317
|
sessionId: t.id,
|
|
317
318
|
abortSignal: e
|
|
318
319
|
});
|
|
319
320
|
i && this.sessionState.setPartial({ session: i });
|
|
320
|
-
}, 1e3) : this.
|
|
321
|
+
}, 1e3) : this.activeSessionPoller.reset();
|
|
321
322
|
});
|
|
322
323
|
});
|
|
323
324
|
s(this, "registerInitialSessionsFetch", () => {
|
|
@@ -325,44 +326,62 @@ class j {
|
|
|
325
326
|
const t = async () => {
|
|
326
327
|
this.sessionsState.setPartial({ didStartInitialFetch: !0 }), await this.loadMoreSessions(), this.sessionsState.setPartial({ isInitialFetchLoading: !1 });
|
|
327
328
|
};
|
|
328
|
-
(e = this.contactCtx.state.get().contact) != null && e.token && !this.sessionsState.get().didStartInitialFetch && t(), this.contactCtx.state.subscribe(({ contact: i }) => {
|
|
329
|
-
i != null && i.token && !this.sessionsState.get().didStartInitialFetch && t();
|
|
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());
|
|
330
331
|
});
|
|
331
332
|
});
|
|
333
|
+
s(this, "registerSessionsRefresher", () => {
|
|
334
|
+
this.sessionsRefresher.startPolling(async () => {
|
|
335
|
+
const { data: t } = await this.getSessions({ cursor: void 0 });
|
|
336
|
+
if (!t) return;
|
|
337
|
+
const e = [...t.items, ...this.sessionsState.get().data].filter(
|
|
338
|
+
(i, a, r) => a === r.findIndex((c) => i.id === c.id)
|
|
339
|
+
);
|
|
340
|
+
this.sessionsState.setPartial({ data: e });
|
|
341
|
+
}, 1e4);
|
|
342
|
+
});
|
|
332
343
|
s(this, "createSession", async () => {
|
|
333
|
-
var i,
|
|
344
|
+
var i, a;
|
|
334
345
|
this.sessionState.setPartial({ session: null, isCreatingSession: !0 });
|
|
335
346
|
const { data: t, error: e } = await this.api.createSession({
|
|
336
347
|
customData: (i = this.config.user) != null && i.externalId ? {
|
|
337
|
-
external_id: (
|
|
348
|
+
external_id: (a = this.config.user) == null ? void 0 : a.externalId
|
|
338
349
|
} : void 0
|
|
339
350
|
});
|
|
340
351
|
return t ? (this.sessionState.setPartial({ session: t, isCreatingSession: !1 }), t) : (console.error("Failed to create session:", e), null);
|
|
341
352
|
});
|
|
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
|
+
*/
|
|
342
356
|
s(this, "loadMoreSessions", async () => {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
cursor: this.sessionsState.get().cursor,
|
|
347
|
-
filters: (i = this.config.user) != null && i.externalId ? {
|
|
348
|
-
external_id: this.config.user.externalId
|
|
349
|
-
} : {}
|
|
357
|
+
if (this.sessionsState.get().isLastPage) return;
|
|
358
|
+
const { data: t } = await this.getSessions({
|
|
359
|
+
cursor: this.sessionsState.get().cursor
|
|
350
360
|
});
|
|
351
361
|
if (t) {
|
|
352
|
-
const
|
|
353
|
-
(
|
|
362
|
+
const i = [...this.sessionsState.get().data, ...t.items].filter(
|
|
363
|
+
(a, r, c) => r === c.findIndex((d) => a.id === d.id)
|
|
354
364
|
);
|
|
355
365
|
this.sessionsState.setPartial({
|
|
356
|
-
data:
|
|
366
|
+
data: i,
|
|
357
367
|
cursor: t.next || void 0,
|
|
358
368
|
isLastPage: t.next === null
|
|
359
369
|
});
|
|
360
370
|
}
|
|
361
371
|
});
|
|
362
|
-
this
|
|
372
|
+
s(this, "getSessions", async ({ cursor: t }) => {
|
|
373
|
+
var e, i;
|
|
374
|
+
return (e = this.contactCtx.state.get().contact) != null && e.token ? await this.api.getSessions({
|
|
375
|
+
cursor: t,
|
|
376
|
+
filters: (i = this.config.user) != null && i.externalId ? {
|
|
377
|
+
external_id: this.config.user.externalId
|
|
378
|
+
} : {}
|
|
379
|
+
}) : { data: null };
|
|
380
|
+
});
|
|
381
|
+
this.config = t, this.api = e, this.contactCtx = i, this.registerActiveSessionPolling(), this.registerInitialSessionsFetch();
|
|
363
382
|
}
|
|
364
383
|
}
|
|
365
|
-
class
|
|
384
|
+
class u {
|
|
366
385
|
constructor({
|
|
367
386
|
config: t,
|
|
368
387
|
api: e,
|
|
@@ -371,8 +390,8 @@ class p {
|
|
|
371
390
|
s(this, "config");
|
|
372
391
|
s(this, "api");
|
|
373
392
|
s(this, "sessionCtx");
|
|
374
|
-
s(this, "poller", new
|
|
375
|
-
s(this, "state", new
|
|
393
|
+
s(this, "poller", new v());
|
|
394
|
+
s(this, "state", new p({
|
|
376
395
|
messages: [],
|
|
377
396
|
isSendingMessage: !1,
|
|
378
397
|
lastAIResMightSolveUserIssue: !1,
|
|
@@ -390,9 +409,9 @@ class p {
|
|
|
390
409
|
});
|
|
391
410
|
});
|
|
392
411
|
s(this, "sendMessage", async (t) => {
|
|
393
|
-
var
|
|
412
|
+
var a, r, c, d, S, m, x, U, A;
|
|
394
413
|
this.sendMessageAbortController = new AbortController();
|
|
395
|
-
const e = this.state.get().isSendingMessage, i = ((
|
|
414
|
+
const e = this.state.get().isSendingMessage, i = ((a = this.sessionCtx.sessionState.get().session) == null ? void 0 : a.assignee.kind) === "ai";
|
|
396
415
|
if (e && i) {
|
|
397
416
|
console.warn("Cannot send messages while awaiting AI response");
|
|
398
417
|
return;
|
|
@@ -400,12 +419,12 @@ class p {
|
|
|
400
419
|
this.state.setPartial({ lastAIResMightSolveUserIssue: !1 });
|
|
401
420
|
try {
|
|
402
421
|
this.state.setPartial({ isSendingMessage: !0 });
|
|
403
|
-
const b =
|
|
422
|
+
const b = u.toUserMessage(
|
|
404
423
|
t.content,
|
|
405
424
|
t.attachments || void 0
|
|
406
|
-
),
|
|
425
|
+
), k = this.state.get().messages;
|
|
407
426
|
if (this.state.setPartial({
|
|
408
|
-
messages: [...
|
|
427
|
+
messages: [...k, b]
|
|
409
428
|
}), !((r = this.sessionCtx.sessionState.get().session) != null && r.id) && !await this.sessionCtx.createSession()) {
|
|
410
429
|
console.error("Failed to create session");
|
|
411
430
|
return;
|
|
@@ -425,28 +444,28 @@ class p {
|
|
|
425
444
|
this.sendMessageAbortController.signal
|
|
426
445
|
);
|
|
427
446
|
if (o != null && o.success) {
|
|
428
|
-
const
|
|
429
|
-
if (
|
|
447
|
+
const g = u.toBotMessage(o);
|
|
448
|
+
if (g) {
|
|
430
449
|
const w = this.state.get().messages;
|
|
431
450
|
if (!!w.some(
|
|
432
|
-
(F) => F.id ===
|
|
451
|
+
(F) => F.id === g.id
|
|
433
452
|
)) {
|
|
434
453
|
this.state.setPartial({
|
|
435
|
-
lastAIResMightSolveUserIssue: ((
|
|
454
|
+
lastAIResMightSolveUserIssue: ((S = o.autopilotResponse) == null ? void 0 : S.mightSolveUserIssue) || ((m = o.uiResponse) == null ? void 0 : m.mightSolveUserIssue)
|
|
436
455
|
});
|
|
437
456
|
return;
|
|
438
457
|
}
|
|
439
458
|
this.state.setPartial({
|
|
440
|
-
messages: [...w,
|
|
441
|
-
lastAIResMightSolveUserIssue: ((x = o.autopilotResponse) == null ? void 0 : x.mightSolveUserIssue) || ((
|
|
459
|
+
messages: [...w, g],
|
|
460
|
+
lastAIResMightSolveUserIssue: ((x = o.autopilotResponse) == null ? void 0 : x.mightSolveUserIssue) || ((U = o.uiResponse) == null ? void 0 : U.mightSolveUserIssue)
|
|
442
461
|
});
|
|
443
462
|
}
|
|
444
463
|
} else {
|
|
445
|
-
const
|
|
446
|
-
((
|
|
464
|
+
const g = u.toBotErrorMessage(
|
|
465
|
+
((A = o == null ? void 0 : o.error) == null ? void 0 : A.message) || "Unknown error occurred"
|
|
447
466
|
), w = this.state.get().messages;
|
|
448
467
|
this.state.setPartial({
|
|
449
|
-
messages: [...w,
|
|
468
|
+
messages: [...w, g]
|
|
450
469
|
});
|
|
451
470
|
}
|
|
452
471
|
} catch (b) {
|
|
@@ -458,14 +477,14 @@ class p {
|
|
|
458
477
|
s(this, "fetchAndSetHistory", async (t, e) => {
|
|
459
478
|
var r;
|
|
460
479
|
this.state.get().messages.length === 0 && this.state.setPartial({ isInitialFetchLoading: !0 });
|
|
461
|
-
const i = (r = this.state.get().messages.at(-1)) == null ? void 0 : r.timestamp, { data:
|
|
480
|
+
const i = (r = this.state.get().messages.at(-1)) == null ? void 0 : r.timestamp, { data: a } = await this.api.getSessionHistory({
|
|
462
481
|
sessionId: t,
|
|
463
482
|
lastMessageTimestamp: i,
|
|
464
483
|
abortSignal: e
|
|
465
484
|
});
|
|
466
|
-
if (
|
|
467
|
-
const c = this.state.get().messages, d =
|
|
468
|
-
(
|
|
485
|
+
if (a && a.length > 0) {
|
|
486
|
+
const c = this.state.get().messages, d = a.map(u.mapHistoryToMessage).filter(
|
|
487
|
+
(S) => !c.some((m) => m.id === S.id)
|
|
469
488
|
);
|
|
470
489
|
this.state.setPartial({
|
|
471
490
|
messages: [...c, ...d]
|
|
@@ -477,24 +496,30 @@ class p {
|
|
|
477
496
|
}
|
|
478
497
|
/** Not the best name but whatever */
|
|
479
498
|
static mapHistoryToMessage(t) {
|
|
499
|
+
var a;
|
|
480
500
|
const e = {
|
|
481
501
|
id: t.publicId,
|
|
482
502
|
timestamp: t.sentAt || "",
|
|
483
503
|
attachments: t.attachments || void 0
|
|
484
504
|
};
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
505
|
+
if (t.sender.kind === "user")
|
|
506
|
+
return {
|
|
507
|
+
...e,
|
|
508
|
+
type: "FROM_USER",
|
|
509
|
+
content: t.content.text || "",
|
|
510
|
+
deliveredAt: t.sentAt || ""
|
|
511
|
+
};
|
|
512
|
+
if (t.sender.kind === "agent")
|
|
513
|
+
return {
|
|
514
|
+
...e,
|
|
515
|
+
type: "FROM_AGENT",
|
|
516
|
+
component: "agent_message",
|
|
517
|
+
data: {
|
|
518
|
+
message: t.content.text || ""
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
const i = (a = t.actionCalls) == null ? void 0 : a.at(-1);
|
|
522
|
+
return {
|
|
498
523
|
...e,
|
|
499
524
|
type: "FROM_BOT",
|
|
500
525
|
component: "bot_message",
|
|
@@ -505,7 +530,8 @@ class p {
|
|
|
505
530
|
avatar: t.sender.avatar || null
|
|
506
531
|
},
|
|
507
532
|
data: {
|
|
508
|
-
message: t.content.text
|
|
533
|
+
message: t.content.text || "",
|
|
534
|
+
action: i ? { name: i.actionName, data: i.result } : void 0
|
|
509
535
|
}
|
|
510
536
|
};
|
|
511
537
|
}
|
|
@@ -520,29 +546,22 @@ class p {
|
|
|
520
546
|
};
|
|
521
547
|
}
|
|
522
548
|
static toBotMessage(t) {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
id: y(),
|
|
538
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
539
|
-
component: e.name,
|
|
540
|
-
data: e.request_response
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
return null;
|
|
549
|
+
var e;
|
|
550
|
+
return t.success && t.autopilotResponse ? {
|
|
551
|
+
type: "FROM_BOT",
|
|
552
|
+
id: t.autopilotResponse.id || y(),
|
|
553
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
554
|
+
component: "bot_message",
|
|
555
|
+
data: {
|
|
556
|
+
message: t.autopilotResponse.value.content,
|
|
557
|
+
action: (e = t.uiResponse) != null && e.value.name ? {
|
|
558
|
+
name: t.uiResponse.value.name,
|
|
559
|
+
data: t.uiResponse.value.request_response
|
|
560
|
+
} : void 0
|
|
561
|
+
}
|
|
562
|
+
} : null;
|
|
544
563
|
}
|
|
545
|
-
static
|
|
564
|
+
static toBotErrorMessage(t) {
|
|
546
565
|
return {
|
|
547
566
|
type: "FROM_BOT",
|
|
548
567
|
id: y(),
|
|
@@ -550,12 +569,13 @@ class p {
|
|
|
550
569
|
component: "TEXT",
|
|
551
570
|
data: {
|
|
552
571
|
message: t,
|
|
553
|
-
variant: "error"
|
|
572
|
+
variant: "error",
|
|
573
|
+
action: void 0
|
|
554
574
|
}
|
|
555
575
|
};
|
|
556
576
|
}
|
|
557
577
|
}
|
|
558
|
-
class
|
|
578
|
+
class N {
|
|
559
579
|
constructor({
|
|
560
580
|
contactCtx: t,
|
|
561
581
|
sessionCtx: e,
|
|
@@ -584,12 +604,12 @@ class X {
|
|
|
584
604
|
}
|
|
585
605
|
this.state.setPartial({ screen: "chat" });
|
|
586
606
|
});
|
|
587
|
-
this.state = new
|
|
607
|
+
this.state = new p({
|
|
588
608
|
screen: t.shouldCollectData() ? "welcome" : "sessions"
|
|
589
609
|
}), this.contactCtx = t, this.sessionCtx = e, this.resetChat = i, this.registerRoutingListener();
|
|
590
610
|
}
|
|
591
611
|
}
|
|
592
|
-
class
|
|
612
|
+
class Q {
|
|
593
613
|
constructor({ config: t }) {
|
|
594
614
|
s(this, "config");
|
|
595
615
|
s(this, "api");
|
|
@@ -607,11 +627,11 @@ class K {
|
|
|
607
627
|
config: this.config,
|
|
608
628
|
api: this.api,
|
|
609
629
|
contactCtx: this.contactCtx
|
|
610
|
-
}), this.messageCtx = new
|
|
630
|
+
}), this.messageCtx = new u({
|
|
611
631
|
config: this.config,
|
|
612
632
|
api: this.api,
|
|
613
633
|
sessionCtx: this.sessionCtx
|
|
614
|
-
}), this.routerCtx = new
|
|
634
|
+
}), this.routerCtx = new N({
|
|
615
635
|
contactCtx: this.contactCtx,
|
|
616
636
|
sessionCtx: this.sessionCtx,
|
|
617
637
|
resetChat: this.resetChat
|
|
@@ -619,7 +639,7 @@ class K {
|
|
|
619
639
|
}
|
|
620
640
|
}
|
|
621
641
|
export {
|
|
622
|
-
|
|
623
|
-
|
|
642
|
+
p as P,
|
|
643
|
+
Q as W
|
|
624
644
|
};
|
|
625
|
-
//# sourceMappingURL=widget.ctx-
|
|
645
|
+
//# sourceMappingURL=widget.ctx-naCIXuET.js.map
|