@opencx/widget-core 4.0.10 → 4.0.12

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 (84) hide show
  1. package/dist/index.cjs +2 -2
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +2 -15
  4. package/dist/index.js +316 -205
  5. package/dist/index.js.map +1 -1
  6. package/dist/src/__tests__/api-caller.mock.d.ts +2 -0
  7. package/dist/src/__tests__/api-caller.mock.d.ts.map +1 -0
  8. package/dist/src/__tests__/context/contact/auth/auto-create-unverified-anonymous.spec.d.ts +1 -0
  9. package/dist/src/__tests__/context/contact/auth/auto-create-unverified-anonymous.spec.d.ts.map +1 -0
  10. package/dist/src/__tests__/context/contact/auth/auto-create-unverified-with-user-data-provided-by-org.spec.d.ts +1 -0
  11. package/dist/src/__tests__/context/contact/auth/auto-create-unverified-with-user-data-provided-by-org.spec.d.ts.map +1 -0
  12. package/dist/src/__tests__/context/contact/auth/manually-create-unverified-with-user-data-provided-by-user.spec.d.ts +1 -0
  13. package/dist/src/__tests__/context/contact/auth/manually-create-unverified-with-user-data-provided-by-user.spec.d.ts.map +1 -0
  14. package/dist/src/__tests__/context/contact/auth/with-secure-token.spec.d.ts +1 -0
  15. package/dist/src/__tests__/context/contact/auth/with-secure-token.spec.d.ts.map +1 -0
  16. package/dist/src/__tests__/context/contact/should-collect-data.spec.d.ts +1 -0
  17. package/dist/src/__tests__/context/contact/should-collect-data.spec.d.ts.map +1 -0
  18. package/dist/{__tests__ → src/__tests__}/test-utils.d.ts +39 -0
  19. package/dist/src/__tests__/test-utils.d.ts.map +1 -0
  20. package/dist/src/__tests__/utils/Poller.spec.d.ts +2 -0
  21. package/dist/src/__tests__/utils/Poller.spec.d.ts.map +1 -0
  22. package/dist/src/__tests__/utils/PrimitiveState.spec.d.ts +2 -0
  23. package/dist/src/__tests__/utils/PrimitiveState.spec.d.ts.map +1 -0
  24. package/dist/{api → src/api}/api-caller.d.ts +39 -0
  25. package/dist/src/api/api-caller.d.ts.map +1 -0
  26. package/dist/{api → src/api}/client.d.ts +1 -0
  27. package/dist/src/api/client.d.ts.map +1 -0
  28. package/dist/{api → src/api}/schema.d.ts +96 -16
  29. package/dist/src/api/schema.d.ts.map +1 -0
  30. package/dist/{context → src/context}/active-session-polling.ctx.d.ts +10 -3
  31. package/dist/src/context/active-session-polling.ctx.d.ts.map +1 -0
  32. package/dist/{context → src/context}/contact.ctx.d.ts +1 -0
  33. package/dist/src/context/contact.ctx.d.ts.map +1 -0
  34. package/dist/src/context/csat.ctx.d.ts +31 -0
  35. package/dist/src/context/csat.ctx.d.ts.map +1 -0
  36. package/dist/{context → src/context}/message.ctx.d.ts +3 -2
  37. package/dist/src/context/message.ctx.d.ts.map +1 -0
  38. package/dist/{context → src/context}/router.ctx.d.ts +1 -0
  39. package/dist/src/context/router.ctx.d.ts.map +1 -0
  40. package/dist/{context → src/context}/session.ctx.d.ts +3 -2
  41. package/dist/src/context/session.ctx.d.ts.map +1 -0
  42. package/dist/{context → src/context}/storage.ctx.d.ts +1 -0
  43. package/dist/src/context/storage.ctx.d.ts.map +1 -0
  44. package/dist/{context → src/context}/widget.ctx.d.ts +3 -0
  45. package/dist/src/context/widget.ctx.d.ts.map +1 -0
  46. package/dist/src/index.d.ts +17 -0
  47. package/dist/src/index.d.ts.map +1 -0
  48. package/dist/{types → src/types}/agent-or-bot.d.ts +1 -0
  49. package/dist/src/types/agent-or-bot.d.ts.map +1 -0
  50. package/dist/{types → src/types}/component-name.d.ts +1 -0
  51. package/dist/src/types/component-name.d.ts.map +1 -0
  52. package/dist/{types → src/types}/dtos.d.ts +1 -0
  53. package/dist/src/types/dtos.d.ts.map +1 -0
  54. package/dist/{types → src/types}/external-storage.d.ts +1 -0
  55. package/dist/src/types/external-storage.d.ts.map +1 -0
  56. package/dist/{types → src/types}/helpers.d.ts +2 -0
  57. package/dist/src/types/helpers.d.ts.map +1 -0
  58. package/dist/{types → src/types}/icons.d.ts +1 -0
  59. package/dist/src/types/icons.d.ts.map +1 -0
  60. package/dist/{types → src/types}/json-value.d.ts +1 -0
  61. package/dist/src/types/json-value.d.ts.map +1 -0
  62. package/dist/{types → src/types}/messages.d.ts +43 -10
  63. package/dist/src/types/messages.d.ts.map +1 -0
  64. package/dist/{types → src/types}/widget-config.d.ts +1 -0
  65. package/dist/src/types/widget-config.d.ts.map +1 -0
  66. package/dist/{utils → src/utils}/Poller.d.ts +1 -0
  67. package/dist/src/utils/Poller.d.ts.map +1 -0
  68. package/dist/{utils → src/utils}/PrimitiveState.d.ts +1 -0
  69. package/dist/src/utils/PrimitiveState.d.ts.map +1 -0
  70. package/dist/{utils → src/utils}/is-exhaustive.d.ts +1 -0
  71. package/dist/src/utils/is-exhaustive.d.ts.map +1 -0
  72. package/dist/{utils → src/utils}/run-catching.d.ts +1 -0
  73. package/dist/src/utils/run-catching.d.ts.map +1 -0
  74. package/dist/{utils → src/utils}/uuid.d.ts +1 -0
  75. package/dist/src/utils/uuid.d.ts.map +1 -0
  76. package/package.json +2 -2
  77. package/dist/__tests__/api-caller.mock.d.ts +0 -1
  78. package/dist/__tests__/context/contact/auth/auto-create-unverified-anonymous.spec.d.ts +0 -0
  79. package/dist/__tests__/context/contact/auth/auto-create-unverified-with-user-data-provided-by-org.spec.d.ts +0 -0
  80. package/dist/__tests__/context/contact/auth/manually-create-unverified-with-user-data-provided-by-user.spec.d.ts +0 -0
  81. package/dist/__tests__/context/contact/auth/with-secure-token.spec.d.ts +0 -0
  82. package/dist/__tests__/context/contact/should-collect-data.spec.d.ts +0 -0
  83. package/dist/__tests__/utils/Poller.spec.d.ts +0 -1
  84. package/dist/__tests__/utils/PrimitiveState.spec.d.ts +0 -1
package/dist/index.js CHANGED
@@ -1,21 +1,21 @@
1
- import _ from "openapi-fetch";
2
- import B from "lodash.isequal";
1
+ import D from "openapi-fetch";
2
+ import L from "lodash.isequal";
3
3
  import { v4 as O } from "uuid";
4
- const L = (d) => {
5
- console.log(d.error);
6
- }, $ = (d) => {
7
- const n = _({
8
- baseUrl: d.baseUrl
9
- }), o = {
10
- onRequest: d.onRequest,
11
- onResponse: d.onResponse,
12
- onError: d.onError || L
4
+ const H = (g) => {
5
+ console.log(g.error);
6
+ }, q = (g) => {
7
+ const n = D({
8
+ baseUrl: g.baseUrl
9
+ }), a = {
10
+ onRequest: g.onRequest,
11
+ onResponse: g.onResponse,
12
+ onError: g.onError || H
13
13
  };
14
- return n.use(o), n;
14
+ return n.use(a), n;
15
15
  };
16
- class M {
16
+ class U {
17
17
  constructor({ config: n }) {
18
- var g, e;
18
+ var d, e;
19
19
  this.userToken = null, this.constructClientOptions = (t) => {
20
20
  const s = this.config.apiUrl || "https://api.open.cx", i = {
21
21
  "X-Bot-Token": this.config.token,
@@ -27,11 +27,11 @@ class M {
27
27
  }, this.createOpenAPIClient = ({
28
28
  baseUrl: t,
29
29
  headers: s
30
- }) => $({
30
+ }) => q({
31
31
  baseUrl: t,
32
32
  onRequest: ({ request: i }) => {
33
- Object.entries(s).forEach(([r, a]) => {
34
- a && i.headers.set(r, a);
33
+ Object.entries(s).forEach(([o, r]) => {
34
+ r && i.headers.set(o, r);
35
35
  });
36
36
  }
37
37
  }), this.setAuthToken = (t) => {
@@ -58,9 +58,9 @@ class M {
58
58
  lastMessageTimestamp: s,
59
59
  abortSignal: i
60
60
  }) => {
61
- const r = s ? { lastMessageTimestamp: s } : void 0;
61
+ const o = s ? { lastMessageTimestamp: s } : void 0;
62
62
  return await this.client.GET("/backend/widget/v2/poll/{sessionId}", {
63
- params: { path: { sessionId: t }, query: r },
63
+ params: { path: { sessionId: t }, query: o },
64
64
  signal: i
65
65
  });
66
66
  }, this.getSessions = async ({
@@ -74,85 +74,88 @@ class M {
74
74
  file: t,
75
75
  abortSignal: s,
76
76
  onProgress: i
77
- }) => new Promise((r, a) => {
78
- var b;
79
- const h = new FormData();
80
- h.append("file", t);
81
- const l = new XMLHttpRequest();
77
+ }) => new Promise((o, r) => {
78
+ var w;
79
+ const l = new FormData();
80
+ l.append("file", t);
81
+ const h = new XMLHttpRequest();
82
82
  if (s && (s.addEventListener("abort", () => {
83
- l.abort(), a(new DOMException("Aborted", "AbortError"));
83
+ h.abort(), r(new DOMException("Aborted", "AbortError"));
84
84
  }), s.aborted)) {
85
- a(new DOMException("Aborted", "AbortError"));
85
+ r(new DOMException("Aborted", "AbortError"));
86
86
  return;
87
87
  }
88
- l.upload.addEventListener("progress", (f) => {
88
+ h.upload.addEventListener("progress", (f) => {
89
89
  if (f.lengthComputable && i) {
90
90
  const S = Math.round(f.loaded / f.total * 100);
91
91
  i(S);
92
92
  }
93
- }), l.addEventListener("load", () => {
94
- if (l.status >= 200 && l.status < 300)
93
+ }), h.addEventListener("load", () => {
94
+ if (h.status >= 200 && h.status < 300)
95
95
  try {
96
- const f = JSON.parse(l.responseText);
97
- r(f);
96
+ const f = JSON.parse(h.responseText);
97
+ o(f);
98
98
  } catch (f) {
99
- a(new Error(`Failed to parse response: ${f}`));
99
+ r(new Error(`Failed to parse response: ${f}`));
100
100
  }
101
101
  else
102
- a(new Error(`Upload failed with status: ${l.status}`));
103
- }), l.addEventListener("error", () => {
104
- a(new Error("Network error occurred"));
105
- }), l.addEventListener("timeout", () => {
106
- a(new Error("Upload timed out"));
102
+ r(new Error(`Upload failed with status: ${h.status}`));
103
+ }), h.addEventListener("error", () => {
104
+ r(new Error("Network error occurred"));
105
+ }), h.addEventListener("timeout", () => {
106
+ r(new Error("Upload timed out"));
107
107
  });
108
- const { baseUrl: p } = this.constructClientOptions(this.userToken), m = `${p}/backend/widget/v2/upload`;
109
- l.open("POST", m), l.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((b = this.config.user) == null ? void 0 : b.token) ? l.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : console.error("User token not set"), l.send(h);
108
+ const { baseUrl: m } = this.constructClientOptions(this.userToken), C = `${m}/backend/widget/v2/upload`;
109
+ h.open("POST", C), h.setRequestHeader("X-Bot-Token", this.config.token), this.userToken ?? ((w = this.config.user) == null ? void 0 : w.token) ? h.setRequestHeader("Authorization", `Bearer ${this.userToken}`) : console.error("User token not set"), h.send(l);
110
110
  }), this.vote = async (t) => await this.client.POST("/backend/widget/v2/chat/vote", { body: t }), this.resolveSession = async (t, s) => await this.client.POST("/backend/widget/v2/session/resolve", {
111
111
  body: t,
112
112
  signal: s
113
113
  }), this.createStateCheckpoint = async (t) => await this.client.POST("/backend/widget/v2/checkpoint", {
114
114
  body: t
115
- }), this.config = n, this.userToken = ((g = n.user) == null ? void 0 : g.token) || null;
116
- const { baseUrl: o, headers: c } = this.constructClientOptions(
115
+ }), this.submitCsat = async (t) => await this.client.POST("/backend/widget/v2/submit-csat", { body: t }), this.config = n, this.userToken = ((d = n.user) == null ? void 0 : d.token) || null;
116
+ const { baseUrl: a, headers: c } = this.constructClientOptions(
117
117
  (e = n.user) == null ? void 0 : e.token
118
118
  );
119
- this.client = this.createOpenAPIClient({ baseUrl: o, headers: c });
119
+ this.client = this.createOpenAPIClient({ baseUrl: a, headers: c });
120
120
  }
121
121
  }
122
- class P {
122
+ function B(g, n) {
123
+ console.error(`Missing case for ${g} in ${n}`);
124
+ }
125
+ class y {
123
126
  constructor(n) {
124
- this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (o) => {
125
- B(this.state, o) || (this.state = o, this.notifySubscribers(o));
126
- }, this.setPartial = (o) => {
127
- if (o == null) return;
128
- const c = { ...this.state, ...o };
127
+ this.subscribers = /* @__PURE__ */ new Set(), this.get = () => this.state, this.set = (a) => {
128
+ L(this.state, a) || (this.state = a, this.notifySubscribers(a));
129
+ }, this.setPartial = (a) => {
130
+ if (a == null) return;
131
+ const c = { ...this.state, ...a };
129
132
  this.set(c);
130
133
  }, this.reset = () => {
131
134
  this.set(this.initialState);
132
- }, this.notifySubscribers = (o) => {
133
- Array.from(this.subscribers).forEach((g) => {
135
+ }, this.notifySubscribers = (a) => {
136
+ Array.from(this.subscribers).forEach((d) => {
134
137
  try {
135
- g(o);
138
+ d(a);
136
139
  } catch (e) {
137
140
  console.error(e);
138
141
  }
139
142
  });
140
- }, this.subscribe = (o) => (this.subscribers.add(o), () => {
141
- this.subscribers.delete(o);
143
+ }, this.subscribe = (a) => (this.subscribers.add(a), () => {
144
+ this.subscribers.delete(a);
142
145
  }), this.state = n, this.initialState = n;
143
146
  }
144
147
  }
145
148
  class F {
146
149
  constructor() {
147
- this.state = new P({
150
+ this.state = new y({
148
151
  isPolling: !1,
149
152
  isError: !1
150
153
  }), this.abortController = new AbortController(), this.reset = () => {
151
154
  var n;
152
155
  this.abortController.abort("Resetting poller"), (n = this.stopPolling) == null || n.call(this), this.stopPolling = null;
153
- }, this.stopPolling = null, this.startPolling = (n, o) => {
156
+ }, this.stopPolling = null, this.startPolling = (n, a) => {
154
157
  if (this.stopPolling) return;
155
- const c = [], g = async () => {
158
+ const c = [], d = async () => {
156
159
  this.abortController = new AbortController(), this.state.setPartial({ isPolling: !0 });
157
160
  try {
158
161
  await n(this.abortController.signal);
@@ -163,18 +166,18 @@ class F {
163
166
  } finally {
164
167
  this.state.setPartial({ isPolling: !1 });
165
168
  }
166
- this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") : c.push(setTimeout(g, o));
169
+ this.abortController.signal.aborted ? console.log("Poller aborted, not scheduling anymore") : c.push(setTimeout(d, a));
167
170
  };
168
- g(), this.stopPolling = () => {
171
+ d(), this.stopPolling = () => {
169
172
  c.forEach(clearTimeout), this.state.reset();
170
173
  };
171
174
  };
172
175
  }
173
176
  }
174
- function q(d) {
177
+ function $(g) {
175
178
  try {
176
- const n = d();
177
- return n instanceof Promise ? n.then((o) => ({ data: o })).catch((o) => ({ error: o })) : { data: n };
179
+ const n = g();
180
+ return n instanceof Promise ? n.then((a) => ({ data: a })).catch((a) => ({ error: a })) : { data: n };
178
181
  } catch (n) {
179
182
  return { error: n };
180
183
  }
@@ -182,36 +185,53 @@ function q(d) {
182
185
  class N {
183
186
  constructor({
184
187
  api: n,
185
- config: o,
188
+ config: a,
186
189
  sessionCtx: c,
187
- messageCtx: g,
190
+ messageCtx: d,
188
191
  sessionPollingIntervalSeconds: e
189
192
  }) {
190
- this.poller = new F(), this.registerPolling = () => {
193
+ this.poller = new F(), this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.registerPolling = () => {
191
194
  this.sessionCtx.sessionState.subscribe(({ session: t }) => {
192
195
  t != null && t.id ? this.poller.startPolling(async (s) => {
193
- this.hackAndSlash(t.id, s);
196
+ this.fetchSessionAndHistory({ sessionId: t.id, abortSignal: s });
194
197
  }, this.sessionPollingIntervalSeconds * 1e3) : this.poller.reset();
198
+ }), this.sessionCtx.sessionState.subscribe(({ session: t }) => {
199
+ if (t != null && t.id && !t.isOpened)
200
+ try {
201
+ this.fetchSessionAndFullHistoryAbortController = new AbortController(), this.fetchSessionAndHistory({
202
+ sessionId: t.id,
203
+ abortSignal: this.fetchSessionAndFullHistoryAbortController.signal,
204
+ fetchFullHistory: !0
205
+ });
206
+ } catch (s) {
207
+ this.fetchSessionAndFullHistoryAbortController.signal.aborted || console.error("Failed to fetch session and full history:", s);
208
+ }
209
+ else
210
+ this.fetchSessionAndFullHistoryAbortController.abort();
195
211
  });
196
- }, this.hackAndSlash = async (t, s) => {
212
+ }, this.fetchSessionAndHistory = async ({
213
+ sessionId: t,
214
+ abortSignal: s,
215
+ fetchFullHistory: i = !1
216
+ }) => {
197
217
  var h;
198
218
  this.messageCtx.state.get().messages.length === 0 && this.messageCtx.state.setPartial({ isInitialFetchLoading: !0 });
199
- const i = this.messageCtx.state.get().messages, r = i.length > 0 ? ((h = i[i.length - 1]) == null ? void 0 : h.timestamp) ?? void 0 : void 0, { data: a } = await this.api.pollSessionAndHistory({
219
+ const o = this.messageCtx.state.get().messages, r = o.length > 0 ? ((h = o[o.length - 1]) == null ? void 0 : h.timestamp) ?? void 0 : void 0, { data: l } = await this.api.pollSessionAndHistory({
200
220
  sessionId: t,
201
221
  abortSignal: s,
202
- lastMessageTimestamp: r
222
+ lastMessageTimestamp: i ? void 0 : r
203
223
  });
204
- if (a != null && a.session && (this.sessionCtx.sessionState.setPartial({ session: a.session }), this.sessionCtx.setSessions([a.session])), a != null && a.history && a.history.length > 0) {
205
- const l = this.messageCtx.state.get().messages, p = a.history.map(this.mapHistoryToMessage).filter(
206
- (v) => !l.some((m) => m.id === v.id)
224
+ if (l != null && l.session && (this.sessionCtx.sessionState.setPartial({ session: l.session }), this.sessionCtx.setSessions([l.session])), l != null && l.history && l.history.length > 0) {
225
+ const m = this.messageCtx.state.get().messages, v = l.history.map(this.mapHistoryToMessage).filter((C) => C !== null).filter(
226
+ (C) => !m.some((x) => x.id === C.id)
207
227
  );
208
228
  this.messageCtx.state.setPartial({
209
- messages: [...l, ...p]
229
+ messages: [...m, ...v]
210
230
  });
211
231
  }
212
232
  this.messageCtx.state.get().isInitialFetchLoading && this.messageCtx.state.setPartial({ isInitialFetchLoading: !1 });
213
233
  }, this.mapHistoryToMessage = (t) => {
214
- var r, a;
234
+ var i, o;
215
235
  const s = {
216
236
  id: t.publicId,
217
237
  timestamp: t.sentAt || "",
@@ -220,14 +240,14 @@ class N {
220
240
  if (t.sender.kind === "user")
221
241
  return {
222
242
  ...s,
223
- type: "FROM_USER",
243
+ type: "USER",
224
244
  content: t.content.text || "",
225
245
  deliveredAt: t.sentAt || ""
226
246
  };
227
247
  if (t.sender.kind === "agent")
228
248
  return {
229
249
  ...s,
230
- type: "FROM_AGENT",
250
+ type: "AGENT",
231
251
  component: "agent_message",
232
252
  data: {
233
253
  message: t.content.text || ""
@@ -239,67 +259,117 @@ class N {
239
259
  isAi: !1
240
260
  }
241
261
  };
242
- const i = t.actionCalls && t.actionCalls.length > 0 ? t.actionCalls[t.actionCalls.length - 1] : void 0;
243
- return {
244
- ...s,
245
- type: "FROM_BOT",
246
- component: "bot_message",
247
- agent: {
248
- id: null,
249
- name: ((r = this.config.bot) == null ? void 0 : r.name) || "",
250
- isAi: !0,
251
- avatar: ((a = this.config.bot) == null ? void 0 : a.avatar) || ""
252
- },
253
- data: {
254
- message: t.content.text || "",
255
- action: i ? {
256
- name: i.actionName,
257
- data: this.extractActionResult(i)
258
- } : void 0
259
- }
260
- };
262
+ if (t.sender.kind === "ai") {
263
+ const r = t.actionCalls && t.actionCalls.length > 0 ? t.actionCalls[t.actionCalls.length - 1] : void 0;
264
+ return {
265
+ ...s,
266
+ type: "AI",
267
+ component: "bot_message",
268
+ agent: {
269
+ id: null,
270
+ name: ((i = this.config.bot) == null ? void 0 : i.name) || "",
271
+ isAi: !0,
272
+ avatar: ((o = this.config.bot) == null ? void 0 : o.avatar) || ""
273
+ },
274
+ data: {
275
+ message: t.content.text || "",
276
+ action: r ? {
277
+ name: r.actionName,
278
+ data: this.extractActionResult(r)
279
+ } : void 0
280
+ }
281
+ };
282
+ }
283
+ if (t.sender.kind === "system") {
284
+ const r = this.constructSystemMessage(t);
285
+ return r === null ? null : { ...r };
286
+ }
287
+ return null;
288
+ }, this.constructSystemMessage = (t) => {
289
+ if (!t || !t.systemMessagePayload) return null;
290
+ switch (t.systemMessagePayload.type) {
291
+ case "state_checkpoint":
292
+ return {
293
+ id: t.publicId,
294
+ type: "SYSTEM",
295
+ subtype: "state_checkpoint",
296
+ data: { payload: t.systemMessagePayload.payload },
297
+ timestamp: t.sentAt || "",
298
+ attachments: void 0
299
+ };
300
+ case "csat_requested":
301
+ return {
302
+ id: t.publicId,
303
+ type: "SYSTEM",
304
+ subtype: "csat_requested",
305
+ data: { payload: void 0 },
306
+ timestamp: t.sentAt || "",
307
+ attachments: void 0
308
+ };
309
+ case "csat_submitted":
310
+ return {
311
+ id: t.publicId,
312
+ type: "SYSTEM",
313
+ subtype: "csat_submitted",
314
+ data: {
315
+ payload: {
316
+ score: t.systemMessagePayload.payload.score ?? void 0,
317
+ feedback: t.systemMessagePayload.payload.feedback ?? void 0
318
+ }
319
+ },
320
+ timestamp: t.sentAt || "",
321
+ attachments: void 0
322
+ };
323
+ case "none":
324
+ return null;
325
+ default:
326
+ return B(
327
+ t.systemMessagePayload,
328
+ this.constructSystemMessage.name
329
+ ), null;
330
+ }
261
331
  }, this.extractActionResult = (t) => {
262
332
  const s = t.result;
263
333
  if (s === null || typeof s != "object") return s;
264
334
  if ("responseBodyText" in s && typeof s.responseBodyText == "string") {
265
- const i = s.responseBodyText, r = q(() => JSON.parse(i)).data;
266
- if (r) return r;
335
+ const i = s.responseBodyText, o = $(() => JSON.parse(i)).data;
336
+ if (o) return o;
267
337
  }
268
338
  return t.result;
269
- }, this.api = n, this.config = o, this.sessionCtx = c, this.messageCtx = g, this.sessionPollingIntervalSeconds = e, this.registerPolling();
339
+ }, this.api = n, this.config = a, this.sessionCtx = c, this.messageCtx = d, this.sessionPollingIntervalSeconds = e, this.registerPolling();
270
340
  }
271
341
  }
272
- class H {
342
+ class Y {
273
343
  constructor({
274
344
  config: n,
275
- api: o,
345
+ api: a,
276
346
  storageCtx: c
277
347
  }) {
278
- var g;
348
+ var d;
279
349
  this.shouldCollectData = () => {
280
350
  var e;
281
351
  return !!(!((e = this.state.get().contact) != null && e.token) && this.config.collectUserData);
282
352
  }, this.autoCreateUnverifiedUserIfNotExists = async () => {
283
- var e, t, s, i, r, a, h, l, p, v, m, w, b, f;
353
+ var e, t, s, i, o, r, l, h, m, v, C, x, w, f;
284
354
  if (!((e = this.config.user) != null && e.token)) {
285
355
  if (this.config.collectUserData && !((s = (t = this.config.user) == null ? void 0 : t.data) != null && s.email)) {
286
356
  if ((i = this.config.extraDataCollectionFields) != null && i.length)
287
357
  return;
288
- const S = await ((r = this.storageCtx) == null ? void 0 : r.getContactToken());
358
+ const S = await ((o = this.storageCtx) == null ? void 0 : o.getContactToken());
289
359
  S && await this.setUnverifiedContact(S);
290
360
  return;
291
361
  }
292
- if (!((h = (a = this.config.user) == null ? void 0 : a.data) != null && h.email)) {
293
- const S = await ((l = this.storageCtx) == null ? void 0 : l.getContactToken());
362
+ if (!((l = (r = this.config.user) == null ? void 0 : r.data) != null && l.email)) {
363
+ const S = await ((h = this.storageCtx) == null ? void 0 : h.getContactToken());
294
364
  if (S) {
295
365
  await this.setUnverifiedContact(S);
296
366
  return;
297
367
  }
298
368
  }
299
369
  await this.createUnverifiedContact({
300
- email: (v = (p = this.config.user) == null ? void 0 : p.data) == null ? void 0 : v.email,
301
- non_verified_name: ((w = (m = this.config.user) == null ? void 0 : m.data) == null ? void 0 : w.name) || "Anonymous",
302
- non_verified_custom_data: (f = (b = this.config.user) == null ? void 0 : b.data) == null ? void 0 : f.customData
370
+ email: (v = (m = this.config.user) == null ? void 0 : m.data) == null ? void 0 : v.email,
371
+ non_verified_name: ((x = (C = this.config.user) == null ? void 0 : C.data) == null ? void 0 : x.name) || "Anonymous",
372
+ non_verified_custom_data: (f = (w = this.config.user) == null ? void 0 : w.data) == null ? void 0 : f.customData
303
373
  });
304
374
  }
305
375
  }, this.createUnverifiedContact = async (e, t) => {
@@ -315,11 +385,11 @@ class H {
315
385
  this.state.setPartial({ isCreatingUnverifiedContact: !1 });
316
386
  }
317
387
  }, this.setUnverifiedContact = async (e) => {
318
- var i, r, a, h;
319
- const t = await ((i = this.storageCtx) == null ? void 0 : i.getExternalContactId()), s = ((r = this.config.user) == null ? void 0 : r.externalId) || t || O();
320
- this.api.setAuthToken(e), await ((a = this.storageCtx) == null ? void 0 : a.setContactToken(e)), await ((h = this.storageCtx) == null ? void 0 : h.setExternalContactId(s)), this.state.setPartial({ contact: { token: e, externalId: s } });
321
- }, this.config = n, this.storageCtx = c, this.api = o, this.state = new P({
322
- contact: (g = n.user) != null && g.token ? {
388
+ var i, o, r, l;
389
+ const t = await ((i = this.storageCtx) == null ? void 0 : i.getExternalContactId()), s = ((o = this.config.user) == null ? void 0 : o.externalId) || t || O();
390
+ this.api.setAuthToken(e), await ((r = this.storageCtx) == null ? void 0 : r.setContactToken(e)), await ((l = this.storageCtx) == null ? void 0 : l.setExternalContactId(s)), this.state.setPartial({ contact: { token: e, externalId: s } });
391
+ }, this.config = n, this.storageCtx = c, this.api = a, this.state = new y({
392
+ contact: (d = n.user) != null && d.token ? {
323
393
  token: n.user.token,
324
394
  // Set optional externalId from config... not local storage
325
395
  externalId: n.user.externalId
@@ -330,21 +400,60 @@ class H {
330
400
  }), this.autoCreateUnverifiedUserIfNotExists();
331
401
  }
332
402
  }
333
- function k() {
403
+ function I() {
334
404
  return O();
335
405
  }
336
406
  class X {
337
407
  constructor({
338
408
  config: n,
339
- api: o,
409
+ api: a,
410
+ sessionCtx: c,
411
+ messageCtx: d
412
+ }) {
413
+ this.submitCsat = async (e) => {
414
+ var r;
415
+ const t = (r = this.sessionCtx.sessionState.get().session) == null ? void 0 : r.id;
416
+ if (!t)
417
+ return { data: null, error: "No session id found" };
418
+ const s = I();
419
+ this.messageCtx.state.setPartial({
420
+ messages: [
421
+ ...this.messageCtx.state.get().messages,
422
+ {
423
+ id: s,
424
+ type: "SYSTEM",
425
+ subtype: "csat_submitted",
426
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
427
+ data: {
428
+ payload: {
429
+ score: e.score,
430
+ feedback: e.feedback
431
+ }
432
+ }
433
+ }
434
+ ]
435
+ });
436
+ const { data: i, error: o } = await this.api.submitCsat({
437
+ ...e,
438
+ system_message_uuid: s,
439
+ session_id: t
440
+ });
441
+ return { data: i, error: o };
442
+ }, this.config = n, this.api = a, this.sessionCtx = c, this.messageCtx = d;
443
+ }
444
+ }
445
+ class G {
446
+ constructor({
447
+ config: n,
448
+ api: a,
340
449
  contactCtx: c,
341
- sessionsPollingIntervalSeconds: g
450
+ sessionsPollingIntervalSeconds: d
342
451
  }) {
343
- this.sessionsRefresher = new F(), this.sessionState = new P({
452
+ this.sessionsRefresher = new F(), this.sessionState = new y({
344
453
  session: null,
345
454
  isCreatingSession: !1,
346
455
  isResolvingSession: !1
347
- }), this.sessionsState = new P({
456
+ }), this.sessionsState = new y({
348
457
  data: [],
349
458
  cursor: void 0,
350
459
  isLastPage: !1,
@@ -366,9 +475,9 @@ class X {
366
475
  this.sessionsState.get().didStartInitialFetch === !1 && this.sessionsState.setPartial({ didStartInitialFetch: !0 }), await this.refreshSessions(), this.sessionsState.get().isInitialFetchLoading === !0 && this.sessionsState.setPartial({ isInitialFetchLoading: !1 });
367
476
  }, this.sessionsPollingIntervalSeconds * 1e3);
368
477
  }, this.createSession = async () => {
369
- var r;
478
+ var o;
370
479
  this.sessionState.setPartial({ session: null, isCreatingSession: !0 });
371
- const e = (r = this.contactCtx.state.get().contact) == null ? void 0 : r.externalId, t = {
480
+ const e = (o = this.contactCtx.state.get().contact) == null ? void 0 : o.externalId, t = {
372
481
  ...this.config.sessionCustomData,
373
482
  ...e ? { external_id: e } : {}
374
483
  }, { data: s, error: i } = await this.api.createSession({
@@ -382,7 +491,7 @@ class X {
382
491
  });
383
492
  if (e) {
384
493
  const s = [...this.sessionsState.get().data, ...e.items].filter(
385
- (i, r, a) => r === a.findIndex((h) => i.id === h.id)
494
+ (i, o, r) => o === r.findIndex((l) => i.id === l.id)
386
495
  );
387
496
  this.sessionsState.setPartial({
388
497
  data: s,
@@ -402,7 +511,7 @@ class X {
402
511
  });
403
512
  }, this.setSessions = (e) => {
404
513
  const t = [...e, ...this.sessionsState.get().data].filter(
405
- (s, i, r) => i === r.findIndex((a) => s.id === a.id)
514
+ (s, i, o) => i === o.findIndex((r) => s.id === r.id)
406
515
  );
407
516
  this.sessionsState.setPartial({ data: t });
408
517
  }, this.refreshSessions = async () => {
@@ -418,25 +527,25 @@ class X {
418
527
  });
419
528
  return t ? (this.sessionState.setPartial({ session: t, isResolvingSession: !1 }), { success: !0, data: t }) : (this.sessionState.setPartial({ isResolvingSession: !1 }), { success: !1, error: s });
420
529
  }, this.createStateCheckpoint = async (e) => {
421
- var r;
422
- const t = (r = this.sessionState.get().session) == null ? void 0 : r.id;
530
+ var o;
531
+ const t = (o = this.sessionState.get().session) == null ? void 0 : o.id;
423
532
  if (!t) return;
424
533
  const { data: s, error: i } = await this.api.createStateCheckpoint({
425
534
  session_id: t,
426
535
  payload: e
427
536
  });
428
537
  return s ? { data: s } : { success: !1, error: i };
429
- }, this.config = n, this.api = o, this.contactCtx = c, this.sessionsPollingIntervalSeconds = g, this.registerSessionsRefresherWrapper();
538
+ }, this.config = n, this.api = a, this.contactCtx = c, this.sessionsPollingIntervalSeconds = d, this.registerSessionsRefresherWrapper();
430
539
  }
431
540
  }
432
- class G {
541
+ class K {
433
542
  constructor({
434
543
  config: n,
435
- api: o,
544
+ api: a,
436
545
  sessionCtx: c,
437
- contactCtx: g
546
+ contactCtx: d
438
547
  }) {
439
- this.state = new P({
548
+ this.state = new y({
440
549
  messages: [],
441
550
  isSendingMessage: !1,
442
551
  lastAIResMightSolveUserIssue: !1,
@@ -444,7 +553,7 @@ class G {
444
553
  }), this.sendMessageAbortController = new AbortController(), this.reset = () => {
445
554
  this.sendMessageAbortController.abort("Resetting chat"), this.state.reset();
446
555
  }, this.sendMessage = async (e) => {
447
- var t, s, i, r, a, h, l, p, v, m;
556
+ var t, s, i, o, r, l, h, m, v, C;
448
557
  try {
449
558
  if (!e.content.trim() && (!e.attachments || e.attachments.length === 0)) {
450
559
  console.warn(
@@ -452,51 +561,51 @@ class G {
452
561
  );
453
562
  return;
454
563
  }
455
- const w = this.state.get().isSendingMessage, b = ((t = this.sessionCtx.sessionState.get().session) == null ? void 0 : t.assignee.kind) === "ai", f = this.state.get().messages, S = f.length > 0 ? f[f.length - 1] : void 0;
456
- if (b && w || // If last message is from user, then bot response did not arrive yet
457
- b && (S == null ? void 0 : S.type) === "FROM_USER") {
564
+ const x = this.state.get().isSendingMessage, w = ((t = this.sessionCtx.sessionState.get().session) == null ? void 0 : t.assignee.kind) === "ai", f = this.state.get().messages, S = f.length > 0 ? f[f.length - 1] : void 0;
565
+ if (w && x || // If last message is from user, then bot response did not arrive yet
566
+ w && (S == null ? void 0 : S.type) === "USER") {
458
567
  console.warn("Cannot send messages while awaiting AI response");
459
568
  return;
460
569
  }
461
570
  this.sendMessageAbortController = new AbortController(), this.state.setPartial({ lastAIResMightSolveUserIssue: !1 }), this.state.setPartial({ isSendingMessage: !0 });
462
- const T = this.state.get().messages, E = !((s = this.sessionCtx.sessionState.get().session) != null && s.id) && T.length === 0 && ((i = this.config.advancedInitialMessages) == null ? void 0 : i.some((u) => u.persistent)), R = E ? (this.config.advancedInitialMessages || []).filter((u) => u.persistent).map(
571
+ const A = this.state.get().messages, M = !((s = this.sessionCtx.sessionState.get().session) != null && s.id) && A.length === 0 && ((i = this.config.advancedInitialMessages) == null ? void 0 : i.some((u) => u.persistent)), E = M ? (this.config.advancedInitialMessages || []).filter((u) => u.persistent).map(
463
572
  (u) => ({
464
- id: k(),
573
+ id: I(),
465
574
  component: "bot_message",
466
- type: "FROM_BOT",
575
+ type: "AI",
467
576
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
468
577
  data: {
469
578
  message: u.message
470
579
  }
471
580
  })
472
- ) : [], y = this.toUserMessage(
581
+ ) : [], k = this.toUserMessage(
473
582
  e.content.trim(),
474
583
  e.attachments || void 0
475
584
  );
476
585
  if (this.state.setPartial({
477
586
  messages: [
478
- ...R,
479
- ...T,
480
- y
587
+ ...E,
588
+ ...A,
589
+ k
481
590
  ]
482
- }), !((r = this.sessionCtx.sessionState.get().session) != null && r.id)) {
591
+ }), !((o = this.sessionCtx.sessionState.get().session) != null && o.id)) {
483
592
  if (!await this.sessionCtx.createSession()) {
484
593
  console.error("Failed to create session");
485
594
  return;
486
595
  }
487
596
  this.sessionCtx.refreshSessions();
488
597
  }
489
- const U = (a = this.sessionCtx.sessionState.get().session) == null ? void 0 : a.id;
490
- if (!U) return;
491
- const { data: C } = await this.api.sendMessage(
598
+ const T = (r = this.sessionCtx.sessionState.get().session) == null ? void 0 : r.id;
599
+ if (!T) return;
600
+ const { data: p } = await this.api.sendMessage(
492
601
  {
493
- uuid: y.id,
602
+ uuid: k.id,
494
603
  bot_token: this.config.token,
495
604
  headers: this.config.headers,
496
605
  query_params: this.config.queryParams,
497
606
  body_properties: this.config.bodyProperties,
498
- session_id: U,
499
- content: y.content,
607
+ session_id: T,
608
+ content: k.content,
500
609
  attachments: e.attachments,
501
610
  clientContext: this.config.context,
502
611
  custom_data: {
@@ -505,55 +614,55 @@ class G {
505
614
  },
506
615
  language: this.config.language,
507
616
  exit_mode_prompt: e.exitModePrompt,
508
- initial_messages: E ? R.map((u) => ({
617
+ initial_messages: M ? E.map((u) => ({
509
618
  uuid: u.id,
510
619
  content: u.data.message
511
620
  })) : void 0
512
621
  },
513
622
  this.sendMessageAbortController.signal
514
623
  );
515
- if (C != null && C.success) {
516
- const u = this.toBotMessage(C);
624
+ if (p != null && p.success) {
625
+ const u = this.toBotMessage(p);
517
626
  if (u) {
518
- const I = this.state.get().messages;
519
- if (!!I.some(
520
- (D) => D.id === u.id
627
+ const P = this.state.get().messages;
628
+ if (!!P.some(
629
+ (_) => _.id === u.id
521
630
  )) {
522
631
  this.state.setPartial({
523
- lastAIResMightSolveUserIssue: ((h = C.autopilotResponse) == null ? void 0 : h.mightSolveUserIssue) || ((l = C.uiResponse) == null ? void 0 : l.mightSolveUserIssue)
632
+ lastAIResMightSolveUserIssue: ((l = p.autopilotResponse) == null ? void 0 : l.mightSolveUserIssue) || ((h = p.uiResponse) == null ? void 0 : h.mightSolveUserIssue)
524
633
  });
525
634
  return;
526
635
  }
527
636
  this.state.setPartial({
528
- messages: [...I, u],
529
- lastAIResMightSolveUserIssue: ((p = C.autopilotResponse) == null ? void 0 : p.mightSolveUserIssue) || ((v = C.uiResponse) == null ? void 0 : v.mightSolveUserIssue)
637
+ messages: [...P, u],
638
+ lastAIResMightSolveUserIssue: ((m = p.autopilotResponse) == null ? void 0 : m.mightSolveUserIssue) || ((v = p.uiResponse) == null ? void 0 : v.mightSolveUserIssue)
530
639
  });
531
640
  }
532
- C.session && this.sessionCtx.sessionState.setPartial({ session: C.session });
641
+ p.session && this.sessionCtx.sessionState.setPartial({ session: p.session });
533
642
  } else {
534
643
  const u = this.toBotErrorMessage(
535
- ((m = C == null ? void 0 : C.error) == null ? void 0 : m.message) || "Unknown error occurred"
536
- ), I = this.state.get().messages;
644
+ ((C = p == null ? void 0 : p.error) == null ? void 0 : C.message) || "Unknown error occurred"
645
+ ), P = this.state.get().messages;
537
646
  this.state.setPartial({
538
- messages: [...I, u]
647
+ messages: [...P, u]
539
648
  });
540
649
  }
541
- } catch (w) {
542
- this.sendMessageAbortController.signal.aborted || console.error("Failed to send message:", w);
650
+ } catch (x) {
651
+ this.sendMessageAbortController.signal.aborted || console.error("Failed to send message:", x);
543
652
  } finally {
544
653
  this.state.setPartial({ isSendingMessage: !1 });
545
654
  }
546
655
  }, this.toUserMessage = (e, t) => {
547
656
  const s = (() => {
548
657
  const i = this.contactCtx.state.get().extraCollectedData;
549
- return this.state.get().messages.length === 0 && i && Object.keys(i).length > 0 ? `${Object.entries(i).filter(([a, h]) => !!h).map(([a, h]) => `${a}: ${h}`).join(`
658
+ return this.state.get().messages.length === 0 && i && Object.keys(i).length > 0 ? `${Object.entries(i).filter(([r, l]) => !!l).map(([r, l]) => `${r}: ${l}`).join(`
550
659
  `)}
551
660
 
552
661
  ${e}` : e;
553
662
  })();
554
663
  return {
555
- id: k(),
556
- type: "FROM_USER",
664
+ id: I(),
665
+ type: "USER",
557
666
  content: s,
558
667
  deliveredAt: (/* @__PURE__ */ new Date()).toISOString(),
559
668
  attachments: t,
@@ -562,8 +671,8 @@ ${e}` : e;
562
671
  }, this.toBotMessage = (e) => {
563
672
  var t;
564
673
  return e.success && e.autopilotResponse ? {
565
- type: "FROM_BOT",
566
- id: e.autopilotResponse.id || k(),
674
+ type: "AI",
675
+ id: e.autopilotResponse.id || I(),
567
676
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
568
677
  component: "bot_message",
569
678
  agent: this.config.bot ? {
@@ -581,8 +690,8 @@ ${e}` : e;
581
690
  }
582
691
  } : null;
583
692
  }, this.toBotErrorMessage = (e) => ({
584
- type: "FROM_BOT",
585
- id: k(),
693
+ type: "AI",
694
+ id: I(),
586
695
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
587
696
  component: "TEXT",
588
697
  data: {
@@ -590,15 +699,15 @@ ${e}` : e;
590
699
  variant: "error",
591
700
  action: void 0
592
701
  }
593
- }), this.config = n, this.api = o, this.sessionCtx = c, this.contactCtx = g;
702
+ }), this.config = n, this.api = a, this.sessionCtx = c, this.contactCtx = d;
594
703
  }
595
704
  }
596
- class K {
705
+ class z {
597
706
  constructor({
598
707
  config: n,
599
- contactCtx: o,
708
+ contactCtx: a,
600
709
  sessionCtx: c,
601
- resetChat: g
710
+ resetChat: d
602
711
  }) {
603
712
  var e;
604
713
  this.registerRoutingListener = () => {
@@ -609,14 +718,14 @@ class K {
609
718
  });
610
719
  }), this.sessionCtx.sessionsState.subscribe(
611
720
  ({ isInitialFetchLoading: t, data: s }) => {
612
- var i, r, a, h;
721
+ var i, o, r, l;
613
722
  if ((i = this.config.router) != null && i.chatScreenOnly && // Do not route to a chat if we are currently inside one already
614
723
  // This also applies to newly created sessions; the new session will be in `sessionState` before it is refreshed and included in `sessionsState`
615
- !((r = this.sessionCtx.sessionState.get().session) != null && r.id)) {
616
- const l = (a = s.find((p) => p.isOpened)) == null ? void 0 : a.id;
617
- return l ? this.toChatScreen(l) : void 0;
724
+ !((o = this.sessionCtx.sessionState.get().session) != null && o.id)) {
725
+ const h = (r = s.find((m) => m.isOpened)) == null ? void 0 : r.id;
726
+ return h ? this.toChatScreen(h) : void 0;
618
727
  }
619
- s.length || ((h = this.config.router) == null ? void 0 : h.goToChatIfNoSessions) !== !1 && !t && this.state.get().screen !== "chat" && this.toChatScreen();
728
+ s.length || ((l = this.config.router) == null ? void 0 : l.goToChatIfNoSessions) !== !1 && !t && this.state.get().screen !== "chat" && this.toChatScreen();
620
729
  }
621
730
  );
622
731
  }, this.toSessionsScreen = () => {
@@ -628,15 +737,15 @@ class K {
628
737
  this.sessionCtx.sessionState.setPartial({ session: s });
629
738
  }
630
739
  this.state.setPartial({ screen: "chat" });
631
- }, this.config = n, this.contactCtx = o, this.sessionCtx = c, this.resetChat = g, this.state = new P({
740
+ }, this.config = n, this.contactCtx = a, this.sessionCtx = c, this.resetChat = d, this.state = new y({
632
741
  screen: this.contactCtx.shouldCollectData() ? "welcome" : (e = this.config.router) != null && e.chatScreenOnly ? "chat" : "sessions"
633
742
  }), this.registerRoutingListener();
634
743
  }
635
744
  }
636
- class Y {
745
+ class j {
637
746
  constructor({
638
747
  storage: n,
639
- config: o
748
+ config: a
640
749
  }) {
641
750
  this.KEYS = {
642
751
  contactToken: (c) => `opencx-widget:org-token-${c}:contact-token`,
@@ -645,42 +754,47 @@ class Y {
645
754
  await this.storage.set(this.KEYS.contactToken(this.config.token), c);
646
755
  }, this.getContactToken = async () => this.storage.get(this.KEYS.contactToken(this.config.token)), this.setExternalContactId = async (c) => {
647
756
  await this.storage.set(this.KEYS.externalContactId(this.config.token), c);
648
- }, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId(this.config.token)), this.storage = n, this.config = o;
757
+ }, this.getExternalContactId = async () => this.storage.get(this.KEYS.externalContactId(this.config.token)), this.storage = n, this.config = a;
649
758
  }
650
759
  }
651
- const x = class x {
760
+ const b = class b {
652
761
  constructor({
653
762
  config: n,
654
- storage: o,
763
+ storage: a,
655
764
  modes: c
656
765
  }) {
657
766
  if (this.modes = [], this.resetChat = () => {
658
767
  this.sessionCtx.reset(), this.messageCtx.reset();
659
- }, !x.pollingIntervalsSeconds)
768
+ }, !b.pollingIntervalsSeconds)
660
769
  throw Error(
661
770
  "Widget polling values are not defined, did you call WidgetCtx.initialize()"
662
771
  );
663
- this.config = n, this.api = new M({ config: n }), this.storageCtx = o ? new Y({ storage: o, config: n }) : void 0, this.modes = c, this.contactCtx = new H({
772
+ this.config = n, this.api = new U({ config: n }), this.storageCtx = a ? new j({ storage: a, config: n }) : void 0, this.modes = c, this.contactCtx = new Y({
664
773
  api: this.api,
665
774
  config: this.config,
666
775
  storageCtx: this.storageCtx
667
- }), this.sessionCtx = new X({
776
+ }), this.sessionCtx = new G({
668
777
  config: this.config,
669
778
  api: this.api,
670
779
  contactCtx: this.contactCtx,
671
- sessionsPollingIntervalSeconds: x.pollingIntervalsSeconds.sessions
672
- }), this.messageCtx = new G({
780
+ sessionsPollingIntervalSeconds: b.pollingIntervalsSeconds.sessions
781
+ }), this.messageCtx = new K({
673
782
  config: this.config,
674
783
  api: this.api,
675
784
  sessionCtx: this.sessionCtx,
676
785
  contactCtx: this.contactCtx
786
+ }), this.csatCtx = new X({
787
+ config: this.config,
788
+ api: this.api,
789
+ sessionCtx: this.sessionCtx,
790
+ messageCtx: this.messageCtx
677
791
  }), this.activeSessionPollingCtx = new N({
678
792
  api: this.api,
679
793
  config: this.config,
680
794
  sessionCtx: this.sessionCtx,
681
795
  messageCtx: this.messageCtx,
682
- sessionPollingIntervalSeconds: x.pollingIntervalsSeconds.session
683
- }), this.routerCtx = new K({
796
+ sessionPollingIntervalSeconds: b.pollingIntervalsSeconds.session
797
+ }), this.routerCtx = new z({
684
798
  config: this.config,
685
799
  contactCtx: this.contactCtx,
686
800
  sessionCtx: this.sessionCtx,
@@ -688,30 +802,27 @@ const x = class x {
688
802
  });
689
803
  }
690
804
  };
691
- x.pollingIntervalsSeconds = null, x.initialize = async ({
805
+ b.pollingIntervalsSeconds = null, b.initialize = async ({
692
806
  config: n,
693
- storage: o
807
+ storage: a
694
808
  }) => {
695
- var g, e, t;
696
- const c = await new M({
809
+ var d, e, t;
810
+ const c = await new U({
697
811
  config: n
698
812
  }).getExternalWidgetConfig();
699
- return x.pollingIntervalsSeconds = {
700
- session: ((g = c.data) == null ? void 0 : g.sessionPollingIntervalSeconds) || 10,
813
+ return b.pollingIntervalsSeconds = {
814
+ session: ((d = c.data) == null ? void 0 : d.sessionPollingIntervalSeconds) || 10,
701
815
  sessions: ((e = c.data) == null ? void 0 : e.sessionsPollingIntervalSeconds) || 60
702
- }, new x({
816
+ }, new b({
703
817
  config: n,
704
- storage: o,
818
+ storage: a,
705
819
  modes: ((t = c.data) == null ? void 0 : t.modes) || []
706
820
  });
707
821
  };
708
- let A = x;
709
- function Q(d, n) {
710
- console.error(`Missing case for ${d} in ${n}`);
711
- }
822
+ let R = b;
712
823
  export {
713
- P as PrimitiveState,
714
- A as WidgetCtx,
715
- Q as isExhaustive
824
+ y as PrimitiveState,
825
+ R as WidgetCtx,
826
+ B as isExhaustive
716
827
  };
717
828
  //# sourceMappingURL=index.js.map