@opencx/widget 3.0.19 → 3.0.21

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 (29) hide show
  1. package/dist/designs.cjs +72 -72
  2. package/dist/designs.cjs.map +1 -1
  3. package/dist/designs.js +36244 -36248
  4. package/dist/designs.js.map +1 -1
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/react.cjs +1 -1
  8. package/dist/react.js +2 -2
  9. package/dist/src/designs/react/components/BotOrAgentMessage.d.ts +2 -8
  10. package/dist/src/designs/react/components/{Text.component.d.ts → BotOrAgentTextResponse.d.ts} +1 -2
  11. package/dist/src/headless/core/context/message.ctx.d.ts +1 -1
  12. package/dist/src/headless/core/index.d.ts +1 -1
  13. package/dist/src/headless/core/sdk/schema.d.ts +2 -6
  14. package/dist/src/headless/core/types/messages.d.ts +15 -8
  15. package/dist/src/headless/react/ComponentRegistry.d.ts +1 -2
  16. package/dist/src/headless/react/types/components.d.ts +1 -1
  17. package/dist/{useUploadFiles-sY8364dS.js → useUploadFiles-DNazXzpj.js} +11 -18
  18. package/dist/useUploadFiles-DNazXzpj.js.map +1 -0
  19. package/dist/{useUploadFiles-CyBcsF-U.cjs → useUploadFiles-DufH5njs.cjs} +3 -3
  20. package/dist/useUploadFiles-DufH5njs.cjs.map +1 -0
  21. package/dist/{widget.ctx-C4fHGXaH.cjs → widget.ctx-DoLfq9VQ.cjs} +2 -2
  22. package/dist/{widget.ctx-C4fHGXaH.cjs.map → widget.ctx-DoLfq9VQ.cjs.map} +1 -1
  23. package/dist/{widget.ctx-DkhYPIAY.js → widget.ctx-naCIXuET.js} +106 -105
  24. package/dist/{widget.ctx-DkhYPIAY.js.map → widget.ctx-naCIXuET.js.map} +1 -1
  25. package/dist-embed/script.js +110 -110
  26. package/dist-embed/script.js.map +1 -1
  27. package/package.json +1 -1
  28. package/dist/useUploadFiles-CyBcsF-U.cjs.map +0 -1
  29. package/dist/useUploadFiles-sY8364dS.js.map +0 -1
@@ -1,23 +1,23 @@
1
- var O = Object.defineProperty;
2
- var M = (a) => {
3
- throw TypeError(a);
1
+ var L = Object.defineProperty;
2
+ var M = (n) => {
3
+ throw TypeError(n);
4
4
  };
5
- var L = (a, t, e) => t in a ? O(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
6
- var s = (a, t, e) => L(a, typeof t != "symbol" ? t + "" : t, e), R = (a, t, e) => t.has(a) || M("Cannot " + e);
7
- var h = (a, t, e) => (R(a, t, "read from private field"), e ? e.call(a) : t.get(a)), y = (a, t, e) => t.has(a) ? M("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(a) : t.set(a, e), S = (a, t, e, i) => (R(a, t, "write to private field"), i ? i.call(a, e) : t.set(a, e), e);
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 _ } from "uuid";
12
- const q = (a) => {
13
- console.log(a.error);
14
- }, B = (a) => {
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: a.baseUrl
16
+ baseUrl: n.baseUrl
17
17
  }), e = {
18
- onRequest: a.onRequest,
19
- onResponse: a.onResponse,
20
- onError: a.onError || q
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
- }) => B({
43
+ }) => _({
44
44
  baseUrl: t,
45
45
  onRequest: ({ request: i }) => {
46
- Object.entries(e).forEach(([n, r]) => {
47
- r && i.headers.set(n, r);
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 n = e ? { lastMessageTimestamp: e } : void 0;
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: n }, signal: i }
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,19 +105,19 @@ 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: n } = await this.uploadFileClient.post("", i, {
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 n;
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 n;
117
+ var a;
118
118
  this.config = t;
119
119
  const { baseUrl: e, headers: i } = this.constructClientOptions(
120
- (n = t.user) == null ? void 0 : n.token
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
  }
@@ -126,21 +126,21 @@ var l, f;
126
126
  class p {
127
127
  constructor(t) {
128
128
  s(this, "subscribers", /* @__PURE__ */ new Set());
129
- y(this, l);
129
+ P(this, l);
130
130
  s(this, "initialState");
131
- y(this, f);
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 n = {
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(n);
143
+ r(a);
144
144
  } catch {
145
145
  }
146
146
  });
@@ -150,8 +150,8 @@ class p {
150
150
  Array.from(this.subscribers).forEach((i) => {
151
151
  try {
152
152
  i(t);
153
- } catch (n) {
154
- this.emitLifecycle("error", { error: n });
153
+ } catch (a) {
154
+ this.emitLifecycle("error", { error: a });
155
155
  }
156
156
  });
157
157
  });
@@ -181,7 +181,7 @@ class p {
181
181
  this.emitLifecycle("beforeUpdate", {
182
182
  previousState: h(this, l),
183
183
  nextState: t
184
- }), D(h(this, l), t) || (S(this, l, t), S(this, f, Date.now()), this.emitLifecycle("stateChange", { state: t }), this.notifySubscribers(t)), this.emitLifecycle("afterUpdate", { state: 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) => {
@@ -202,7 +202,7 @@ class p {
202
202
  this.set(this.initialState);
203
203
  });
204
204
  s(this, "lastUpdated", () => h(this, f));
205
- S(this, l, t), this.initialState = t, S(this, f, Date.now()), this.emitLifecycle("init", { initialState: h(this, l) });
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
208
  l = new WeakMap(), f = new WeakMap();
@@ -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, n;
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: (n = (i = this.config.user) == null ? void 0 : i.data) == null ? void 0 : n.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,15 +237,15 @@ class G {
237
237
  this.state.setPartial({ isCreatingUnverifiedContact: !1 });
238
238
  }
239
239
  });
240
- var i, n, r;
240
+ var i, a, r;
241
241
  this.config = t, this.api = e, this.state = new p({
242
- contact: (i = t.user) != null && i.token ? { token: (n = t.user) == null ? void 0 : n.token } : null,
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 x {
248
+ class v {
249
249
  constructor() {
250
250
  s(this, "state", new p({
251
251
  isPolling: !1,
@@ -259,7 +259,7 @@ class x {
259
259
  s(this, "stopPolling", null);
260
260
  s(this, "startPolling", (t, e) => {
261
261
  if (this.stopPolling) return;
262
- const i = [], n = async () => {
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 x {
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(n, e));
273
+ this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") : i.push(setTimeout(a, e));
274
274
  };
275
- n(), this.stopPolling = () => {
275
+ a(), this.stopPolling = () => {
276
276
  i.forEach(clearTimeout), this.state.reset();
277
277
  };
278
278
  });
279
279
  }
280
280
  }
281
- function P() {
282
- return _();
281
+ function y() {
282
+ return B();
283
283
  }
284
284
  class j {
285
285
  constructor({
@@ -290,8 +290,8 @@ class j {
290
290
  s(this, "config");
291
291
  s(this, "api");
292
292
  s(this, "contactCtx");
293
- s(this, "activeSessionPoller", new x());
294
- s(this, "sessionsRefresher", new x());
293
+ s(this, "activeSessionPoller", new v());
294
+ s(this, "sessionsRefresher", new v());
295
295
  s(this, "sessionState", new p({
296
296
  session: null,
297
297
  isCreatingSession: !1
@@ -335,17 +335,17 @@ class j {
335
335
  const { data: t } = await this.getSessions({ cursor: void 0 });
336
336
  if (!t) return;
337
337
  const e = [...t.items, ...this.sessionsState.get().data].filter(
338
- (i, n, r) => n === r.findIndex((c) => i.id === c.id)
338
+ (i, a, r) => a === r.findIndex((c) => i.id === c.id)
339
339
  );
340
340
  this.sessionsState.setPartial({ data: e });
341
341
  }, 1e4);
342
342
  });
343
343
  s(this, "createSession", async () => {
344
- var i, n;
344
+ var i, a;
345
345
  this.sessionState.setPartial({ session: null, isCreatingSession: !0 });
346
346
  const { data: t, error: e } = await this.api.createSession({
347
347
  customData: (i = this.config.user) != null && i.externalId ? {
348
- external_id: (n = this.config.user) == null ? void 0 : n.externalId
348
+ external_id: (a = this.config.user) == null ? void 0 : a.externalId
349
349
  } : void 0
350
350
  });
351
351
  return t ? (this.sessionState.setPartial({ session: t, isCreatingSession: !1 }), t) : (console.error("Failed to create session:", e), null);
@@ -360,7 +360,7 @@ class j {
360
360
  });
361
361
  if (t) {
362
362
  const i = [...this.sessionsState.get().data, ...t.items].filter(
363
- (n, r, c) => r === c.findIndex((d) => n.id === d.id)
363
+ (a, r, c) => r === c.findIndex((d) => a.id === d.id)
364
364
  );
365
365
  this.sessionsState.setPartial({
366
366
  data: i,
@@ -390,7 +390,7 @@ class u {
390
390
  s(this, "config");
391
391
  s(this, "api");
392
392
  s(this, "sessionCtx");
393
- s(this, "poller", new x());
393
+ s(this, "poller", new v());
394
394
  s(this, "state", new p({
395
395
  messages: [],
396
396
  isSendingMessage: !1,
@@ -409,9 +409,9 @@ class u {
409
409
  });
410
410
  });
411
411
  s(this, "sendMessage", async (t) => {
412
- var n, r, c, d, C, m, v, I, U;
412
+ var a, r, c, d, S, m, x, U, A;
413
413
  this.sendMessageAbortController = new AbortController();
414
- const e = this.state.get().isSendingMessage, i = ((n = this.sessionCtx.sessionState.get().session) == null ? void 0 : n.assignee.kind) === "ai";
414
+ const e = this.state.get().isSendingMessage, i = ((a = this.sessionCtx.sessionState.get().session) == null ? void 0 : a.assignee.kind) === "ai";
415
415
  if (e && i) {
416
416
  console.warn("Cannot send messages while awaiting AI response");
417
417
  return;
@@ -429,15 +429,15 @@ class u {
429
429
  console.error("Failed to create session");
430
430
  return;
431
431
  }
432
- const A = (c = this.sessionCtx.sessionState.get().session) == null ? void 0 : c.id;
433
- if (!A) return;
432
+ const I = (c = this.sessionCtx.sessionState.get().session) == null ? void 0 : c.id;
433
+ if (!I) return;
434
434
  const { data: o } = await this.api.sendMessage(
435
435
  {
436
436
  uuid: b.id,
437
437
  bot_token: this.config.token,
438
438
  headers: this.config.headers,
439
439
  query_params: this.config.queryParams,
440
- session_id: A,
440
+ session_id: I,
441
441
  user: (d = this.config.user) == null ? void 0 : d.data,
442
442
  ...t
443
443
  },
@@ -451,18 +451,18 @@ class u {
451
451
  (F) => F.id === g.id
452
452
  )) {
453
453
  this.state.setPartial({
454
- lastAIResMightSolveUserIssue: ((C = o.autopilotResponse) == null ? void 0 : C.mightSolveUserIssue) || ((m = o.uiResponse) == null ? void 0 : m.mightSolveUserIssue)
454
+ lastAIResMightSolveUserIssue: ((S = o.autopilotResponse) == null ? void 0 : S.mightSolveUserIssue) || ((m = o.uiResponse) == null ? void 0 : m.mightSolveUserIssue)
455
455
  });
456
456
  return;
457
457
  }
458
458
  this.state.setPartial({
459
459
  messages: [...w, g],
460
- lastAIResMightSolveUserIssue: ((v = o.autopilotResponse) == null ? void 0 : v.mightSolveUserIssue) || ((I = o.uiResponse) == null ? void 0 : I.mightSolveUserIssue)
460
+ lastAIResMightSolveUserIssue: ((x = o.autopilotResponse) == null ? void 0 : x.mightSolveUserIssue) || ((U = o.uiResponse) == null ? void 0 : U.mightSolveUserIssue)
461
461
  });
462
462
  }
463
463
  } else {
464
- const g = u.toErrorMessage(
465
- ((U = o == null ? void 0 : o.error) == null ? void 0 : U.message) || "Unknown error occurred"
464
+ const g = u.toBotErrorMessage(
465
+ ((A = o == null ? void 0 : o.error) == null ? void 0 : A.message) || "Unknown error occurred"
466
466
  ), w = this.state.get().messages;
467
467
  this.state.setPartial({
468
468
  messages: [...w, g]
@@ -477,14 +477,14 @@ class u {
477
477
  s(this, "fetchAndSetHistory", async (t, e) => {
478
478
  var r;
479
479
  this.state.get().messages.length === 0 && this.state.setPartial({ isInitialFetchLoading: !0 });
480
- const i = (r = this.state.get().messages.at(-1)) == null ? void 0 : r.timestamp, { data: n } = await this.api.getSessionHistory({
480
+ const i = (r = this.state.get().messages.at(-1)) == null ? void 0 : r.timestamp, { data: a } = await this.api.getSessionHistory({
481
481
  sessionId: t,
482
482
  lastMessageTimestamp: i,
483
483
  abortSignal: e
484
484
  });
485
- if (n && n.length > 0) {
486
- const c = this.state.get().messages, d = n.map(u.mapHistoryToMessage).filter(
487
- (C) => !c.some((m) => m.id === C.id)
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)
488
488
  );
489
489
  this.state.setPartial({
490
490
  messages: [...c, ...d]
@@ -496,24 +496,30 @@ class u {
496
496
  }
497
497
  /** Not the best name but whatever */
498
498
  static mapHistoryToMessage(t) {
499
+ var a;
499
500
  const e = {
500
501
  id: t.publicId,
501
502
  timestamp: t.sentAt || "",
502
503
  attachments: t.attachments || void 0
503
504
  };
504
- return t.sender.kind === "user" ? {
505
- ...e,
506
- type: "FROM_USER",
507
- content: t.content.text || "",
508
- deliveredAt: t.sentAt || ""
509
- } : t.sender.kind === "agent" ? {
510
- ...e,
511
- type: "FROM_AGENT",
512
- component: "agent_message",
513
- data: {
514
- message: t.content.text || ""
515
- }
516
- } : {
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 {
517
523
  ...e,
518
524
  type: "FROM_BOT",
519
525
  component: "bot_message",
@@ -524,13 +530,14 @@ class u {
524
530
  avatar: t.sender.avatar || null
525
531
  },
526
532
  data: {
527
- message: t.content.text
533
+ message: t.content.text || "",
534
+ action: i ? { name: i.actionName, data: i.result } : void 0
528
535
  }
529
536
  };
530
537
  }
531
538
  static toUserMessage(t, e) {
532
539
  return {
533
- id: P(),
540
+ id: y(),
534
541
  type: "FROM_USER",
535
542
  content: t,
536
543
  deliveredAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -539,42 +546,36 @@ class u {
539
546
  };
540
547
  }
541
548
  static toBotMessage(t) {
542
- if (t.success && t.autopilotResponse)
543
- return {
544
- type: "FROM_BOT",
545
- id: t.autopilotResponse.id || P(),
546
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
547
- component: "bot_message",
548
- data: {
549
- message: t.autopilotResponse.value.content
550
- }
551
- };
552
- if (t.success && t.uiResponse) {
553
- const e = t.uiResponse.value;
554
- return {
555
- type: "FROM_BOT",
556
- id: P(),
557
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
558
- component: e.name,
559
- data: e.request_response
560
- };
561
- }
562
- 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;
563
563
  }
564
- static toErrorMessage(t) {
564
+ static toBotErrorMessage(t) {
565
565
  return {
566
566
  type: "FROM_BOT",
567
- id: P(),
567
+ id: y(),
568
568
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
569
569
  component: "TEXT",
570
570
  data: {
571
571
  message: t,
572
- variant: "error"
572
+ variant: "error",
573
+ action: void 0
573
574
  }
574
575
  };
575
576
  }
576
577
  }
577
- class X {
578
+ class N {
578
579
  constructor({
579
580
  contactCtx: t,
580
581
  sessionCtx: e,
@@ -608,7 +609,7 @@ class X {
608
609
  }), this.contactCtx = t, this.sessionCtx = e, this.resetChat = i, this.registerRoutingListener();
609
610
  }
610
611
  }
611
- class K {
612
+ class Q {
612
613
  constructor({ config: t }) {
613
614
  s(this, "config");
614
615
  s(this, "api");
@@ -630,7 +631,7 @@ class K {
630
631
  config: this.config,
631
632
  api: this.api,
632
633
  sessionCtx: this.sessionCtx
633
- }), this.routerCtx = new X({
634
+ }), this.routerCtx = new N({
634
635
  contactCtx: this.contactCtx,
635
636
  sessionCtx: this.sessionCtx,
636
637
  resetChat: this.resetChat
@@ -639,6 +640,6 @@ class K {
639
640
  }
640
641
  export {
641
642
  p as P,
642
- K as W
643
+ Q as W
643
644
  };
644
- //# sourceMappingURL=widget.ctx-DkhYPIAY.js.map
645
+ //# sourceMappingURL=widget.ctx-naCIXuET.js.map