@opencx/widget 2.4.4-rn.1 → 2.4.4-rn.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/basic.cjs +31 -31
  2. package/dist/basic.cjs.map +1 -1
  3. package/dist/basic.js +37 -38
  4. package/dist/basic.js.map +1 -1
  5. package/dist/core/client/api.d.ts +6 -15
  6. package/dist/core/client/chat.d.ts +10 -10
  7. package/dist/core/client/contact.d.ts +2 -2
  8. package/dist/core/types/helpers.d.ts +1 -1
  9. package/dist/core/types/index.d.ts +2 -3
  10. package/dist/core/types/schemas-v2.d.ts +92 -91
  11. package/dist/core/types/schemas.d.ts +123 -69
  12. package/dist/{index-ENMg5VOh.js → index-B-VyJuQ9.js} +964 -864
  13. package/dist/index-B-VyJuQ9.js.map +1 -0
  14. package/dist/index-D2PGs8oF.cjs +18 -0
  15. package/dist/index-D2PGs8oF.cjs.map +1 -0
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.js +189 -189
  19. package/dist/index.js.map +1 -1
  20. package/dist/package.json.d.ts +1 -1
  21. package/dist/react-web/hooks/useAbstractChat.d.ts +22 -21
  22. package/dist/react-web/hooks/useAxiosInstance.d.ts +35 -23
  23. package/dist/react-web/hooks/useUploadFiles.d.ts +1 -1
  24. package/dist/react-web/providers/ChatProvider.d.ts +24 -24
  25. package/dist/react-web/providers/ContactProvider.d.ts +4 -4
  26. package/dist/react.cjs +1 -1
  27. package/dist/react.js +1 -1
  28. package/dist/schemas-v2-BiJWHypc.cjs +2 -0
  29. package/dist/schemas-v2-BiJWHypc.cjs.map +1 -0
  30. package/dist/schemas-v2-DZ3nwfID.js +138 -0
  31. package/dist/schemas-v2-DZ3nwfID.js.map +1 -0
  32. package/dist/src/components/RenderFile.d.ts +1 -1
  33. package/dist/src/components/dialog.d.ts +2 -2
  34. package/dist-embed/script.js +107 -107
  35. package/dist-embed/script.js.map +1 -1
  36. package/package.json +1 -1
  37. package/dist/index-Bx4hrNc7.cjs +0 -18
  38. package/dist/index-Bx4hrNc7.cjs.map +0 -1
  39. package/dist/index-ENMg5VOh.js.map +0 -1
  40. package/dist/schemas-BBAV6Sd_.js +0 -122
  41. package/dist/schemas-BBAV6Sd_.js.map +0 -1
  42. package/dist/schemas-wky4fpbc.cjs +0 -2
  43. package/dist/schemas-wky4fpbc.cjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,30 +1,30 @@
1
- var x = Object.defineProperty;
2
- var N = (t) => {
1
+ var j = Object.defineProperty;
2
+ var D = (t) => {
3
3
  throw TypeError(t);
4
4
  };
5
- var q = (t, e, s) => e in t ? x(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
6
- var S = (t, e, s) => q(t, typeof e != "symbol" ? e + "" : e, s), D = (t, e, s) => e.has(t) || N("Cannot " + s);
7
- var h = (t, e, s) => (D(t, e, "read from private field"), s ? s.call(t) : e.get(t)), M = (t, e, s) => e.has(t) ? N("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, s), P = (t, e, s, o) => (D(t, e, "write to private field"), o ? o.call(t, s) : e.set(t, s), s);
8
- import j from "lodash.isequal";
9
- import { g as _ } from "./schemas-BBAV6Sd_.js";
10
- import { A as de, M as fe, b as me, a as ge, S as he, d as Se, e as pe, c as Ee, f as ye, s as be } from "./schemas-BBAV6Sd_.js";
11
- var H = /* @__PURE__ */ ((t) => (t.INIT = "init", t.STATE_CHANGE = "stateChange", t.BEFORE_UPDATE = "beforeUpdate", t.AFTER_UPDATE = "afterUpdate", t.DESTROY = "destroy", t.ERROR = "error", t))(H || {}), y, L;
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, L);
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 d = {
22
+ const f = {
23
23
  type: e,
24
24
  timestamp: Date.now(),
25
25
  data: s
26
26
  };
27
- o.forEach((n) => n(d));
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
- }), j(h(this, y), e) || (P(this, y, e), P(this, L, Date.now()), this.emitLifecycle("stateChange", { state: e }), this.subscribers.forEach((s) => {
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, L));
82
- P(this, y, e), this.initialState = e, P(this, L, Date.now()), this.emitLifecycle("init", { initialState: h(this, y) });
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(), L = new WeakMap();
86
- function W(t) {
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 Z extends v {
94
+ class te extends v {
95
95
  constructor(e = "Connection failed") {
96
96
  super(e), this.name = "ConnectionError";
97
97
  }
98
98
  }
99
- class ee extends v {
99
+ class se extends v {
100
100
  constructor(e = "Authentication failed") {
101
101
  super(e), this.name = "AuthenticationError";
102
102
  }
103
103
  }
104
- class B extends v {
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 te extends B {
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 se extends v {
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 re extends v {
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 T(t) {
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 O(t, e) {
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 R = {
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 k(t) {
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 J(t, e, s) {
174
+ function X(t, e, s) {
175
175
  async function o(i) {
176
- const c = e.getState().messages;
177
- if (c.length === 0) {
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(k)
181
+ messages: g.map($)
182
182
  });
183
183
  return;
184
184
  }
185
- const l = c[c.length - 1], r = new Date(l.timestamp);
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: c.length
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(k).filter((p) => !c.some((I) => I.id === p.id));
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: [...c, ...g]
201
+ messages: [...l, ...g]
202
202
  }));
203
203
  }
204
204
  }
205
- function d(i, c) {
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: c,
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 c = i.uiResponse.value;
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: c.name,
233
- data: c.request_response
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: d,
252
+ addUserMessage: f,
253
253
  addBotMessage: n,
254
254
  addErrorMessage: a
255
255
  };
256
256
  }
257
- function G(t, e, s, o, d, n) {
258
- var F, U;
259
- const a = (F = n.platform) == null ? void 0 : F.logger;
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 c = (U = n.platform) == null ? void 0 : U.storage, l = `${d.getConfig().user.external_id}:${d.getConfig().token}:session`, r = n.config.getSettings().persistSession;
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 (c)
263
+ if (l)
264
264
  try {
265
265
  a == null || a.debug("Attempting to restore session from storage");
266
- const f = await c.getItem(l);
267
- if (f) {
268
- const m = JSON.parse(f);
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 (f) {
272
- a == null || a.error("Error restoring session from storage:", f);
271
+ } catch (d) {
272
+ a == null || a.error("Error restoring session from storage:", d);
273
273
  }
274
274
  }
275
275
  function E() {
276
- c && (a == null || a.debug("Setting up session persistence"), e.subscribe(async (f) => {
276
+ l && (a == null || a.debug("Setting up session persistence"), e.subscribe(async (d) => {
277
277
  try {
278
- f ? (await c.setItem(l, JSON.stringify(f)), a == null || a.debug("Session persisted to storage", { sessionId: f.id })) : (await c.removeItem(l), a == null || a.debug("Session removed from storage"));
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 f = [];
294
- f.push(
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
- }, R.SESSION)
305
- ), f.push(
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
- }, R.MESSAGES)
314
+ }, k.MESSAGES)
315
315
  ), i = () => {
316
- a == null || a.debug("Stopping polling"), f.forEach(clearInterval);
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 f = await t.createSession();
326
- return a == null || a.info("Session created successfully", { sessionId: f.id }), e.setState(f), g(), f;
327
- } catch (f) {
328
- a == null || a.error("Failed to create session:", f);
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: f instanceof Error ? f.message : "Failed to create session",
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 f = e.getState();
344
- if (f != null && f.id)
343
+ const d = e.getState();
344
+ if (d != null && d.id)
345
345
  try {
346
- i && (i(), i = null), e.setState(null), r && c && T(c) && c.removeItem(l), s.setState({
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 A() {
362
+ function T() {
363
363
  try {
364
- i && (i(), i = null), r && c && T(c) && c.removeItem(l), s.setState({
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 (f) {
371
- console.error("Error in cleanup:", f), s.setStatePartial({
370
+ } catch (d) {
371
+ console.error("Error in cleanup:", d), s.setStatePartial({
372
372
  error: {
373
373
  hasError: !0,
374
- message: f instanceof Error ? f.message : "Failed to cleanup",
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
- return r && T(c) && (u(), E()), {
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: A,
384
- startPolling: g
392
+ cleanup: T,
393
+ startPolling: g,
394
+ fetchSession: F,
395
+ refetchSession: q
385
396
  };
386
397
  }
387
- function ae(t) {
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), d = J(t.api, s, e), n = G(
407
+ }), o = new C(null), f = X(t.api, s, e), n = z(
397
408
  t.api,
398
409
  o,
399
410
  s,
400
- d,
411
+ f,
401
412
  t.config,
402
413
  t
403
414
  );
404
- async function a(c) {
415
+ async function a(l) {
405
416
  var r;
406
- let l = o.getState();
407
- if (!(l != null && l.id) && (e == null || e.debug("No active session, creating new session"), l = await n.createSession(), !l))
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: l.id }), s.setStatePartial({
411
- loading: { isLoading: !0, reason: "sending_message" },
422
+ e == null || e.debug("Sending message", { sessionId: c.id }), c.assignee.kind === "ai" ? s.setStatePartial({
423
+ loading: { isLoading: !0, reason: "sending_message_to_agent" },
424
+ error: { hasError: !1 }
425
+ }) : s.setStatePartial({
426
+ loading: { isLoading: !0, reason: "sending_message_to_bot" },
412
427
  error: { hasError: !1 }
413
428
  });
414
- const u = d.addUserMessage(c.content, c.attachments || void 0), E = s.getState().messages;
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,23 @@ function ae(t) {
419
434
  bot_token: g.token,
420
435
  headers: g.headers,
421
436
  query_params: g.queryParams,
422
- session_id: l.id,
423
- ...c
437
+ session_id: c.id,
438
+ ...l
424
439
  });
425
440
  if (p.success) {
426
441
  e == null || e.debug("Message sent successfully");
427
- const I = d.addBotMessage(p);
442
+ const I = f.addBotMessage(p);
428
443
  if (I) {
429
- const A = s.getState().messages;
444
+ const T = s.getState().messages;
430
445
  s.setStatePartial({
431
- messages: [...A, I]
446
+ messages: [...T, I]
432
447
  });
433
448
  }
434
449
  } else {
435
450
  e == null || e.warn("Message send failed", p.error);
436
- const I = d.addErrorMessage(((r = p.error) == null ? void 0 : r.message) || "Unknown error occurred"), A = s.getState().messages;
451
+ const I = f.addErrorMessage(((r = p.error) == null ? void 0 : r.message) || "Unknown error occurred"), T = s.getState().messages;
437
452
  s.setStatePartial({
438
- messages: [...A, I]
453
+ messages: [...T, I]
439
454
  });
440
455
  }
441
456
  return !0;
@@ -462,27 +477,27 @@ function ae(t) {
462
477
  cleanup: n.cleanup
463
478
  };
464
479
  }
465
- function ne(t) {
480
+ function ie(t) {
466
481
  const e = t.config.getConfig();
467
482
  t.config.getConfig;
468
- const s = `${e.token}:contact:${e.user.external_id}`, o = T(t.platform.storage) ? t.platform.storage : void 0;
469
- let d = null;
470
- o && O(
483
+ const s = `${e.token}:contact:${e.user.external_id}`, o = L(t.platform.storage) ? t.platform.storage : void 0;
484
+ let f = null;
485
+ o && A(
471
486
  async () => {
472
487
  const r = await o.getItem(s);
473
488
  return r ? JSON.parse(r) : null;
474
489
  },
475
490
  "Error loading contact from storage"
476
491
  ).then((r) => {
477
- r.success && (d = r.result);
492
+ r.success && (f = r.result);
478
493
  });
479
494
  const n = new C({
480
- contact: d,
495
+ contact: f,
481
496
  loading: { isLoading: !1 },
482
497
  error: { hasError: !1 }
483
498
  });
484
- T(o) && n.subscribe((r) => {
485
- O(
499
+ L(o) && n.subscribe((r) => {
500
+ A(
486
501
  async () => {
487
502
  r.contact ? await o.setItem(s, JSON.stringify(r.contact)) : o.removeItem(s);
488
503
  },
@@ -503,7 +518,7 @@ function ne(t) {
503
518
  loading: { isLoading: !0, reason: "loading_contact" },
504
519
  error: { hasError: !1 }
505
520
  }), o) {
506
- const r = await O(
521
+ const r = await A(
507
522
  async () => {
508
523
  const u = await o.getItem(s);
509
524
  return u ? JSON.parse(u) : null;
@@ -545,8 +560,8 @@ function ne(t) {
545
560
  avatar_url: r.avatar_url ?? (u == null ? void 0 : u.avatar_url) ?? null,
546
561
  email: r.email ?? (u == null ? void 0 : u.email) ?? null
547
562
  };
548
- if (T(o)) {
549
- const g = await O(
563
+ if (L(o)) {
564
+ const g = await A(
550
565
  () => o.setItem(s, JSON.stringify(E)),
551
566
  "Error saving contact"
552
567
  );
@@ -571,7 +586,7 @@ function ne(t) {
571
586
  });
572
587
  }
573
588
  }
574
- function c() {
589
+ function l() {
575
590
  var u;
576
591
  return !((u = n.getState().contact) != null && u.id) && e.collectUserData ? {
577
592
  should: !0,
@@ -580,13 +595,13 @@ function ne(t) {
580
595
  should: !1
581
596
  };
582
597
  }
583
- async function l() {
598
+ async function c() {
584
599
  try {
585
600
  if (n.setStatePartial({
586
601
  loading: { isLoading: !0, reason: "cleaning_up" },
587
602
  error: { hasError: !1 }
588
603
  }), o) {
589
- const r = await O(
604
+ const r = await A(
590
605
  () => o.removeItem(s),
591
606
  "Error removing contact data"
592
607
  );
@@ -614,29 +629,28 @@ function ne(t) {
614
629
  }
615
630
  return {
616
631
  contactState: n,
617
- shouldCollectData: c,
632
+ shouldCollectData: l,
618
633
  loadContact: a,
619
634
  saveContact: i,
620
- cleanup: l
635
+ cleanup: c
621
636
  };
622
637
  }
623
- const X = {
638
+ const V = {
624
639
  messageArrived: "https://cloud.opencopilot.so/sfx/notification3.mp3"
625
- }, $ = {
640
+ }, x = {
626
641
  primaryColor: "hsl(211,65%,59%)",
627
642
  triggerOffset: "20px"
628
- }, z = 1e3 * 3;
629
- function oe(t) {
630
- var s, o, d, n, a, i, c, l, r;
643
+ }, K = 1e3 * 3;
644
+ function ce(t) {
645
+ var s, o, f, n, a, i, l, c, r;
631
646
  if (!t.token)
632
647
  throw new Error("Token is required");
633
- if (t.pollingInterval && t.pollingInterval < z)
648
+ if (t.pollingInterval && t.pollingInterval < K)
634
649
  throw new Error("Polling interval must be at least 3 seconds");
635
650
  const e = {
636
651
  ...t,
637
652
  collectUserData: t.collectUserData ?? !1,
638
653
  apiUrl: t.apiUrl ?? "https://api-v2.opencopilot.so/backend",
639
- socketUrl: t.socketUrl ?? "https://api-v2.opencopilot.so",
640
654
  pollingInterval: t.pollingInterval ?? 3e3,
641
655
  headers: t.headers ?? {},
642
656
  queryParams: t.queryParams ?? {},
@@ -644,7 +658,7 @@ function oe(t) {
644
658
  bot: {
645
659
  name: ((s = t.bot) == null ? void 0 : s.name) ?? "Bot",
646
660
  avatarUrl: (o = t.bot) == null ? void 0 : o.avatarUrl,
647
- id: ((d = t.bot) == null ? void 0 : d.id) ?? null,
661
+ id: ((f = t.bot) == null ? void 0 : f.id) ?? null,
648
662
  is_ai: ((n = t.bot) == null ? void 0 : n.is_ai) ?? !0
649
663
  },
650
664
  contactToken: t.contactToken,
@@ -652,14 +666,14 @@ function oe(t) {
652
666
  language: t.language ?? "en",
653
667
  user: t.user ?? {},
654
668
  soundEffectFiles: {
655
- messageArrived: ((a = t.soundEffectFiles) == null ? void 0 : a.messageArrived) ?? X.messageArrived
669
+ messageArrived: ((a = t.soundEffectFiles) == null ? void 0 : a.messageArrived) ?? V.messageArrived
656
670
  },
657
671
  theme: {
658
- primaryColor: ((i = t.theme) == null ? void 0 : i.primaryColor) ?? $.primaryColor,
659
- triggerOffset: ((c = t.theme) == null ? void 0 : c.triggerOffset) ?? $.triggerOffset
672
+ primaryColor: ((i = t.theme) == null ? void 0 : i.primaryColor) ?? x.primaryColor,
673
+ triggerOffset: ((l = t.theme) == null ? void 0 : l.triggerOffset) ?? x.triggerOffset
660
674
  },
661
675
  settings: {
662
- persistSession: ((l = t.settings) == null ? void 0 : l.persistSession) ?? !1,
676
+ persistSession: ((c = t.settings) == null ? void 0 : c.persistSession) ?? !1,
663
677
  useSoundEffects: ((r = t.settings) == null ? void 0 : r.useSoundEffects) ?? !1
664
678
  }
665
679
  };
@@ -681,8 +695,8 @@ function oe(t) {
681
695
  getDebugMode: () => e.debug
682
696
  };
683
697
  }
684
- function V(t = {}) {
685
- const e = [], s = [], o = [], d = async (n, a = {}) => {
698
+ function Y(t = {}) {
699
+ const e = [], s = [], o = [], f = async (n, a = {}) => {
686
700
  let i = {
687
701
  ...t,
688
702
  ...a,
@@ -694,19 +708,19 @@ function V(t = {}) {
694
708
  try {
695
709
  for (const u of e)
696
710
  i = await u(i);
697
- const c = i.params ? "?" + new URLSearchParams(i.params).toString() : "", l = i.baseURL ? `${i.baseURL}${n}${c}`.replace(/([^:]\/)\/+/g, "$1") : `${n}${c}`;
698
- let r = await fetch(l, i);
711
+ const l = i.params ? "?" + new URLSearchParams(i.params).toString() : "", c = i.baseURL ? `${i.baseURL}${n}${l}`.replace(/([^:]\/)\/+/g, "$1") : `${n}${l}`;
712
+ let r = await fetch(c, i);
699
713
  for (const u of s)
700
714
  r = await u(r);
701
715
  return r;
702
- } catch (c) {
703
- let l = c;
716
+ } catch (l) {
717
+ let c = l;
704
718
  for (const r of o)
705
- l = await r(l);
706
- throw l;
719
+ c = await r(c);
720
+ throw c;
707
721
  }
708
722
  };
709
- return d.interceptors = {
723
+ return f.interceptors = {
710
724
  request: {
711
725
  use: (n) => (e.push(n), e.length - 1),
712
726
  eject: (n) => {
@@ -719,10 +733,10 @@ function V(t = {}) {
719
733
  s.splice(n, 1), o.splice(n, 1);
720
734
  }
721
735
  }
722
- }, d;
736
+ }, f;
723
737
  }
724
738
  var b;
725
- class ie {
739
+ class le {
726
740
  constructor(e) {
727
741
  M(this, b);
728
742
  this.options = e;
@@ -731,15 +745,15 @@ class ie {
731
745
  value: ""
732
746
  };
733
747
  s != null && s.email ? (o.claim = "email", o.value = s.email) : s != null && s.phone && (o.claim = "phone", o.value = s.phone);
734
- const d = {
748
+ const f = {
735
749
  "X-Bot-Token": this.options.config.token,
736
750
  "X-Consumer-Id": `${o.claim}:${o.value}`,
737
751
  "Content-Type": "application/json",
738
752
  Accept: "application/json"
739
753
  };
740
- this.options.config.contactToken && (d.Authorization = `Bearer ${this.options.config.contactToken}`), P(this, b, V({
754
+ this.options.config.contactToken && (f.Authorization = `Bearer ${this.options.config.contactToken}`), _(this, b, Y({
741
755
  baseURL: `${this.options.config.apiUrl}/widget/v2`,
742
- headers: d
756
+ headers: f
743
757
  }));
744
758
  }
745
759
  async me() {
@@ -757,8 +771,8 @@ class ie {
757
771
  async getSessionHistory(e, s) {
758
772
  const o = new URLSearchParams({
759
773
  lastMessageTimestamp: s || ""
760
- }), d = `/session/history/${e}?${o.toString()}`;
761
- return (await h(this, b).call(this, d, {
774
+ }), f = `/session/history/${e}?${o.toString()}`;
775
+ return (await h(this, b).call(this, f, {
762
776
  method: "GET"
763
777
  })).json();
764
778
  }
@@ -772,35 +786,29 @@ class ie {
772
786
  method: "GET"
773
787
  })).json();
774
788
  }
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
789
  }
782
790
  b = new WeakMap();
783
- function ce(t = {}) {
791
+ function ue(t = {}) {
784
792
  const {
785
793
  level: e = "info",
786
794
  prefix: s = "[openCx]",
787
795
  enabled: o = !0
788
796
  } = t;
789
- let d = e;
797
+ let f = e;
790
798
  const n = {
791
799
  debug: 0,
792
800
  info: 1,
793
801
  warn: 2,
794
802
  error: 3
795
803
  };
796
- function a(l) {
797
- return o && n[l] >= n[d];
804
+ function a(c) {
805
+ return o && n[c] >= n[f];
798
806
  }
799
- function i(l) {
800
- return `${s} ${l}`;
807
+ function i(c) {
808
+ return `${s} ${c}`;
801
809
  }
802
- function c(l) {
803
- return l.map((r) => {
810
+ function l(c) {
811
+ return c.map((r) => {
804
812
  if (r instanceof Error)
805
813
  return {
806
814
  name: r.name,
@@ -817,50 +825,42 @@ function ce(t = {}) {
817
825
  });
818
826
  }
819
827
  return {
820
- debug(l, ...r) {
821
- a("debug") && console.debug(i(l), ...c(r));
828
+ debug(c, ...r) {
829
+ a("debug") && console.debug(i(c), ...l(r));
822
830
  },
823
- info(l, ...r) {
824
- a("info") && console.info(i(l), ...c(r));
831
+ info(c, ...r) {
832
+ a("info") && console.info(i(c), ...l(r));
825
833
  },
826
- warn(l, ...r) {
827
- a("warn") && console.warn(i(l), ...c(r));
834
+ warn(c, ...r) {
835
+ a("warn") && console.warn(i(c), ...l(r));
828
836
  },
829
- error(l, ...r) {
830
- a("error") && console.error(i(l), ...c(r));
837
+ error(c, ...r) {
838
+ a("error") && console.error(i(c), ...l(r));
831
839
  },
832
- setLevel(l) {
833
- d = l;
840
+ setLevel(c) {
841
+ f = c;
834
842
  }
835
843
  };
836
844
  }
837
845
  export {
838
- de as AIClosureType,
839
- ie as ApiCaller,
840
- ee as AuthenticationError,
841
- Z as ConnectionError,
842
- re as FileUploadError,
843
- H as LifecycleEvent,
844
- fe as MessageTypeEnum,
846
+ le as ApiCaller,
847
+ se as AuthenticationError,
848
+ te as ConnectionError,
849
+ ne as FileUploadError,
850
+ G as LifecycleEvent,
851
+ me as MessageTypeEnum,
845
852
  v as OpenCXError,
846
853
  C as PubSub,
847
- me as SentimentEnum,
848
- ge as SessionChannel,
849
- B as SessionError,
850
- te as SessionNotDefinedError,
851
- he as SessionStatus,
852
- se as TransportError,
853
- Se as chatAttachmentSchema,
854
- pe as chatHistoryMessageSchema,
855
- Ee as chatSessionSchema,
856
- ye as consumerSchema,
857
- ae as createChat,
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
854
+ J as SessionError,
855
+ re as SessionNotDefinedError,
856
+ ae as TransportError,
857
+ ge as chatAttachmentSchema,
858
+ oe as createChat,
859
+ ce as createConfig,
860
+ ie as createContact,
861
+ ue as createLogger,
862
+ ee as createPubSub,
863
+ L as isStorageAvailable,
864
+ A as safeStorageOperation
865
865
  };
866
866
  //# sourceMappingURL=index.js.map