@opencx/widget 3.0.49 → 3.0.51

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.
@@ -1,25 +1,24 @@
1
- import F from "axios";
2
1
  import O from "openapi-fetch";
3
- import _ from "lodash.isequal";
4
- import { v4 as R } from "uuid";
5
- const D = (h) => {
6
- console.log(h.error);
7
- }, L = (h) => {
2
+ import F from "lodash.isequal";
3
+ import { v4 as A } from "uuid";
4
+ const L = (g) => {
5
+ console.log(g.error);
6
+ }, B = (g) => {
8
7
  const n = O({
9
- baseUrl: h.baseUrl
8
+ baseUrl: g.baseUrl
10
9
  }), i = {
11
- onRequest: h.onRequest,
12
- onResponse: h.onResponse,
13
- onError: h.onError || D
10
+ onRequest: g.onRequest,
11
+ onResponse: g.onResponse,
12
+ onError: g.onError || L
14
13
  };
15
14
  return n.use(i), n;
16
15
  };
17
- class k {
16
+ class E {
18
17
  constructor({
19
18
  config: n
20
19
  }) {
21
20
  var a;
22
- this.constructClientOptions = (t) => {
21
+ this.userToken = null, this.constructClientOptions = (t) => {
23
22
  const s = this.config.apiUrl || "https://api.open.cx", e = {
24
23
  "X-Bot-Token": this.config.token,
25
24
  "Content-Type": "application/json",
@@ -30,22 +29,17 @@ class k {
30
29
  }, this.createOpenAPIClient = ({
31
30
  baseUrl: t,
32
31
  headers: s
33
- }) => L({
32
+ }) => B({
34
33
  baseUrl: t,
35
34
  onRequest: ({ request: e }) => {
36
- Object.entries(s).forEach(([o, l]) => {
37
- l && e.headers.set(o, l);
35
+ Object.entries(s).forEach(([o, r]) => {
36
+ r && e.headers.set(o, r);
38
37
  });
39
38
  }
40
- }), this.createAxiosUploadClient = ({
41
- baseUrl: t,
42
- headers: s
43
- }) => F.create({
44
- baseURL: `${t}/backend/widget/v2/upload`,
45
- headers: s
46
39
  }), this.setAuthToken = (t) => {
40
+ this.userToken = t;
47
41
  const { baseUrl: s, headers: e } = this.constructClientOptions(t);
48
- this.client = this.createOpenAPIClient({ baseUrl: s, headers: e }), this.uploadFileClient = this.createAxiosUploadClient({ baseUrl: s, headers: e });
42
+ this.client = this.createOpenAPIClient({ baseUrl: s, headers: e });
49
43
  }, this.getExternalWidgetConfig = async () => await this.client.GET("/backend/widget/v2/config", {
50
44
  params: { header: { "X-Bot-Token": this.config.token } }
51
45
  }), this.widgetPrelude = async () => await this.client.GET("/backend/widget/v2/prelude", {
@@ -78,31 +72,57 @@ class k {
78
72
  }) => await this.client.GET("/backend/widget/v2/sessions", {
79
73
  params: { query: { cursor: t, filters: JSON.stringify(s) } },
80
74
  signal: e
81
- }), this.uploadFile = async (t, s = {}) => {
82
- const e = new FormData();
83
- e.append("file", t.file);
84
- const { data: o } = await this.uploadFileClient.post("", e, {
85
- headers: {
86
- "Content-Type": "multipart/form-data"
87
- },
88
- ...s
75
+ }), this.uploadFile = async ({
76
+ file: t,
77
+ abortSignal: s,
78
+ onProgress: e
79
+ }) => new Promise((o, r) => {
80
+ const l = new FormData();
81
+ l.append("file", t);
82
+ const c = new XMLHttpRequest();
83
+ if (s && (s.addEventListener("abort", () => {
84
+ c.abort(), r(new DOMException("Aborted", "AbortError"));
85
+ }), s.aborted)) {
86
+ r(new DOMException("Aborted", "AbortError"));
87
+ return;
88
+ }
89
+ c.upload.addEventListener("progress", (d) => {
90
+ if (d.lengthComputable && e) {
91
+ const x = Math.round(d.loaded / d.total * 100);
92
+ e(x);
93
+ }
94
+ }), c.addEventListener("load", () => {
95
+ if (c.status >= 200 && c.status < 300)
96
+ try {
97
+ const d = JSON.parse(c.responseText);
98
+ o(d);
99
+ } catch (d) {
100
+ r(new Error(`Failed to parse response: ${d}`));
101
+ }
102
+ else
103
+ r(new Error(`Upload failed with status: ${c.status}`));
104
+ }), c.addEventListener("error", () => {
105
+ r(new Error("Network error occurred"));
106
+ }), c.addEventListener("timeout", () => {
107
+ r(new Error("Upload timed out"));
89
108
  });
90
- return o;
91
- }, this.vote = async (t) => await this.client.POST("/backend/widget/v2/chat/vote", { body: t }), this.config = n;
92
- const { baseUrl: i, headers: c } = this.constructClientOptions(
109
+ const { baseUrl: f } = this.constructClientOptions(this.userToken), C = `${f}/backend/widget/v2/upload`;
110
+ c.open("POST", C), c.setRequestHeader("X-Bot-Token", this.config.token), this.userToken && c.setRequestHeader("Authorization", `Bearer ${this.userToken}`), c.send(l);
111
+ }), this.vote = async (t) => await this.client.POST("/backend/widget/v2/chat/vote", { body: t }), this.config = n;
112
+ const { baseUrl: i, headers: h } = this.constructClientOptions(
93
113
  (a = n.user) == null ? void 0 : a.token
94
114
  );
95
- this.client = this.createOpenAPIClient({ baseUrl: i, headers: c }), this.uploadFileClient = this.createAxiosUploadClient({ baseUrl: i, headers: c });
115
+ this.client = this.createOpenAPIClient({ baseUrl: i, headers: h });
96
116
  }
97
117
  }
98
- class v {
118
+ class b {
99
119
  constructor(n) {
100
120
  this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (i) => {
101
- _(this.state, i) || (this.state = i, this.notifySubscribers(i));
121
+ F(this.state, i) || (this.state = i, this.notifySubscribers(i));
102
122
  }, this.setPartial = (i) => {
103
123
  if (i == null) return;
104
- const c = { ...this.state, ...i };
105
- this.set(c);
124
+ const h = { ...this.state, ...i };
125
+ this.set(h);
106
126
  }, this.reset = () => {
107
127
  this.set(this.initialState);
108
128
  }, this.notifySubscribers = (i) => {
@@ -118,9 +138,9 @@ class v {
118
138
  }), this.state = n, this.initialState = n;
119
139
  }
120
140
  }
121
- class M {
141
+ class T {
122
142
  constructor() {
123
- this.state = new v({
143
+ this.state = new b({
124
144
  isPolling: !1,
125
145
  isError: !1
126
146
  }), this.abortController = new AbortController(), this.reset = () => {
@@ -128,7 +148,7 @@ class M {
128
148
  this.abortController.abort("Resetting poller"), (n = this.stopPolling) == null || n.call(this), this.stopPolling = null;
129
149
  }, this.stopPolling = null, this.startPolling = (n, i) => {
130
150
  if (this.stopPolling) return;
131
- const c = [], a = async () => {
151
+ const h = [], a = async () => {
132
152
  this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
133
153
  try {
134
154
  await n(this.abortController.signal);
@@ -139,47 +159,55 @@ class M {
139
159
  } finally {
140
160
  this.state.setPartial({ isPolling: !1 });
141
161
  }
142
- this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") : c.push(setTimeout(a, i));
162
+ this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") : h.push(setTimeout(a, i));
143
163
  };
144
164
  a(), this.stopPolling = () => {
145
- c.forEach(clearTimeout), this.state.reset();
165
+ h.forEach(clearTimeout), this.state.reset();
146
166
  };
147
167
  };
148
168
  }
149
169
  }
150
- class B {
170
+ function D(g) {
171
+ try {
172
+ const n = g();
173
+ return n instanceof Promise ? n.then((i) => ({ data: i })).catch((i) => ({ error: i })) : { data: n };
174
+ } catch (n) {
175
+ return { error: n };
176
+ }
177
+ }
178
+ class _ {
151
179
  constructor({
152
180
  api: n,
153
181
  config: i,
154
- sessionCtx: c,
182
+ sessionCtx: h,
155
183
  messageCtx: a,
156
184
  sessionPollingIntervalSeconds: t
157
185
  }) {
158
- this.poller = new M(), this.registerPolling = () => {
186
+ this.poller = new T(), this.registerPolling = () => {
159
187
  this.sessionCtx.sessionState.subscribe(({ session: s }) => {
160
188
  s != null && s.id ? this.poller.startPolling(async (e) => {
161
189
  this.hackAndSlash(s.id, e);
162
190
  }, this.sessionPollingIntervalSeconds * 1e3) : this.poller.reset();
163
191
  });
164
192
  }, this.hackAndSlash = async (s, e) => {
165
- var g;
193
+ var c;
166
194
  this.messageCtx.state.get().messages.length === 0 && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
167
- const o = this.messageCtx.state.get().messages, l = o.length > 0 ? (g = o[o.length - 1]) == null ? void 0 : g.timestamp : void 0, { data: r } = await this.api.pollSessionAndHistory({
195
+ const o = this.messageCtx.state.get().messages, r = o.length > 0 ? (c = o[o.length - 1]) == null ? void 0 : c.timestamp : void 0, { data: l } = await this.api.pollSessionAndHistory({
168
196
  sessionId: s,
169
197
  abortSignal: e,
170
- lastMessageTimestamp: l
198
+ lastMessageTimestamp: r
171
199
  });
172
- if (r != null && r.session && this.sessionCtx.sessionState.setPartial({ session: r.session }), r != null && r.history && r.history.length > 0) {
173
- const f = this.messageCtx.state.get().messages, p = r.history.map(this.mapHistoryToMessage).filter(
174
- (m) => !f.some((S) => S.id === m.id)
200
+ if (l != null && l.session && this.sessionCtx.sessionState.setPartial({ session: l.session }), l != null && l.history && l.history.length > 0) {
201
+ const f = this.messageCtx.state.get().messages, m = l.history.map(this.mapHistoryToMessage).filter(
202
+ (C) => !f.some((d) => d.id === C.id)
175
203
  );
176
204
  this.messageCtx.state.setPartial({
177
- messages: [...f, ...p]
205
+ messages: [...f, ...m]
178
206
  });
179
207
  }
180
208
  this.messageCtx.state.get().isInitialFetchLoading && this.messageCtx.state.setPartial({ isInitialFetchLoading: !1 });
181
209
  }, this.mapHistoryToMessage = (s) => {
182
- var l, r;
210
+ var r, l;
183
211
  const e = {
184
212
  id: s.publicId,
185
213
  timestamp: s.sentAt || "",
@@ -214,48 +242,59 @@ class B {
214
242
  component: "bot_message",
215
243
  agent: {
216
244
  id: null,
217
- name: ((l = this.config.bot) == null ? void 0 : l.name) || "",
245
+ name: ((r = this.config.bot) == null ? void 0 : r.name) || "",
218
246
  isAi: !0,
219
- avatar: ((r = this.config.bot) == null ? void 0 : r.avatar) || ""
247
+ avatar: ((l = this.config.bot) == null ? void 0 : l.avatar) || ""
220
248
  },
221
249
  data: {
222
250
  message: s.content.text || "",
223
- action: o ? { name: o.actionName, data: o.result } : void 0
251
+ action: o ? {
252
+ name: o.actionName,
253
+ data: this.extractActionResult(o)
254
+ } : void 0
224
255
  }
225
256
  };
226
- }, this.api = n, this.config = i, this.sessionCtx = c, this.messageCtx = a, this.sessionPollingIntervalSeconds = t, this.registerPolling();
257
+ }, this.extractActionResult = (s) => {
258
+ const e = s.result;
259
+ if (e === null || typeof e != "object") return e;
260
+ if ("responseBodyText" in e && typeof e.responseBodyText == "string") {
261
+ const o = e.responseBodyText, r = D(() => JSON.parse(o)).data;
262
+ if (r) return r;
263
+ }
264
+ return s.result;
265
+ }, this.api = n, this.config = i, this.sessionCtx = h, this.messageCtx = a, this.sessionPollingIntervalSeconds = t, this.registerPolling();
227
266
  }
228
267
  }
229
268
  class q {
230
269
  constructor({
231
270
  config: n,
232
271
  api: i,
233
- storageCtx: c
272
+ storageCtx: h
234
273
  }) {
235
274
  var a;
236
275
  this.shouldCollectData = () => {
237
276
  var t;
238
277
  return !!(!((t = this.state.get().contact) != null && t.token) && this.config.collectUserData);
239
278
  }, this.autoCreateUnverifiedUserIfNotExists = async () => {
240
- var t, s, e, o, l, r, g, f, p, m, S, b;
279
+ var t, s, e, o, r, l, c, f, m, C, d, x;
241
280
  if (!((t = this.config.user) != null && t.token)) {
242
281
  if (this.config.collectUserData && !((e = (s = this.config.user) == null ? void 0 : s.data) != null && e.email)) {
243
282
  if ((o = this.config.extraDataCollectionFields) != null && o.length)
244
283
  return;
245
- const C = await ((l = this.storageCtx) == null ? void 0 : l.getContactToken());
246
- C && await this.setUnverifiedContact(C);
284
+ const S = await ((r = this.storageCtx) == null ? void 0 : r.getContactToken());
285
+ S && await this.setUnverifiedContact(S);
247
286
  return;
248
287
  }
249
- if (!((g = (r = this.config.user) == null ? void 0 : r.data) != null && g.email)) {
250
- const C = await ((f = this.storageCtx) == null ? void 0 : f.getContactToken());
251
- if (C) {
252
- await this.setUnverifiedContact(C);
288
+ if (!((c = (l = this.config.user) == null ? void 0 : l.data) != null && c.email)) {
289
+ const S = await ((f = this.storageCtx) == null ? void 0 : f.getContactToken());
290
+ if (S) {
291
+ await this.setUnverifiedContact(S);
253
292
  return;
254
293
  }
255
294
  }
256
295
  await this.createUnverifiedContact({
257
- name: ((m = (p = this.config.user) == null ? void 0 : p.data) == null ? void 0 : m.name) || "Anonymous",
258
- email: (b = (S = this.config.user) == null ? void 0 : S.data) == null ? void 0 : b.email
296
+ name: ((C = (m = this.config.user) == null ? void 0 : m.data) == null ? void 0 : C.name) || "Anonymous",
297
+ email: (x = (d = this.config.user) == null ? void 0 : d.data) == null ? void 0 : x.email
259
298
  });
260
299
  }
261
300
  }, this.createUnverifiedContact = async (t, s) => {
@@ -271,10 +310,10 @@ class q {
271
310
  this.state.setPartial({ isCreatingUnverifiedContact: !1 });
272
311
  }
273
312
  }, this.setUnverifiedContact = async (t) => {
274
- var o, l, r, g;
275
- const s = await ((o = this.storageCtx) == null ? void 0 : o.getExternalContactId()), e = ((l = this.config.user) == null ? void 0 : l.externalId) || s || R();
276
- this.api.setAuthToken(t), await ((r = this.storageCtx) == null ? void 0 : r.setContactToken(t)), await ((g = this.storageCtx) == null ? void 0 : g.setExternalContactId(e)), this.state.setPartial({ contact: { token: t, externalId: e } });
277
- }, this.config = n, this.storageCtx = c, this.api = i, this.state = new v({
313
+ var o, r, l, c;
314
+ const s = await ((o = this.storageCtx) == null ? void 0 : o.getExternalContactId()), e = ((r = this.config.user) == null ? void 0 : r.externalId) || s || A();
315
+ this.api.setAuthToken(t), await ((l = this.storageCtx) == null ? void 0 : l.setContactToken(t)), await ((c = this.storageCtx) == null ? void 0 : c.setExternalContactId(e)), this.state.setPartial({ contact: { token: t, externalId: e } });
316
+ }, this.config = n, this.storageCtx = h, this.api = i, this.state = new b({
278
317
  contact: (a = n.user) != null && a.token ? {
279
318
  token: n.user.token,
280
319
  // Set optional externalId from config... not local storage
@@ -287,18 +326,18 @@ class q {
287
326
  }
288
327
  }
289
328
  function I() {
290
- return R();
329
+ return A();
291
330
  }
292
331
  class $ {
293
332
  constructor({
294
333
  api: n,
295
334
  contactCtx: i,
296
- sessionsPollingIntervalSeconds: c
335
+ sessionsPollingIntervalSeconds: h
297
336
  }) {
298
- this.sessionsRefresher = new M(), this.sessionState = new v({
337
+ this.sessionsRefresher = new T(), this.sessionState = new b({
299
338
  session: null,
300
339
  isCreatingSession: !1
301
- }), this.sessionsState = new v({
340
+ }), this.sessionsState = new b({
302
341
  data: [],
303
342
  cursor: void 0,
304
343
  isLastPage: !1,
@@ -335,7 +374,7 @@ class $ {
335
374
  });
336
375
  if (a) {
337
376
  const s = [...this.sessionsState.get().data, ...a.items].filter(
338
- (e, o, l) => o === l.findIndex((r) => e.id === r.id)
377
+ (e, o, r) => o === r.findIndex((l) => e.id === l.id)
339
378
  );
340
379
  this.sessionsState.setPartial({
341
380
  data: s,
@@ -357,20 +396,20 @@ class $ {
357
396
  const { data: a } = await this.getSessions({ cursor: void 0 });
358
397
  if (!a) return;
359
398
  const t = [...a.items, ...this.sessionsState.get().data].filter(
360
- (s, e, o) => e === o.findIndex((l) => s.id === l.id)
399
+ (s, e, o) => e === o.findIndex((r) => s.id === r.id)
361
400
  );
362
401
  this.sessionsState.setPartial({ data: t });
363
- }, this.api = n, this.contactCtx = i, this.sessionsPollingIntervalSeconds = c, this.registerSessionsRefresherWrapper();
402
+ }, this.api = n, this.contactCtx = i, this.sessionsPollingIntervalSeconds = h, this.registerSessionsRefresherWrapper();
364
403
  }
365
404
  }
366
- class j {
405
+ class N {
367
406
  constructor({
368
407
  config: n,
369
408
  api: i,
370
- sessionCtx: c,
409
+ sessionCtx: h,
371
410
  contactCtx: a
372
411
  }) {
373
- this.state = new v({
412
+ this.state = new b({
374
413
  messages: [],
375
414
  isSendingMessage: !1,
376
415
  lastAIResMightSolveUserIssue: !1,
@@ -378,14 +417,14 @@ class j {
378
417
  }), this.sendMessageAbortController = new AbortController(), this.reset = () => {
379
418
  this.sendMessageAbortController.abort("Resetting chat"), this.state.reset();
380
419
  }, this.sendMessage = async (t) => {
381
- var r, g, f, p, m, S, b, C, U;
420
+ var l, c, f, m, C, d, x, S, y;
382
421
  if (!t.content.trim() && (!t.attachments || t.attachments.length === 0)) {
383
422
  console.warn("Cannot send an empty message of no content or attachments");
384
423
  return;
385
424
  }
386
- const s = this.state.get().isSendingMessage, e = ((r = this.sessionCtx.sessionState.get().session) == null ? void 0 : r.assignee.kind) === "ai", o = this.state.get().messages, l = o.length > 0 ? o[o.length - 1] : void 0;
425
+ const s = this.state.get().isSendingMessage, e = ((l = this.sessionCtx.sessionState.get().session) == null ? void 0 : l.assignee.kind) === "ai", o = this.state.get().messages, r = o.length > 0 ? o[o.length - 1] : void 0;
387
426
  if (e && s || // If last message is from user, then bot response did not arrive yet
388
- e && (l == null ? void 0 : l.type) === "FROM_USER") {
427
+ e && (r == null ? void 0 : r.type) === "FROM_USER") {
389
428
  console.warn("Cannot send messages while awaiting AI response");
390
429
  return;
391
430
  }
@@ -395,55 +434,55 @@ class j {
395
434
  const w = this.toUserMessage(
396
435
  t.content.trim(),
397
436
  t.attachments || void 0
398
- ), E = this.state.get().messages;
437
+ ), R = this.state.get().messages;
399
438
  if (this.state.setPartial({
400
- messages: [...E, w]
401
- }), !((g = this.sessionCtx.sessionState.get().session) != null && g.id)) {
439
+ messages: [...R, w]
440
+ }), !((c = this.sessionCtx.sessionState.get().session) != null && c.id)) {
402
441
  if (!await this.sessionCtx.createSession()) {
403
442
  console.error("Failed to create session");
404
443
  return;
405
444
  }
406
445
  this.sessionCtx.refreshSessions();
407
446
  }
408
- const y = (f = this.sessionCtx.sessionState.get().session) == null ? void 0 : f.id;
409
- if (!y) return;
410
- const { data: d } = await this.api.sendMessage(
447
+ const k = (f = this.sessionCtx.sessionState.get().session) == null ? void 0 : f.id;
448
+ if (!k) return;
449
+ const { data: u } = await this.api.sendMessage(
411
450
  {
412
451
  uuid: w.id,
413
452
  bot_token: this.config.token,
414
453
  headers: this.config.headers,
415
454
  query_params: this.config.queryParams,
416
- session_id: y,
417
- user: (p = this.config.user) == null ? void 0 : p.data,
455
+ session_id: k,
456
+ user: (m = this.config.user) == null ? void 0 : m.data,
418
457
  content: w.content,
419
458
  attachments: t.attachments,
420
459
  clientContext: this.config.context
421
460
  },
422
461
  this.sendMessageAbortController.signal
423
462
  );
424
- if (d != null && d.success) {
425
- const x = this.toBotMessage(d);
426
- if (x) {
463
+ if (u != null && u.success) {
464
+ const v = this.toBotMessage(u);
465
+ if (v) {
427
466
  const P = this.state.get().messages;
428
467
  if (!!P.some(
429
- (T) => T.id === x.id
468
+ (M) => M.id === v.id
430
469
  )) {
431
470
  this.state.setPartial({
432
- lastAIResMightSolveUserIssue: ((m = d.autopilotResponse) == null ? void 0 : m.mightSolveUserIssue) || ((S = d.uiResponse) == null ? void 0 : S.mightSolveUserIssue)
471
+ lastAIResMightSolveUserIssue: ((C = u.autopilotResponse) == null ? void 0 : C.mightSolveUserIssue) || ((d = u.uiResponse) == null ? void 0 : d.mightSolveUserIssue)
433
472
  });
434
473
  return;
435
474
  }
436
475
  this.state.setPartial({
437
- messages: [...P, x],
438
- lastAIResMightSolveUserIssue: ((b = d.autopilotResponse) == null ? void 0 : b.mightSolveUserIssue) || ((C = d.uiResponse) == null ? void 0 : C.mightSolveUserIssue)
476
+ messages: [...P, v],
477
+ lastAIResMightSolveUserIssue: ((x = u.autopilotResponse) == null ? void 0 : x.mightSolveUserIssue) || ((S = u.uiResponse) == null ? void 0 : S.mightSolveUserIssue)
439
478
  });
440
479
  }
441
480
  } else {
442
- const x = this.toBotErrorMessage(
443
- ((U = d == null ? void 0 : d.error) == null ? void 0 : U.message) || "Unknown error occurred"
481
+ const v = this.toBotErrorMessage(
482
+ ((y = u == null ? void 0 : u.error) == null ? void 0 : y.message) || "Unknown error occurred"
444
483
  ), P = this.state.get().messages;
445
484
  this.state.setPartial({
446
- messages: [...P, x]
485
+ messages: [...P, v]
447
486
  });
448
487
  }
449
488
  } catch (w) {
@@ -454,7 +493,7 @@ class j {
454
493
  }, this.toUserMessage = (t, s) => {
455
494
  const e = (() => {
456
495
  const o = this.contactCtx.state.get().extraCollectedData;
457
- return this.state.get().messages.length === 0 && o && Object.keys(o).length > 0 ? `${Object.entries(o).filter(([r, g]) => !!g).map(([r, g]) => `${r}: ${g}`).join(`
496
+ return this.state.get().messages.length === 0 && o && Object.keys(o).length > 0 ? `${Object.entries(o).filter(([l, c]) => !!c).map(([l, c]) => `${l}: ${c}`).join(`
458
497
  `)}
459
498
 
460
499
  ${t}` : t;
@@ -498,14 +537,14 @@ ${t}` : t;
498
537
  variant: "error",
499
538
  action: void 0
500
539
  }
501
- }), this.config = n, this.api = i, this.sessionCtx = c, this.contactCtx = a;
540
+ }), this.config = n, this.api = i, this.sessionCtx = h, this.contactCtx = a;
502
541
  }
503
542
  }
504
- class N {
543
+ class H {
505
544
  constructor({
506
545
  config: n,
507
546
  contactCtx: i,
508
- sessionCtx: c,
547
+ sessionCtx: h,
509
548
  resetChat: a
510
549
  }) {
511
550
  this.registerRoutingListener = () => {
@@ -526,12 +565,12 @@ class N {
526
565
  this.sessionCtx.sessionState.setPartial({ session: s });
527
566
  }
528
567
  this.state.setPartial({ screen: "chat" });
529
- }, this.state = new v({
568
+ }, this.state = new b({
530
569
  screen: i.shouldCollectData() ? "welcome" : "sessions"
531
- }), this.config = n, this.contactCtx = i, this.sessionCtx = c, this.resetChat = a, this.registerRoutingListener();
570
+ }), this.config = n, this.contactCtx = i, this.sessionCtx = h, this.resetChat = a, this.registerRoutingListener();
532
571
  }
533
572
  }
534
- class G {
573
+ class X {
535
574
  constructor({ storage: n }) {
536
575
  this.KEYS = {
537
576
  contactToken: "opencx__widget__contactToken",
@@ -543,37 +582,37 @@ class G {
543
582
  }, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId), this.storage = n;
544
583
  }
545
584
  }
546
- const u = class u {
585
+ const p = class p {
547
586
  constructor({
548
587
  config: n,
549
588
  storage: i
550
589
  }) {
551
590
  if (this.resetChat = () => {
552
591
  this.sessionCtx.reset(), this.messageCtx.reset();
553
- }, !u.pollingIntervalsSeconds)
592
+ }, !p.pollingIntervalsSeconds)
554
593
  throw Error(
555
594
  "Widget polling values are not defined, did you call WidgetCtx.initialize()"
556
595
  );
557
- this.config = n, this.api = new k({ config: n }), this.storageCtx = i ? new G({ storage: i }) : void 0, this.contactCtx = new q({
596
+ this.config = n, this.api = new E({ config: n }), this.storageCtx = i ? new X({ storage: i }) : void 0, this.contactCtx = new q({
558
597
  api: this.api,
559
598
  config: this.config,
560
599
  storageCtx: this.storageCtx
561
600
  }), this.sessionCtx = new $({
562
601
  api: this.api,
563
602
  contactCtx: this.contactCtx,
564
- sessionsPollingIntervalSeconds: u.pollingIntervalsSeconds.sessions
565
- }), this.messageCtx = new j({
603
+ sessionsPollingIntervalSeconds: p.pollingIntervalsSeconds.sessions
604
+ }), this.messageCtx = new N({
566
605
  config: this.config,
567
606
  api: this.api,
568
607
  sessionCtx: this.sessionCtx,
569
608
  contactCtx: this.contactCtx
570
- }), this.activeSessionPollingCtx = new B({
609
+ }), this.activeSessionPollingCtx = new _({
571
610
  api: this.api,
572
611
  config: this.config,
573
612
  sessionCtx: this.sessionCtx,
574
613
  messageCtx: this.messageCtx,
575
- sessionPollingIntervalSeconds: u.pollingIntervalsSeconds.session
576
- }), this.routerCtx = new N({
614
+ sessionPollingIntervalSeconds: p.pollingIntervalsSeconds.session
615
+ }), this.routerCtx = new H({
577
616
  config: this.config,
578
617
  contactCtx: this.contactCtx,
579
618
  sessionCtx: this.sessionCtx,
@@ -581,25 +620,25 @@ const u = class u {
581
620
  });
582
621
  }
583
622
  };
584
- u.pollingIntervalsSeconds = null, u.initialize = async ({
623
+ p.pollingIntervalsSeconds = null, p.initialize = async ({
585
624
  config: n,
586
625
  storage: i
587
626
  }) => {
588
627
  var a, t;
589
- const c = await new k({
628
+ const h = await new E({
590
629
  config: n
591
630
  }).getExternalWidgetConfig();
592
- return u.pollingIntervalsSeconds = {
593
- session: ((a = c.data) == null ? void 0 : a.sessionPollingIntervalSeconds) || 10,
594
- sessions: ((t = c.data) == null ? void 0 : t.sessionsPollingIntervalSeconds) || 60
595
- }, new u({
631
+ return p.pollingIntervalsSeconds = {
632
+ session: ((a = h.data) == null ? void 0 : a.sessionPollingIntervalSeconds) || 10,
633
+ sessions: ((t = h.data) == null ? void 0 : t.sessionsPollingIntervalSeconds) || 60
634
+ }, new p({
596
635
  config: n,
597
636
  storage: i
598
637
  });
599
638
  };
600
- let A = u;
639
+ let U = p;
601
640
  export {
602
- v as P,
603
- A as W
641
+ b as P,
642
+ U as W
604
643
  };
605
- //# sourceMappingURL=widget.ctx-QcHsFXpb.js.map
644
+ //# sourceMappingURL=widget.ctx-DXznvVMa.js.map