@origonai/web-chat-sdk 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,48 +1,48 @@
1
- import { fetchEventSource as ie } from "@microsoft/fetch-event-source";
2
- function B() {
3
- const e = Date.now(), t = new Uint8Array(16);
4
- crypto.getRandomValues(t), t[0] = e >> 40 & 255, t[1] = e >> 32 & 255, t[2] = e >> 24 & 255, t[3] = e >> 16 & 255, t[4] = e >> 8 & 255, t[5] = e & 255, t[6] = t[6] & 15 | 112, t[8] = t[8] & 63 | 128;
5
- const s = [...t].map((a) => a.toString(16).padStart(2, "0")).join("");
6
- return `${s.slice(0, 8)}-${s.slice(8, 12)}-${s.slice(12, 16)}-${s.slice(
1
+ import { fetchEventSource as de } from "@microsoft/fetch-event-source";
2
+ function X() {
3
+ const e = Date.now(), n = new Uint8Array(16);
4
+ crypto.getRandomValues(n), n[0] = e >> 40 & 255, n[1] = e >> 32 & 255, n[2] = e >> 24 & 255, n[3] = e >> 16 & 255, n[4] = e >> 8 & 255, n[5] = e & 255, n[6] = n[6] & 15 | 112, n[8] = n[8] & 63 | 128;
5
+ const o = [...n].map((r) => r.toString(16).padStart(2, "0")).join("");
6
+ return `${o.slice(0, 8)}-${o.slice(8, 12)}-${o.slice(12, 16)}-${o.slice(
7
7
  16,
8
8
  20
9
- )}-${s.slice(20)}`;
9
+ )}-${o.slice(20)}`;
10
10
  }
11
- function le() {
11
+ function ue() {
12
12
  if (localStorage.getItem("chatDeviceId"))
13
13
  return localStorage.getItem("chatDeviceId");
14
- const e = B();
14
+ const e = X();
15
15
  return localStorage.setItem("chatDeviceId", e), e;
16
16
  }
17
- async function de(e) {
18
- return new Promise((t) => setTimeout(t, e));
17
+ async function ge(e) {
18
+ return new Promise((n) => setTimeout(n, e));
19
19
  }
20
- function ue(e) {
21
- let t;
20
+ function fe(e) {
21
+ let n;
22
22
  try {
23
- const s = new URL(e);
24
- t = `https://${s.hostname}${s.pathname}/sse`;
25
- } catch (s) {
23
+ const o = new URL(e);
24
+ n = `https://${o.hostname}${o.pathname}/sse`;
25
+ } catch (o) {
26
26
  }
27
- return t;
27
+ return n;
28
28
  }
29
- function ge(e) {
30
- let t;
29
+ function pe(e) {
30
+ let n;
31
31
  try {
32
- const s = new URL(e);
33
- t = `wss://${s.hostname}${s.pathname}/wss`;
34
- } catch (s) {
32
+ const o = new URL(e);
33
+ n = `wss://${o.hostname}${o.pathname}/wss`;
34
+ } catch (o) {
35
35
  }
36
- return t;
36
+ return n;
37
37
  }
38
- function fe(e) {
39
- let t;
38
+ function me(e) {
39
+ let n;
40
40
  try {
41
- const s = new URL(e);
42
- t = `wss://${s.hostname}${s.pathname}/audio`;
43
- } catch (s) {
41
+ const o = new URL(e);
42
+ n = `wss://${o.hostname}${o.pathname}/audio`;
43
+ } catch (o) {
44
44
  }
45
- return t;
45
+ return n;
46
46
  }
47
47
  const y = {
48
48
  ASSISTANT: "assistant",
@@ -53,13 +53,13 @@ const y = {
53
53
  // this is human supervisor (ex. Samespace Dock agent, or Resolve human agent)
54
54
  SYSTEM: "system"
55
55
  // this is system message, for ex "Agent joined" / "Agent left"
56
- }, Q = 1e4, pe = 5e3, D = {
56
+ }, Z = 1e4, Se = 5e3, D = {
57
57
  MESSAGE: "message",
58
58
  TYPING: "typing",
59
59
  TYPING_STOP: "typingOff",
60
60
  END: "end"
61
61
  };
62
- function me() {
62
+ function ke() {
63
63
  return {
64
64
  socket: null,
65
65
  previouslyConnected: !1,
@@ -69,112 +69,112 @@ function me() {
69
69
  socketConnectionTimeout: null
70
70
  };
71
71
  }
72
- let c = me();
73
- function U() {
74
- c.pingInterval && (clearInterval(c.pingInterval), c.pingInterval = null);
75
- }
76
- function Se() {
77
- U(), c.pingInterval = setInterval(() => {
78
- c.socket && c.socket.readyState === WebSocket.OPEN ? O({ type: "ping" }) : U();
79
- }, Q);
72
+ let a = ke();
73
+ function M() {
74
+ a.pingInterval && (clearInterval(a.pingInterval), a.pingInterval = null);
80
75
  }
81
- function Z() {
82
- U(), c.socketDisconnectedTimeout && (clearTimeout(c.socketDisconnectedTimeout), c.socketDisconnectedTimeout = null), c.socketConnectionTimeout && (clearTimeout(c.socketConnectionTimeout), c.socketConnectionTimeout = null);
76
+ function Ie() {
77
+ M(), a.pingInterval = setInterval(() => {
78
+ a.socket && a.socket.readyState === WebSocket.OPEN ? x({ type: "ping" }) : M();
79
+ }, Z);
83
80
  }
84
81
  function j() {
85
- c.socketDisconnected = !1, $("socket");
82
+ M(), a.socketDisconnectedTimeout && (clearTimeout(a.socketDisconnectedTimeout), a.socketDisconnectedTimeout = null), a.socketConnectionTimeout && (clearTimeout(a.socketConnectionTimeout), a.socketConnectionTimeout = null);
86
83
  }
87
- function X() {
88
- c.socketDisconnected = !0, $("sse");
84
+ function ee() {
85
+ a.socketDisconnected = !1, O("socket");
86
+ }
87
+ function ne() {
88
+ a.socketDisconnected = !0, O("sse");
89
89
  }
90
- function ke(e) {
91
- return new Promise((t, s) => {
92
- if (c.socket && (c.socket.readyState === WebSocket.CONNECTING || c.socket.readyState === WebSocket.OPEN)) {
93
- t(c.socket.readyState === WebSocket.OPEN);
90
+ function he(e) {
91
+ return new Promise((n, o) => {
92
+ if (a.socket && (a.socket.readyState === WebSocket.CONNECTING || a.socket.readyState === WebSocket.OPEN)) {
93
+ n(a.socket.readyState === WebSocket.OPEN);
94
94
  return;
95
95
  }
96
- const a = N();
97
- if (!a || !a.endpoint) {
98
- s(new Error("SDK not initialized. Please initialize SDK first."));
96
+ const r = b();
97
+ if (!r || !r.endpoint) {
98
+ o(new Error("SDK not initialized. Please initialize SDK first."));
99
99
  return;
100
100
  }
101
- const d = ge(a.endpoint);
102
- if (!d) {
103
- s(
101
+ const l = pe(r.endpoint);
102
+ if (!l) {
103
+ o(
104
104
  new Error(
105
105
  "Invalid endpoint while initializing SDK. Please check the endpoint and try again."
106
106
  )
107
107
  );
108
108
  return;
109
109
  }
110
- const f = A(), i = new URLSearchParams({
111
- externalId: f
110
+ const d = P(), c = new URLSearchParams({
111
+ externalId: d
112
112
  });
113
- e.sessionId && i.set("sessionId", e.sessionId), e.requestId && i.set("requestId", e.requestId), a.token && i.set("token", a.token);
114
- const u = `${d}?${i.toString()}`;
115
- c.socket = new WebSocket(u), c.socket.onopen = () => {
116
- c.previouslyConnected = !0, j(), O({ type: "ping" }), clearTimeout(c.socketConnectionTimeout), Se(), t(!0);
117
- }, c.socket.onmessage = (l) => {
118
- const S = JSON.parse(l.data);
119
- Ie(S);
120
- }, c.socket.onerror = (l) => {
121
- $("sse"), s(l);
122
- }, c.socket.onclose = (l) => {
123
- l.target === c.socket && (l.code === 1006 && (c.previouslyConnected ? X() : I({
113
+ e.sessionId && c.set("sessionId", e.sessionId), e.requestId && c.set("requestId", e.requestId), r.token && c.set("token", r.token);
114
+ const u = `${l}?${c.toString()}`;
115
+ a.socket = new WebSocket(u), a.socket.onopen = () => {
116
+ a.previouslyConnected = !0, ee(), x({ type: "ping" }), clearTimeout(a.socketConnectionTimeout), Ie(), n(!0);
117
+ }, a.socket.onmessage = (f) => {
118
+ const g = JSON.parse(f.data);
119
+ we(g);
120
+ }, a.socket.onerror = (f) => {
121
+ O("sse"), o(f);
122
+ }, a.socket.onclose = (f) => {
123
+ f.target === a.socket && (f.code === 1006 && (a.previouslyConnected ? ne() : h({
124
124
  errorText: "Unable to establish connection",
125
125
  done: !0,
126
126
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
127
- }), clearTimeout(c.socketConnectionTimeout)), c.socket = null, Z());
128
- }, c.previouslyConnected || (c.socketConnectionTimeout = setTimeout(() => {
129
- I({
127
+ }), clearTimeout(a.socketConnectionTimeout)), a.socket = null, j());
128
+ }, a.previouslyConnected || (a.socketConnectionTimeout = setTimeout(() => {
129
+ h({
130
130
  errorText: "Unable to establish connection",
131
131
  done: !0,
132
132
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
133
- }), s(new Error("Socket connection timed out"));
134
- }, pe));
133
+ }), o(new Error("Socket connection timed out"));
134
+ }, Se));
135
135
  });
136
136
  }
137
- function O(e) {
138
- c.socketDisconnected || !c.socket || c.socket.send(JSON.stringify({ ...e, eventId: e.eventId || B() }));
137
+ function x(e) {
138
+ a.socketDisconnected || !a.socket || a.socket.send(JSON.stringify({ ...e, eventId: e.eventId || X() }));
139
139
  }
140
- function Ie(e) {
140
+ function we(e) {
141
141
  switch (e.type) {
142
142
  case "pong": {
143
- c.socketDisconnected && j(), c.socketDisconnectedTimeout && clearTimeout(c.socketDisconnectedTimeout), c.socketDisconnectedTimeout = setTimeout(() => {
144
- X();
145
- }, Q + 1e3);
143
+ a.socketDisconnected && ee(), a.socketDisconnectedTimeout && clearTimeout(a.socketDisconnectedTimeout), a.socketDisconnectedTimeout = setTimeout(() => {
144
+ ne();
145
+ }, Z + 1e3);
146
146
  break;
147
147
  }
148
148
  case D.TYPING: {
149
- Y(!0);
149
+ Q(!0);
150
150
  break;
151
151
  }
152
152
  case D.TYPING_STOP: {
153
- Y(!1);
153
+ Q(!1);
154
154
  break;
155
155
  }
156
156
  case D.MESSAGE: {
157
- const { eventId: t, data: s } = e;
158
- t || I({
159
- ...s,
157
+ const { eventId: n, data: o } = e;
158
+ n || h({
159
+ ...o,
160
160
  done: !0,
161
161
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
162
162
  });
163
163
  break;
164
164
  }
165
165
  case D.END: {
166
- ee();
166
+ te();
167
167
  break;
168
168
  }
169
169
  }
170
170
  }
171
- function ee() {
172
- c.socket && c.socket.close(1e3), c.previouslyConnected = !1, Z(), c.socket = null, $("sse");
171
+ function te() {
172
+ a.socket && a.socket.close(1e3), a.previouslyConnected = !1, j(), a.socket = null, O("sse");
173
173
  }
174
174
  function Ce() {
175
- return c.socket !== null && c.socket.readyState === WebSocket.OPEN && !c.socketDisconnected;
175
+ return a.socket !== null && a.socket.readyState === WebSocket.OPEN && !a.socketDisconnected;
176
176
  }
177
- function ne(e = {}) {
177
+ function oe(e = {}) {
178
178
  return {
179
179
  credentials: void 0,
180
180
  authenticated: !1,
@@ -190,234 +190,236 @@ function ne(e = {}) {
190
190
  control: "agent"
191
191
  };
192
192
  }
193
- let o = ne();
194
- function Le(e) {
195
- o.callbacks = { ...o.callbacks, ...e };
193
+ let s = oe();
194
+ function ze(e) {
195
+ s.callbacks = { ...s.callbacks, ...e };
196
196
  }
197
- function Ge(e) {
198
- o.credentials = e, e.token && (o.authenticated = !0);
197
+ function Fe(e) {
198
+ s.credentials = e, e.token && (s.authenticated = !0);
199
199
  }
200
- function N() {
201
- return o.credentials;
200
+ function b() {
201
+ return s.credentials;
202
202
  }
203
- function he(e) {
204
- var t, s;
205
- e && e !== o.sessionId && (o.sessionId = e, (s = (t = o.callbacks).onSessionUpdate) == null || s.call(t, e));
203
+ function Ee(e) {
204
+ var n, o;
205
+ e && e !== s.sessionId && (s.sessionId = e, (o = (n = s.callbacks).onSessionUpdate) == null || o.call(n, e));
206
206
  }
207
- async function ze(e = {}) {
207
+ async function Ge(e = {}) {
208
208
  try {
209
- let t = null;
210
- o.authenticated ? t = o.configData : (t = await Ee(o.credentials), o.authenticated = !0, o.configData = t);
211
- let s = [], a = "agent";
209
+ let n = null;
210
+ s.authenticated ? n = s.configData : (n = await Te(s.credentials), s.authenticated = !0, s.configData = n);
211
+ let o = [], r = "agent";
212
212
  if (e.sessionId) {
213
- const f = await ve(e.sessionId);
214
- s = f.messages, a = f.control || "agent";
213
+ const d = await ve(e.sessionId);
214
+ o = d.messages, r = d.control || "agent";
215
215
  }
216
- const d = new URLSearchParams();
217
- return o.credentials.token || d.set("externalId", A()), o.sseUrl = `${ue(
218
- o.credentials.endpoint
219
- )}?${d.toString()}`, o.sessionId = e.sessionId, o.messages = s, o.control = a, a === "human" && we({ text: "", html: "" }).catch(() => {
216
+ const l = new URLSearchParams();
217
+ return s.credentials.token || l.set("externalId", P()), s.sseUrl = `${fe(
218
+ s.credentials.endpoint
219
+ )}?${l.toString()}`, s.sessionId = e.sessionId, s.messages = o, s.control = r, r === "human" && ye({ text: "", html: "" }).catch(() => {
220
220
  }), {
221
- sessionId: o.sessionId,
222
- messages: s,
223
- control: a,
224
- configData: t
221
+ sessionId: s.sessionId,
222
+ messages: o,
223
+ control: r,
224
+ configData: n
225
225
  };
226
- } catch (t) {
227
- throw te(), t;
226
+ } catch (n) {
227
+ throw se(), n;
228
228
  }
229
229
  }
230
- function Fe() {
231
- te();
230
+ function Je() {
231
+ se();
232
232
  }
233
- function te() {
234
- o.abortController && o.abortController.abort(), ee();
235
- const { callbacks: e, credentials: t } = o;
236
- o = ne(e), o.credentials = t;
233
+ function se() {
234
+ s.abortController && s.abortController.abort(), te();
235
+ const { callbacks: e, credentials: n } = s;
236
+ s = oe(e), s.credentials = n;
237
237
  }
238
- function A() {
238
+ function P() {
239
239
  var e;
240
- return (e = o.credentials) != null && e.externalId ? o.credentials.externalId : le();
240
+ return (e = s.credentials) != null && e.externalId ? s.credentials.externalId : ue();
241
241
  }
242
- function I(e) {
243
- var t, s;
244
- o.messages = [...o.messages, e], (s = (t = o.callbacks).onMessageAdd) == null || s.call(t, e);
242
+ function h(e) {
243
+ var n, o;
244
+ s.messages = [...s.messages, e], (o = (n = s.callbacks).onMessageAdd) == null || o.call(n, e);
245
245
  }
246
- function Y(e) {
247
- var t, s;
248
- (s = (t = o.callbacks).onTyping) == null || s.call(t, e);
246
+ function Q(e) {
247
+ var n, o;
248
+ (o = (n = s.callbacks).onTyping) == null || o.call(n, e);
249
249
  }
250
- function $(e) {
251
- var t, s;
252
- o.transport = e, (s = (t = o.callbacks).onTransportUpdate) == null || s.call(t, e);
250
+ function O(e) {
251
+ var n, o;
252
+ s.transport = e, (o = (n = s.callbacks).onTransportUpdate) == null || o.call(n, e);
253
253
  }
254
- function we({ text: e, html: t, context: s }) {
255
- return new Promise((a, d) => {
254
+ function ye({ text: e, html: n, context: o, attachments: r }) {
255
+ return new Promise((l, d) => {
256
256
  (async () => {
257
- var f, i, u;
257
+ var c, u, f;
258
258
  try {
259
- const l = !e && !t;
260
- if (!l) {
261
- const g = {
259
+ const g = !e && !n;
260
+ if (!g) {
261
+ const p = {
262
262
  role: y.USER,
263
263
  text: e,
264
- html: t,
265
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
264
+ html: n,
265
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
266
+ attachments: r
266
267
  };
267
- I(g), await de(200);
268
+ h(p), await ge(200);
268
269
  }
269
- if (o.transport === "socket" && Ce()) {
270
- O({
270
+ if (s.transport === "socket" && Ce()) {
271
+ x({
271
272
  type: "message",
272
273
  data: {
273
274
  text: e,
274
- html: t
275
+ html: n
275
276
  }
276
- }), a(o.sessionId);
277
+ }), l(s.sessionId);
277
278
  return;
278
279
  }
279
- if (o.control === "agent") {
280
- const g = {
280
+ if (s.control === "agent") {
281
+ const p = {
281
282
  role: y.ASSISTANT,
282
283
  text: "",
283
284
  loading: !0
284
285
  };
285
- I(g);
286
+ h(p);
286
287
  }
287
- const S = new URL(o.sseUrl);
288
- o.sessionId && S.searchParams.set("sessionId", o.sessionId), o.requestId && S.searchParams.set("requestId", o.requestId), o.lastStreamId = void 0, o.abortController = new AbortController();
289
- const h = {
288
+ const I = new URL(s.sseUrl);
289
+ s.sessionId && I.searchParams.set("sessionId", s.sessionId), s.requestId && I.searchParams.set("requestId", s.requestId), s.lastStreamId = void 0, s.abortController = new AbortController();
290
+ const C = {
290
291
  "Content-Type": "application/json"
291
292
  };
292
- (f = o.credentials) != null && f.token && (h.Authorization = `Bearer ${o.credentials.token}`), await ie(S.toString(), {
293
+ (c = s.credentials) != null && c.token && (C.Authorization = `Bearer ${s.credentials.token}`), await de(I.toString(), {
293
294
  method: "POST",
294
- headers: h,
295
- body: l ? void 0 : JSON.stringify({
295
+ headers: C,
296
+ body: g ? void 0 : JSON.stringify({
296
297
  message: e,
297
- html: t,
298
- context: s
298
+ html: n,
299
+ context: o,
300
+ attachments: r
299
301
  }),
300
- signal: o.abortController.signal,
302
+ signal: s.abortController.signal,
301
303
  openWhenHidden: !0,
302
- onopen: async (g) => {
303
- if (!g.ok)
304
+ onopen: async (p) => {
305
+ if (!p.ok)
304
306
  throw new Error("Failed to send message");
305
307
  },
306
- onmessage: (g) => {
307
- var v, T, M, x, q, L, G, z, F, W, J, _, K, V, H;
308
- const r = JSON.parse(g.data);
309
- if (g.event === "connected")
310
- o.sessionId = r.sessionId, o.requestId = r.requestId, r.control && (o.control = r.control, (T = (v = o.callbacks).onControlUpdate) == null || T.call(v, r.control));
311
- else if (g.event === "upgrade_to_websocket")
312
- ke({
313
- sessionId: o.sessionId,
314
- requestId: r.requestId
308
+ onmessage: (p) => {
309
+ var $, A, q, L, z, F, G, J, W, _, K, H, V, B, Y;
310
+ const i = JSON.parse(p.data);
311
+ if (p.event === "connected")
312
+ s.sessionId = i.sessionId, s.requestId = i.requestId, i.control && (s.control = i.control, (A = ($ = s.callbacks).onControlUpdate) == null || A.call($, i.control));
313
+ else if (p.event === "upgrade_to_websocket")
314
+ he({
315
+ sessionId: s.sessionId,
316
+ requestId: i.requestId
315
317
  });
316
- else if (g.event === "update")
317
- r.control && (o.control = r.control, (x = (M = o.callbacks).onControlUpdate) == null || x.call(M, r.control));
318
- else if (r.error) {
319
- const p = r.error && typeof r.error == "string" ? r.error : "Failed to connect to the system", k = o.messages.length - 1, m = {
320
- ...o.messages[k],
318
+ else if (p.event === "update")
319
+ i.control && (s.control = i.control, (L = (q = s.callbacks).onControlUpdate) == null || L.call(q, i.control));
320
+ else if (i.error) {
321
+ const m = i.error && typeof i.error == "string" ? i.error : "Failed to connect to the system", k = s.messages.length - 1, S = {
322
+ ...s.messages[k],
321
323
  loading: !1,
322
- errorText: p
324
+ errorText: m
323
325
  };
324
- o.messages = o.messages.map(
325
- (E, re) => re === k ? m : E
326
- ), (L = (q = o.callbacks).onMessageUpdate) == null || L.call(q, k, m), d(new Error(p));
327
- } else if (g.event === "done") {
328
- const p = o.messages.length - 1, w = {
329
- ...o.messages[p],
326
+ s.messages = s.messages.map(
327
+ (v, le) => le === k ? S : v
328
+ ), (F = (z = s.callbacks).onMessageUpdate) == null || F.call(z, k, S), d(new Error(m));
329
+ } else if (p.event === "done") {
330
+ const m = s.messages.length - 1, E = {
331
+ ...s.messages[m],
330
332
  loading: !1,
331
333
  done: !0
332
334
  };
333
- o.messages = o.messages.map(
334
- (m, E) => E === p ? w : m
335
- ), (z = (G = o.callbacks).onMessageUpdate) == null || z.call(G, p, w), a(o.sessionId);
336
- } else if (r.message !== void 0) {
337
- if (r.role === y.SUPERVISOR) {
338
- const m = {
335
+ s.messages = s.messages.map(
336
+ (S, v) => v === m ? E : S
337
+ ), (J = (G = s.callbacks).onMessageUpdate) == null || J.call(G, m, E), l(s.sessionId);
338
+ } else if (i.message !== void 0) {
339
+ if (i.role === y.SUPERVISOR) {
340
+ const S = {
339
341
  role: y.SUPERVISOR,
340
- text: r.message,
341
- sources: r.sources,
342
+ text: i.message,
343
+ sources: i.sources,
342
344
  done: !0
343
345
  };
344
- I(m), a(o.sessionId), o.sessionId = (F = r.sessionId) != null ? F : o.sessionId, o.requestId = (W = r.requestId) != null ? W : o.requestId;
346
+ h(S), l(s.sessionId), s.sessionId = (W = i.sessionId) != null ? W : s.sessionId, s.requestId = (_ = i.requestId) != null ? _ : s.requestId;
345
347
  return;
346
348
  }
347
- if (r.streamId !== void 0) {
348
- if (o.lastStreamId === void 0)
349
- o.lastStreamId = r.streamId;
350
- else if (r.streamId !== o.lastStreamId) {
351
- o.lastStreamId = r.streamId;
352
- const m = {
349
+ if (i.streamId !== void 0) {
350
+ if (s.lastStreamId === void 0)
351
+ s.lastStreamId = i.streamId;
352
+ else if (i.streamId !== s.lastStreamId) {
353
+ s.lastStreamId = i.streamId;
354
+ const S = {
353
355
  role: y.ASSISTANT,
354
356
  text: "",
355
357
  loading: !0
356
358
  };
357
- I(m);
359
+ h(S);
358
360
  }
359
361
  }
360
- const p = o.messages.length - 1, k = o.messages[p], w = {
362
+ const m = s.messages.length - 1, k = s.messages[m], E = {
361
363
  ...k,
362
364
  loading: !1,
363
- text: (k.text || "") + r.message,
364
- sources: r.sources,
365
- done: (J = r.done) != null ? J : k.done
365
+ text: (k.text || "") + i.message,
366
+ sources: i.sources,
367
+ done: (K = i.done) != null ? K : k.done
366
368
  };
367
- o.messages = o.messages.map(
368
- (m, E) => E === p ? w : m
369
- ), (K = (_ = o.callbacks).onMessageUpdate) == null || K.call(_, p, w), r.done, o.sessionId = (V = r.sessionId) != null ? V : o.sessionId, o.requestId = (H = r.requestId) != null ? H : o.requestId;
369
+ s.messages = s.messages.map(
370
+ (S, v) => v === m ? E : S
371
+ ), (V = (H = s.callbacks).onMessageUpdate) == null || V.call(H, m, E), i.done, s.sessionId = (B = i.sessionId) != null ? B : s.sessionId, s.requestId = (Y = i.requestId) != null ? Y : s.requestId;
370
372
  }
371
373
  },
372
- onerror: (g) => {
373
- throw g;
374
+ onerror: (p) => {
375
+ throw p;
374
376
  },
375
377
  openWhenHidden: !0
376
378
  });
377
- } catch (l) {
378
- const S = "Failed to connect to the system", h = o.messages.length - 1, g = o.messages[h], r = {
379
- ...g,
379
+ } catch (g) {
380
+ const I = "Failed to connect to the system", C = s.messages.length - 1, p = s.messages[C], i = {
381
+ ...p,
380
382
  loading: !1,
381
- errorText: g.done ? void 0 : l.message || S,
383
+ errorText: p.done ? void 0 : g.message || I,
382
384
  done: !0
383
385
  };
384
- o.messages = o.messages.map(
385
- (v, T) => T === h ? r : v
386
- ), (u = (i = o.callbacks).onMessageUpdate) == null || u.call(i, h, r), d(l);
386
+ s.messages = s.messages.map(
387
+ ($, A) => A === C ? i : $
388
+ ), (f = (u = s.callbacks).onMessageUpdate) == null || f.call(u, C, i), d(g);
387
389
  }
388
390
  })();
389
391
  });
390
392
  }
391
- const ye = "Something went wrong initializing the chat", be = "Chat SDK not initialized";
392
- async function Ee(e) {
393
- const { endpoint: t } = e, s = `${t}/config`, a = await fetch(s, {
393
+ const be = "Something went wrong initializing the chat", N = "Chat SDK not initialized";
394
+ async function Te(e) {
395
+ const { endpoint: n } = e, o = `${n}/config`, r = await fetch(o, {
394
396
  method: "GET",
395
397
  headers: {
396
398
  "Content-Type": "application/json"
397
399
  }
398
400
  });
399
- if (!a.ok) {
400
- const i = await a.json();
401
- throw new Error((i == null ? void 0 : i.error) || ye);
401
+ if (!r.ok) {
402
+ const c = await r.json();
403
+ throw new Error((c == null ? void 0 : c.error) || be);
402
404
  }
403
- return (await a.json()).data;
405
+ return (await r.json()).data;
404
406
  }
405
407
  async function We() {
406
408
  const e = new URLSearchParams({
407
- externalId: A()
408
- }), t = await oe(`/sessions?${e.toString()}`, "GET");
409
- if (!t.ok)
409
+ externalId: P()
410
+ }), n = await re(`/sessions?${e.toString()}`, "GET");
411
+ if (!n.ok)
410
412
  throw new Error("Unable to load history, please try again later");
411
- return t.json();
413
+ return n.json();
412
414
  }
413
415
  async function ve(e) {
414
- var i;
415
- const t = new URLSearchParams({
416
+ var c;
417
+ const n = new URLSearchParams({
416
418
  sessionId: e
417
- }), s = await oe(`/session?${t.toString()}`, "GET");
418
- if (!s.ok)
419
+ }), o = await re(`/session?${n.toString()}`, "GET");
420
+ if (!o.ok)
419
421
  throw new Error("Unable to load messages, please try again later");
420
- const a = await s.json(), d = a == null ? void 0 : a.control, f = ((i = a == null ? void 0 : a.history) != null ? i : []).map((u) => ({
422
+ const r = await o.json(), l = r == null ? void 0 : r.control, d = ((c = r == null ? void 0 : r.history) != null ? c : []).map((u) => ({
421
423
  id: u.id,
422
424
  text: u.text,
423
425
  role: u.youtubeVideo ? y.ASSISTANT : u.role,
@@ -426,22 +428,72 @@ async function ve(e) {
426
428
  channel: u.channel,
427
429
  done: !0
428
430
  }));
429
- return { control: d, messages: f };
431
+ return { control: l, messages: d };
430
432
  }
431
- async function oe(e, t = "GET", s = null) {
432
- const a = N(), { endpoint: d, token: f } = a || {};
433
- if (!d)
434
- throw new Error(be);
435
- const i = `${d}${e}`, u = {
433
+ function _e(e, n, o) {
434
+ const r = b(), { endpoint: l, token: d } = r || {};
435
+ if (!l) {
436
+ const g = new Error(N);
437
+ return o && o(g, null), null;
438
+ }
439
+ const c = new XMLHttpRequest(), u = new FormData();
440
+ u.append("file", e);
441
+ const f = `${l}/upload`;
442
+ return c.open("POST", f), d && c.setRequestHeader("Authorization", `Bearer ${d}`), n && c.upload.addEventListener("progress", (g) => {
443
+ if (g.lengthComputable) {
444
+ const I = g.loaded / g.total * 100;
445
+ n(I, g.loaded, g.total);
446
+ }
447
+ }), c.addEventListener("load", () => {
448
+ if (c.status >= 200 && c.status < 300)
449
+ try {
450
+ const g = JSON.parse(c.responseText);
451
+ o && o(null, g);
452
+ } catch (g) {
453
+ o && o(new Error("Failed to parse response"), null);
454
+ }
455
+ else
456
+ o && o(new Error(`Upload failed with status ${c.status}`), null);
457
+ }), c.addEventListener("error", () => {
458
+ o && o(new Error("Network error during upload"), null);
459
+ }), c.addEventListener("abort", () => {
460
+ o && o(new Error("Upload aborted"), null);
461
+ }), c.send(u), c;
462
+ }
463
+ async function Ke(e) {
464
+ const n = b(), { endpoint: o, token: r } = n || {};
465
+ if (!o)
466
+ throw new Error(N);
467
+ const l = `${o}/delete/${e}`, d = {};
468
+ r && (d.Authorization = `Bearer ${r}`);
469
+ const c = await fetch(l, {
470
+ method: "DELETE",
471
+ headers: d
472
+ });
473
+ if (!c.ok)
474
+ throw new Error(`Delete failed with status ${c.status}`);
475
+ return { success: !0 };
476
+ }
477
+ function He(e) {
478
+ const n = b(), { endpoint: o } = n || {};
479
+ if (!o)
480
+ throw new Error(N);
481
+ return `${o}/upload/${e}`;
482
+ }
483
+ async function re(e, n = "GET", o = null) {
484
+ const r = b(), { endpoint: l, token: d } = r || {};
485
+ if (!l)
486
+ throw new Error(N);
487
+ const c = `${l}${e}`, u = {
436
488
  "Content-Type": "application/json"
437
489
  };
438
- return f && (u.Authorization = `Bearer ${f}`), fetch(i, {
490
+ return d && (u.Authorization = `Bearer ${d}`), fetch(c, {
439
491
  headers: u,
440
- method: t,
441
- body: s ? JSON.stringify(s) : null
492
+ method: n,
493
+ body: o ? JSON.stringify(o) : null
442
494
  });
443
495
  }
444
- function se(e = {}) {
496
+ function ae(e = {}) {
445
497
  return {
446
498
  sessionId: void 0,
447
499
  socket: null,
@@ -459,52 +511,52 @@ function se(e = {}) {
459
511
  pendingRemoteIceCandidates: []
460
512
  };
461
513
  }
462
- let n = se();
463
- const Te = {
514
+ let t = ae();
515
+ const $e = {
464
516
  iceServers: [{ urls: "stun:stun.l.google.com:19302" }, { urls: "stun:stun1.l.google.com:19302" }]
465
517
  };
466
- function Je(e) {
467
- n.callbacks = { ...n.callbacks, ...e };
518
+ function Ve(e) {
519
+ t.callbacks = { ...t.callbacks, ...e };
468
520
  }
469
521
  function ce() {
470
- n.peerConnection && (n.peerConnection.close(), n.peerConnection = null), n.localStream && (n.localStream.getTracks().forEach((t) => t.stop()), n.localStream = null), n.remoteStream && (n.remoteStream = null), n.remoteAudio && (n.remoteAudio.srcObject = null, n.remoteAudio.parentNode && n.remoteAudio.parentNode.removeChild(n.remoteAudio), n.remoteAudio = null), n.socket && (n.socket.close(), n.socket = null), R();
471
- const e = n.callbacks;
472
- n = se(e);
522
+ t.peerConnection && (t.peerConnection.close(), t.peerConnection = null), t.localStream && (t.localStream.getTracks().forEach((n) => n.stop()), t.localStream = null), t.remoteStream && (t.remoteStream = null), t.remoteAudio && (t.remoteAudio.srcObject = null, t.remoteAudio.parentNode && t.remoteAudio.parentNode.removeChild(t.remoteAudio), t.remoteAudio = null), t.socket && (t.socket.close(), t.socket = null), U();
523
+ const e = t.callbacks;
524
+ t = ae(e);
473
525
  }
474
- function C(e) {
475
- var t, s;
476
- n.callStatus = e, (s = (t = n.callbacks).onCallStatus) == null || s.call(t, e);
526
+ function w(e) {
527
+ var n, o;
528
+ t.callStatus = e, (o = (n = t.callbacks).onCallStatus) == null || o.call(n, e);
477
529
  }
478
- function P(e) {
479
- var t, s;
480
- (s = (t = n.callbacks).onCallError) == null || s.call(t, e);
530
+ function R(e) {
531
+ var n, o;
532
+ (o = (n = t.callbacks).onCallError) == null || o.call(n, e);
481
533
  }
482
- function R() {
483
- n.pingInterval && (clearInterval(n.pingInterval), n.pingInterval = null);
534
+ function U() {
535
+ t.pingInterval && (clearInterval(t.pingInterval), t.pingInterval = null);
484
536
  }
485
- function De() {
486
- R(), n.pingInterval = setInterval(() => {
487
- if (n.socket && n.socket.readyState === WebSocket.OPEN) {
488
- n.pingCount++;
537
+ function Ae() {
538
+ U(), t.pingInterval = setInterval(() => {
539
+ if (t.socket && t.socket.readyState === WebSocket.OPEN) {
540
+ t.pingCount++;
489
541
  const e = {
490
542
  type: "ping",
491
543
  timestamp: Date.now(),
492
- count: n.pingCount
544
+ count: t.pingCount
493
545
  };
494
- b(e);
546
+ T(e);
495
547
  } else
496
- R();
548
+ U();
497
549
  }, 1e4);
498
550
  }
499
- function Pe() {
500
- n.lastPongTime = Date.now();
551
+ function De() {
552
+ t.lastPongTime = Date.now();
501
553
  }
502
- function b(e) {
503
- n.socket && n.socket.readyState === WebSocket.OPEN && n.socket.send(JSON.stringify(e));
554
+ function T(e) {
555
+ t.socket && t.socket.readyState === WebSocket.OPEN && t.socket.send(JSON.stringify(e));
504
556
  }
505
557
  async function Re() {
506
558
  try {
507
- n.localStream = await navigator.mediaDevices.getUserMedia({
559
+ t.localStream = await navigator.mediaDevices.getUserMedia({
508
560
  audio: !0,
509
561
  video: !1
510
562
  });
@@ -512,233 +564,236 @@ async function Re() {
512
564
  throw e;
513
565
  }
514
566
  }
515
- function Ae() {
516
- n.peerConnection = new RTCPeerConnection(Te), n.peerConnection.onicecandidate = (e) => {
567
+ function Ue() {
568
+ t.peerConnection = new RTCPeerConnection($e), t.peerConnection.onicecandidate = (e) => {
517
569
  if (e.candidate) {
518
- const t = JSON.stringify(e.candidate);
519
- n.peerConnection && n.peerConnection.remoteDescription ? b({
570
+ const n = JSON.stringify(e.candidate);
571
+ t.peerConnection && t.peerConnection.remoteDescription ? T({
520
572
  type: "ice",
521
573
  data: {
522
- candidate: t
574
+ candidate: n
523
575
  }
524
- }) : n.localIceCandidates.push(t);
576
+ }) : t.localIceCandidates.push(n);
525
577
  }
526
- }, n.peerConnection.ontrack = (e) => {
527
- n.remoteStream = e.streams[0], n.remoteAudio || (n.remoteAudio = document.createElement("audio"), n.remoteAudio.autoplay = !0, n.remoteAudio.controls = !1, document.body.appendChild(n.remoteAudio)), n.remoteAudio.srcObject = n.remoteStream, n.remoteAudio.play().then(() => {
528
- }).catch((t) => {
578
+ }, t.peerConnection.ontrack = (e) => {
579
+ t.remoteStream = e.streams[0], t.remoteAudio || (t.remoteAudio = document.createElement("audio"), t.remoteAudio.autoplay = !0, t.remoteAudio.controls = !1, document.body.appendChild(t.remoteAudio)), t.remoteAudio.srcObject = t.remoteStream, t.remoteAudio.play().then(() => {
580
+ }).catch((n) => {
529
581
  });
530
- }, n.peerConnection.onconnectionstatechange = () => {
531
- const e = n.peerConnection.connectionState;
532
- e === "connected" ? C("connected") : (e === "disconnected" || e === "closed") && (C("disconnected"), ae());
533
- }, n.peerConnection.oniceconnectionstatechange = () => {
582
+ }, t.peerConnection.onconnectionstatechange = () => {
583
+ const e = t.peerConnection.connectionState;
584
+ e === "connected" ? w("connected") : (e === "disconnected" || e === "closed") && (w("disconnected"), ie());
585
+ }, t.peerConnection.oniceconnectionstatechange = () => {
534
586
  };
535
587
  }
536
- function $e(e) {
537
- return new Promise((t, s) => {
538
- if (n.socket && (n.socket.readyState === WebSocket.CONNECTING || n.socket.readyState === WebSocket.OPEN)) {
539
- t(n.socket.readyState === WebSocket.OPEN);
588
+ function Pe(e) {
589
+ return new Promise((n, o) => {
590
+ if (t.socket && (t.socket.readyState === WebSocket.CONNECTING || t.socket.readyState === WebSocket.OPEN)) {
591
+ n(t.socket.readyState === WebSocket.OPEN);
540
592
  return;
541
593
  }
542
- const a = N();
543
- if (!a || !a.endpoint) {
544
- s(new Error("SDK not initialized. Please initialize SDK first."));
594
+ const r = b();
595
+ if (!r || !r.endpoint) {
596
+ o(new Error("SDK not initialized. Please initialize SDK first."));
545
597
  return;
546
598
  }
547
- const d = fe(a.endpoint);
548
- if (!d) {
549
- s(
599
+ const l = me(r.endpoint);
600
+ if (!l) {
601
+ o(
550
602
  new Error(
551
603
  "Invalid endpoint while initializing SDK. Please check the endpoint and try again."
552
604
  )
553
605
  );
554
606
  return;
555
607
  }
556
- const f = A(), i = new URLSearchParams({
557
- externalId: f
608
+ const d = P(), c = new URLSearchParams({
609
+ externalId: d
558
610
  });
559
- e.sessionId && i.set("sessionId", e.sessionId), a.token && i.set("token", a.token);
560
- const u = `${d}?${i.toString()}`;
561
- n.socket = new WebSocket(u), n.socket.onopen = (l) => {
562
- De(), t(!0);
563
- }, n.socket.onmessage = (l) => {
564
- const S = JSON.parse(l.data);
565
- Ue(S);
566
- }, n.socket.onerror = (l) => {
567
- C("error"), P(l.message || "Unable to connect voice"), s(l);
568
- }, n.socket.onclose = (l) => {
569
- R();
611
+ e.sessionId && c.set("sessionId", e.sessionId), r.token && c.set("token", r.token);
612
+ const u = `${l}?${c.toString()}`;
613
+ t.socket = new WebSocket(u), t.socket.onopen = (f) => {
614
+ Ae(), n(!0);
615
+ }, t.socket.onmessage = (f) => {
616
+ const g = JSON.parse(f.data);
617
+ Oe(g);
618
+ }, t.socket.onerror = (f) => {
619
+ w("error"), R(f.message || "Unable to connect voice"), o(f);
620
+ }, t.socket.onclose = (f) => {
621
+ U();
570
622
  };
571
623
  });
572
624
  }
573
- function Ue(e) {
625
+ function Oe(e) {
574
626
  switch (e.type) {
575
627
  case "pong":
576
- Pe();
628
+ De();
577
629
  break;
578
630
  case "answer":
579
- Ne(e.data);
631
+ Me(e.data);
580
632
  break;
581
633
  case "connected":
582
- Oe(e.data);
634
+ Ne(e.data);
583
635
  break;
584
636
  case "ice":
585
- Me(e.data);
637
+ xe(e.data);
586
638
  break;
587
639
  case "renegotiationOffer":
588
- xe(e.data);
640
+ qe(e.data);
589
641
  break;
590
642
  case "end":
591
- ae();
643
+ ie();
592
644
  break;
593
645
  case "error":
594
- C("error"), P(e.error || "Unable to connect voice");
646
+ w("error"), R(e.error || "Unable to connect voice");
595
647
  break;
596
648
  default:
597
649
  break;
598
650
  }
599
651
  }
600
- function Oe(e) {
601
- n.sessionId = e.sessionId, he(e.sessionId);
652
+ function Ne(e) {
653
+ t.sessionId = e.sessionId, Ee(e.sessionId);
602
654
  }
603
- async function Ne(e) {
655
+ async function Me(e) {
604
656
  try {
605
- if (n.peerConnection) {
606
- const t = new RTCSessionDescription({
657
+ if (t.peerConnection) {
658
+ const n = new RTCSessionDescription({
607
659
  type: "answer",
608
660
  sdp: e.sdp
609
661
  });
610
- await n.peerConnection.setRemoteDescription(t);
611
- for (const s of n.localIceCandidates)
612
- b({
662
+ await t.peerConnection.setRemoteDescription(n);
663
+ for (const o of t.localIceCandidates)
664
+ T({
613
665
  type: "ice",
614
666
  data: {
615
- candidate: s
667
+ candidate: o
616
668
  }
617
669
  });
618
- n.localIceCandidates = [];
619
- for (const s of n.pendingRemoteIceCandidates)
670
+ t.localIceCandidates = [];
671
+ for (const o of t.pendingRemoteIceCandidates)
620
672
  try {
621
- const a = new RTCIceCandidate(JSON.parse(s));
622
- await n.peerConnection.addIceCandidate(a);
623
- } catch (a) {
673
+ const r = new RTCIceCandidate(JSON.parse(o));
674
+ await t.peerConnection.addIceCandidate(r);
675
+ } catch (r) {
624
676
  }
625
- n.pendingRemoteIceCandidates = [];
677
+ t.pendingRemoteIceCandidates = [];
626
678
  }
627
- } catch (t) {
679
+ } catch (n) {
628
680
  }
629
681
  }
630
- async function Me(e) {
682
+ async function xe(e) {
631
683
  try {
632
- if (n.peerConnection) {
633
- if (!n.peerConnection.remoteDescription) {
634
- n.pendingRemoteIceCandidates.push(e.candidate);
684
+ if (t.peerConnection) {
685
+ if (!t.peerConnection.remoteDescription) {
686
+ t.pendingRemoteIceCandidates.push(e.candidate);
635
687
  return;
636
688
  }
637
- const t = new RTCIceCandidate(JSON.parse(e.candidate));
638
- await n.peerConnection.addIceCandidate(t);
689
+ const n = new RTCIceCandidate(JSON.parse(e.candidate));
690
+ await t.peerConnection.addIceCandidate(n);
639
691
  }
640
- } catch (t) {
692
+ } catch (n) {
641
693
  }
642
694
  }
643
- async function xe(e) {
695
+ async function qe(e) {
644
696
  try {
645
- if (n.peerConnection) {
646
- const t = new RTCSessionDescription({
697
+ if (t.peerConnection) {
698
+ const n = new RTCSessionDescription({
647
699
  type: "offer",
648
700
  sdp: e.sdp
649
701
  });
650
- await n.peerConnection.setRemoteDescription(t);
651
- const s = await n.peerConnection.createAnswer();
652
- await n.peerConnection.setLocalDescription(s), b({
702
+ await t.peerConnection.setRemoteDescription(n);
703
+ const o = await t.peerConnection.createAnswer();
704
+ await t.peerConnection.setLocalDescription(o), T({
653
705
  type: "renegotiationAnswer",
654
706
  data: {
655
- sdp: s.sdp
707
+ sdp: o.sdp
656
708
  }
657
709
  });
658
710
  }
659
- } catch (t) {
711
+ } catch (n) {
660
712
  }
661
713
  }
662
- async function _e(e = {}) {
714
+ async function Be(e = {}) {
663
715
  try {
664
- if (n.callStatus === "connecting" || n.callStatus === "connected")
716
+ if (t.callStatus === "connecting" || t.callStatus === "connected")
665
717
  return;
666
- C("connecting"), P(null), n.sessionId = e.sessionId, await Re(), Ae(), n.localStream.getTracks().forEach((s) => {
667
- n.peerConnection.addTrack(s, n.localStream);
668
- }), await $e(e);
669
- const t = await n.peerConnection.createOffer();
670
- await n.peerConnection.setLocalDescription(t), b({
718
+ w("connecting"), R(null), t.sessionId = e.sessionId, await Re(), Ue(), t.localStream.getTracks().forEach((o) => {
719
+ t.peerConnection.addTrack(o, t.localStream);
720
+ }), await Pe(e);
721
+ const n = await t.peerConnection.createOffer();
722
+ await t.peerConnection.setLocalDescription(n), T({
671
723
  type: "offer",
672
724
  data: {
673
- sdp: t.sdp
725
+ sdp: n.sdp
674
726
  }
675
727
  });
676
- } catch (t) {
677
- C("error"), P(t.message || "Unable to connect voice"), ce();
728
+ } catch (n) {
729
+ w("error"), R(n.message || "Unable to connect voice"), ce();
678
730
  }
679
731
  }
680
- function ae() {
681
- b({
732
+ function ie() {
733
+ T({
682
734
  type: "end"
683
- }), n.socket && (n.socket.close(), n.socket = null), C("disconnected"), n.peerConnection && (n.peerConnection.close(), n.peerConnection = null), n.localStream && (n.localStream.getTracks().forEach((e) => e.stop()), n.localStream = null), ce();
735
+ }), t.socket && (t.socket.close(), t.socket = null), w("disconnected"), t.peerConnection && (t.peerConnection.close(), t.peerConnection = null), t.localStream && (t.localStream.getTracks().forEach((e) => e.stop()), t.localStream = null), ce();
684
736
  }
685
- function Ke() {
686
- if (n.localStream) {
687
- const e = n.localStream.getAudioTracks()[0];
737
+ function Ye() {
738
+ if (t.localStream) {
739
+ const e = t.localStream.getAudioTracks()[0];
688
740
  if (e)
689
- return e.enabled = !e.enabled, n.isMuted = !e.enabled, n.isMuted;
741
+ return e.enabled = !e.enabled, t.isMuted = !e.enabled, t.isMuted;
690
742
  }
691
743
  return !1;
692
744
  }
693
- function Ve() {
694
- return n.localStream;
745
+ function Qe() {
746
+ return t.localStream;
695
747
  }
696
- function He() {
697
- return new Promise((e, t) => {
698
- if (!n.peerConnection) {
699
- t(new Error("no peer connection"));
748
+ function Xe() {
749
+ return new Promise((e, n) => {
750
+ if (!t.peerConnection) {
751
+ n(new Error("no peer connection"));
700
752
  return;
701
753
  }
702
- n.peerConnection.getStats().then((s) => {
703
- s.forEach((a) => {
704
- a.type == "inbound-rtp" && e(a.totalAudioEnergy);
705
- }), t(new Error("no inbound-rtp stats found"));
706
- }).catch((s) => {
707
- t(s);
754
+ t.peerConnection.getStats().then((o) => {
755
+ o.forEach((r) => {
756
+ r.type == "inbound-rtp" && e(r.totalAudioEnergy);
757
+ }), n(new Error("no inbound-rtp stats found"));
758
+ }).catch((o) => {
759
+ n(o);
708
760
  });
709
761
  });
710
762
  }
711
- function Ye() {
712
- return new Promise((e, t) => {
713
- if (!n.peerConnection) {
714
- t(new Error("no peer connection"));
763
+ function Ze() {
764
+ return new Promise((e, n) => {
765
+ if (!t.peerConnection) {
766
+ n(new Error("no peer connection"));
715
767
  return;
716
768
  }
717
- n.peerConnection.getStats().then((s) => {
718
- s.forEach((a) => {
719
- a.type == "outbound-rtp" && e(a.totalAudioEnergy);
720
- }), t(new Error("no outbound-rtp stats found"));
721
- }).catch((s) => {
722
- t(s);
769
+ t.peerConnection.getStats().then((o) => {
770
+ o.forEach((r) => {
771
+ r.type == "outbound-rtp" && e(r.totalAudioEnergy);
772
+ }), n(new Error("no outbound-rtp stats found"));
773
+ }).catch((o) => {
774
+ n(o);
723
775
  });
724
776
  });
725
777
  }
726
778
  export {
727
779
  y as MESSAGE_ROLES,
728
- Ee as authenticate,
729
- Fe as disconnect,
730
- ae as disconnectCall,
780
+ Te as authenticate,
781
+ Ke as deleteAttachment,
782
+ Je as disconnect,
783
+ ie as disconnectCall,
784
+ He as getAttachment,
731
785
  We as getHistory,
732
- He as getInboundAudioEnergy,
733
- Ve as getLocalStream,
734
- Ye as getOutboundAudioEnergy,
786
+ Xe as getInboundAudioEnergy,
787
+ Qe as getLocalStream,
788
+ Ze as getOutboundAudioEnergy,
735
789
  ve as getSession,
736
- Ge as initialize,
737
- we as sendMessage,
738
- Je as setCallCallbacks,
739
- Le as setCallbacks,
740
- _e as startCall,
741
- ze as startChat,
742
- Ke as toggleMute
790
+ Fe as initialize,
791
+ ye as sendMessage,
792
+ Ve as setCallCallbacks,
793
+ ze as setCallbacks,
794
+ Be as startCall,
795
+ Ge as startChat,
796
+ Ye as toggleMute,
797
+ _e as uploadAttachment
743
798
  };
744
799
  //# sourceMappingURL=origon-chat-sdk.js.map