@d-id/client-sdk 1.1.0-beta.5 → 1.1.0-beta.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.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var ge = Object.defineProperty;
2
2
  var he = (e, t, n) => t in e ? ge(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var U = (e, t, n) => (he(e, typeof t != "symbol" ? t + "" : t, n), n);
4
- class Y extends Error {
3
+ var H = (e, t, n) => (he(e, typeof t != "symbol" ? t + "" : t, n), n);
4
+ class Q extends Error {
5
5
  constructor({
6
6
  kind: n,
7
7
  description: a,
@@ -11,13 +11,13 @@ class Y extends Error {
11
11
  kind: n,
12
12
  description: a
13
13
  }));
14
- U(this, "kind");
15
- U(this, "description");
16
- U(this, "error");
14
+ H(this, "kind");
15
+ H(this, "description");
16
+ H(this, "error");
17
17
  this.kind = n, this.description = a, this.error = o;
18
18
  }
19
19
  }
20
- class we extends Y {
20
+ class we extends Q {
21
21
  constructor(t, n) {
22
22
  super({
23
23
  kind: "ChatCreationFailed",
@@ -25,7 +25,7 @@ class we extends Y {
25
25
  });
26
26
  }
27
27
  }
28
- class pe extends Y {
28
+ class pe extends Q {
29
29
  constructor(t) {
30
30
  super({
31
31
  kind: "ChatModeDowngraded",
@@ -33,17 +33,17 @@ class pe extends Y {
33
33
  });
34
34
  }
35
35
  }
36
- class x extends Y {
36
+ class F extends Q {
37
37
  constructor(n, a) {
38
38
  super({
39
39
  kind: "ValidationError",
40
40
  description: n
41
41
  });
42
- U(this, "key");
42
+ H(this, "key");
43
43
  this.key = a;
44
44
  }
45
45
  }
46
- class ye extends Y {
46
+ class ye extends Q {
47
47
  constructor(t) {
48
48
  super({
49
49
  kind: "WSError",
@@ -51,7 +51,7 @@ class ye extends Y {
51
51
  });
52
52
  }
53
53
  }
54
- var ve = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ve || {}), ke = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(ke || {}), De = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(De || {}), Ce = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ce || {}), b = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(b || {}), J = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(J || {}), Re = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Re || {}), Ee = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Ee || {}), Se = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(Se || {}), ie = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(ie || {});
54
+ var ve = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ve || {}), ke = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(ke || {}), Ce = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ce || {}), De = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(De || {}), j = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e))(j || {}), J = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(J || {}), Re = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Re || {}), Ee = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Ee || {}), Se = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(Se || {}), ie = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e))(ie || {});
55
55
  const Me = (e) => {
56
56
  switch (e) {
57
57
  case "clip":
@@ -62,15 +62,15 @@ const Me = (e) => {
62
62
  throw new Error(`Unknown video type: ${e}`);
63
63
  }
64
64
  };
65
- var v = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(v || {}), W = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(W || {}), H = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(H || {});
65
+ var v = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(v || {}), W = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(W || {}), K = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(K || {});
66
66
  const te = {
67
67
  "stream/started": "START",
68
68
  "stream/done": "STOP"
69
69
  /* Stop */
70
70
  };
71
- var X = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(X || {}), M = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(M || {}), F = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(F || {}), _e = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(_e || {}), Ie = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Ie || {});
72
- const Te = 45 * 1e3, je = "X-Playground-Chat", K = "https://api.d-id.com", be = "wss://notifications.d-id.com", Pe = "79f81a83a67430be2bc0fd61042b8faa", se = (e) => new Promise((t) => setTimeout(t, e)), q = () => Math.random().toString(16).slice(2);
73
- function Be(e, t) {
71
+ var Y = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(Y || {}), I = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(I || {}), N = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(N || {}), _e = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(_e || {}), Ie = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Ie || {});
72
+ const Te = 45 * 1e3, je = "X-Playground-Chat", q = "https://api.d-id.com", be = "wss://notifications.d-id.com", Pe = "79f81a83a67430be2bc0fd61042b8faa", se = (e) => new Promise((t) => setTimeout(t, e)), X = () => Math.random().toString(16).slice(2), Be = (e) => [j.TextOnly, j.Playground, j.Maintenance].includes(e);
73
+ function $e(e, t) {
74
74
  let n;
75
75
  return {
76
76
  promise: new Promise((o, s) => {
@@ -79,7 +79,7 @@ function Be(e, t) {
79
79
  clear: () => clearTimeout(n)
80
80
  };
81
81
  }
82
- async function V(e, t) {
82
+ async function Z(e, t) {
83
83
  const n = {
84
84
  limit: (t == null ? void 0 : t.limit) ?? 3,
85
85
  delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
@@ -97,7 +97,7 @@ async function V(e, t) {
97
97
  const {
98
98
  promise: s,
99
99
  clear: r
100
- } = Be(n.timeout, n.timeoutErrorMessage), i = e().finally(r);
100
+ } = $e(n.timeout, n.timeoutErrorMessage), i = e().finally(r);
101
101
  return await Promise.race([i, s]);
102
102
  } catch (s) {
103
103
  if (a = s, !n.shouldRetryFn(s) || o >= n.limit)
@@ -110,28 +110,28 @@ function oe() {
110
110
  let e = window.localStorage.getItem("did_external_key_id");
111
111
  return e || (e = Math.random().toString(16).slice(2), window.localStorage.setItem("did_external_key_id", e)), e;
112
112
  }
113
- let $e = q();
113
+ let Le = X();
114
114
  function ce(e) {
115
115
  if (e.type === "bearer")
116
116
  return `Bearer ${e.token}`;
117
117
  if (e.type === "basic")
118
118
  return `Basic ${btoa(`${e.username}:${e.password}`)}`;
119
119
  if (e.type === "key")
120
- return `Client-Key ${e.clientKey}.${oe()}_${$e}`;
120
+ return `Client-Key ${e.clientKey}.${oe()}_${Le}`;
121
121
  throw new Error(`Unknown auth type: ${e}`);
122
122
  }
123
- const Le = (e) => V(e, {
123
+ const Ae = (e) => Z(e, {
124
124
  limit: 3,
125
125
  delayMs: 1e3,
126
126
  timeout: 0,
127
127
  shouldRetryFn: (t) => t.status === 429
128
128
  });
129
- function G(e, t = K, n) {
129
+ function O(e, t = q, n) {
130
130
  const a = async (o, s) => {
131
131
  const {
132
132
  skipErrorHandler: r,
133
133
  ...i
134
- } = s || {}, c = await Le(() => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
134
+ } = s || {}, c = await Ae(() => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
135
135
  ...i,
136
136
  headers: {
137
137
  ...i.headers,
@@ -141,12 +141,12 @@ function G(e, t = K, n) {
141
141
  }));
142
142
  if (!c.ok) {
143
143
  let l = await c.text().catch(() => `Failed to fetch with status ${c.status}`);
144
- const f = new Error(l);
145
- throw n && !r && n(f, {
144
+ const u = new Error(l);
145
+ throw n && !r && n(u, {
146
146
  url: o,
147
147
  options: i,
148
148
  headers: c.headers
149
- }), f;
149
+ }), u;
150
150
  }
151
151
  return c.json();
152
152
  };
@@ -180,8 +180,8 @@ function G(e, t = K, n) {
180
180
  }
181
181
  };
182
182
  }
183
- function de(e, t = K, n) {
184
- const a = G(e, `${t}/agents`, n);
183
+ function de(e, t = q, n) {
184
+ const a = O(e, `${t}/agents`, n);
185
185
  return {
186
186
  create(o, s) {
187
187
  return a.post("/", o, s);
@@ -219,7 +219,7 @@ function de(e, t = K, n) {
219
219
  };
220
220
  }
221
221
  const le = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type;
222
- function Ae(e) {
222
+ function ze(e) {
223
223
  var o, s, r, i;
224
224
  const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", n = () => {
225
225
  const c = navigator.platform;
@@ -237,9 +237,9 @@ function Ae(e) {
237
237
  }
238
238
  };
239
239
  }
240
- const ze = (e) => e.reduce((t, n) => t + n, 0), Ne = (e) => ze(e) / e.length;
240
+ const xe = (e) => e.reduce((t, n) => t + n, 0), Ne = (e) => xe(e) / e.length;
241
241
  function Fe(e, t, n) {
242
- var c, l, f;
242
+ var c, l, u;
243
243
  const {
244
244
  event: a,
245
245
  ...o
@@ -261,14 +261,14 @@ function Fe(e, t, n) {
261
261
  language: r
262
262
  }
263
263
  },
264
- stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (f = t == null ? void 0 : t.presenter) == null ? void 0 : f.stitch : void 0,
264
+ stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (u = t == null ? void 0 : t.presenter) == null ? void 0 : u.stitch : void 0,
265
265
  ...n
266
266
  };
267
267
  }
268
- let Q = {};
269
- const xe = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
270
- function Je(e) {
271
- var s, r, i, c, l, f;
268
+ let V = {};
269
+ const Je = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
270
+ function We(e) {
271
+ var s, r, i, c, l, u;
272
272
  const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", n = e.agent.presenter, a = (s = e.agent.llm) == null ? void 0 : s.prompt_customization, o = {
273
273
  token: e.token || "testKey",
274
274
  distinct_id: e.distinctId || oe(),
@@ -283,7 +283,7 @@ function Je(e) {
283
283
  },
284
284
  temperature: (c = e.agent.llm) == null ? void 0 : c.temperature,
285
285
  knowledgeSource: a == null ? void 0 : a.knowledge_source,
286
- starterQuestionsCount: (f = (l = e.agent.knowledge) == null ? void 0 : l.starter_message) == null ? void 0 : f.length,
286
+ starterQuestionsCount: (u = (l = e.agent.knowledge) == null ? void 0 : l.starter_message) == null ? void 0 : u.length,
287
287
  topicsToAvoid: a == null ? void 0 : a.topics_to_avoid,
288
288
  maxResponseLength: a == null ? void 0 : a.max_response_length
289
289
  };
@@ -292,31 +292,31 @@ function Je(e) {
292
292
  additionalProperties: {},
293
293
  isEnabled: e.isEnabled ?? !0,
294
294
  getRandom: () => Math.random().toString(16).slice(2),
295
- enrich(m) {
296
- const D = {};
297
- if (m && typeof m != "object")
295
+ enrich(f) {
296
+ const k = {};
297
+ if (f && typeof f != "object")
298
298
  throw new Error("properties must be a flat json object");
299
- for (let w in m)
300
- (typeof m[w] == "string" || typeof m[w] == "number") && (D[w] = m[w]);
299
+ for (let y in f)
300
+ (typeof f[y] == "string" || typeof f[y] == "number") && (k[y] = f[y]);
301
301
  this.additionalProperties = {
302
302
  ...this.additionalProperties,
303
- ...D
303
+ ...k
304
304
  };
305
305
  },
306
- async track(m, D) {
306
+ async track(f, k) {
307
307
  if (!this.isEnabled)
308
308
  return Promise.resolve();
309
309
  const {
310
- audioPath: w,
310
+ audioPath: y,
311
311
  ...C
312
- } = D || {}, R = {
312
+ } = k || {}, S = {
313
313
  method: "POST",
314
314
  headers: {
315
315
  "Content-Type": "application/x-www-form-urlencoded"
316
316
  },
317
317
  body: new URLSearchParams({
318
318
  data: JSON.stringify([{
319
- event: m,
319
+ event: f,
320
320
  properties: {
321
321
  ...this.additionalProperties,
322
322
  ...C,
@@ -333,32 +333,32 @@ function Je(e) {
333
333
  })
334
334
  };
335
335
  try {
336
- return await fetch(xe, R).then((S) => S.json());
337
- } catch (S) {
338
- return console.error(S);
336
+ return await fetch(Je, S).then((B) => B.json());
337
+ } catch (B) {
338
+ return console.error(B);
339
339
  }
340
340
  },
341
- linkTrack(m, D, w, C) {
342
- Q[m] || (Q[m] = {
341
+ linkTrack(f, k, y, C) {
342
+ V[f] || (V[f] = {
343
343
  events: {},
344
344
  resolvedDependencies: []
345
- }), C.includes(w) || C.push(w);
346
- const R = Q[m];
347
- if (R.events[w] = {
348
- props: D
349
- }, R.resolvedDependencies.push(w), C.every((P) => R.resolvedDependencies.includes(P))) {
350
- const P = C.reduce((d, g) => R.events[g] ? {
345
+ }), C.includes(y) || C.push(y);
346
+ const S = V[f];
347
+ if (S.events[y] = {
348
+ props: k
349
+ }, S.resolvedDependencies.push(y), C.every((M) => S.resolvedDependencies.includes(M))) {
350
+ const M = C.reduce((d, w) => S.events[w] ? {
351
351
  ...d,
352
- ...R.events[g].props
352
+ ...S.events[w].props
353
353
  } : d, {});
354
- this.track(m, P), R.resolvedDependencies = R.resolvedDependencies.filter((d) => !C.includes(d)), C.forEach((d) => {
355
- delete R.events[d];
354
+ this.track(f, M), S.resolvedDependencies = S.resolvedDependencies.filter((d) => !C.includes(d)), C.forEach((d) => {
355
+ delete S.events[d];
356
356
  });
357
357
  }
358
358
  }
359
359
  };
360
360
  }
361
- function We() {
361
+ function Ue() {
362
362
  let e = 0;
363
363
  return {
364
364
  reset: () => e = 0,
@@ -366,9 +366,9 @@ function We() {
366
366
  get: (t = !1) => t ? Date.now() - e : e
367
367
  };
368
368
  }
369
- const N = We();
369
+ const x = Ue();
370
370
  function ue(e) {
371
- return e === b.Playground ? {
371
+ return e === j.Playground ? {
372
372
  headers: {
373
373
  [je]: "true"
374
374
  }
@@ -376,7 +376,7 @@ function ue(e) {
376
376
  }
377
377
  async function fe(e, t, n, a, o = !1, s) {
378
378
  try {
379
- return !s && a !== b.DirectPlayback && (s = await t.newChat(e.id, {
379
+ return !s && a !== j.DirectPlayback && (s = await t.newChat(e.id, {
380
380
  persist: o
381
381
  }, ue(a)), n.track("agent-chat", {
382
382
  event: "created",
@@ -398,10 +398,10 @@ async function fe(e, t, n, a, o = !1, s) {
398
398
  throw new Error("Cannot create new chat");
399
399
  }
400
400
  }
401
- function Ue(e) {
401
+ function He(e) {
402
402
  return e && e.length > 0 ? e : [];
403
403
  }
404
- function He(e) {
404
+ function Ke(e) {
405
405
  return new Promise((t, n) => {
406
406
  const {
407
407
  callbacks: a,
@@ -412,22 +412,22 @@ function He(e) {
412
412
  onOpen: i = null,
413
413
  onClose: c = null,
414
414
  onError: l = null
415
- } = a || {}, f = new WebSocket(`${o}?authorization=${ce(s)}`);
416
- f.onmessage = r, f.onclose = c, f.onerror = (m) => {
417
- console.error(m), l == null || l("Websocket failed to connect", m), n(m);
418
- }, f.onopen = (m) => {
419
- i == null || i(m), t(f);
415
+ } = a || {}, u = new WebSocket(`${o}?authorization=${ce(s)}`);
416
+ u.onmessage = r, u.onclose = c, u.onerror = (f) => {
417
+ console.error(f), l == null || l("Websocket failed to connect", f), n(f);
418
+ }, u.onopen = (f) => {
419
+ i == null || i(f), t(u);
420
420
  };
421
421
  });
422
422
  }
423
- async function Ke(e) {
423
+ async function qe(e) {
424
424
  const {
425
425
  retries: t = 1
426
426
  } = e;
427
427
  let n = null;
428
428
  for (let a = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; a++)
429
429
  try {
430
- n = await He(e);
430
+ n = await Ke(e);
431
431
  } catch (o) {
432
432
  if (a === t)
433
433
  throw o;
@@ -435,8 +435,8 @@ async function Ke(e) {
435
435
  }
436
436
  return n;
437
437
  }
438
- async function qe(e, t, n) {
439
- const a = n != null && n.onMessage ? [n.onMessage] : [], o = await Ke({
438
+ async function Xe(e, t, n) {
439
+ const a = n != null && n.onMessage ? [n.onMessage] : [], o = await qe({
440
440
  auth: e,
441
441
  host: t,
442
442
  callbacks: {
@@ -456,7 +456,7 @@ async function qe(e, t, n) {
456
456
  subscribeToEvents: (s) => a.push(s)
457
457
  };
458
458
  }
459
- function Xe(e) {
459
+ function Ye(e) {
460
460
  if (e.answer !== void 0)
461
461
  return e.answer;
462
462
  let t = 0, n = "";
@@ -464,7 +464,7 @@ function Xe(e) {
464
464
  n += e[t++];
465
465
  return n;
466
466
  }
467
- function Ye(e, t, n, a, o) {
467
+ function Qe(e, t, n, a, o) {
468
468
  const s = a.messages[a.messages.length - 1];
469
469
  if (!(e === J.Partial || e === J.Answer) || (s == null ? void 0 : s.role) !== "assistant")
470
470
  return;
@@ -473,45 +473,45 @@ function Ye(e, t, n, a, o) {
473
473
  sequence: i
474
474
  } = t;
475
475
  e === J.Partial ? n[i] = r : n.answer = r;
476
- const c = Xe(n);
476
+ const c = Ye(n);
477
477
  (s.content !== c || e === J.Answer) && (s.content = c, o == null || o([...a.messages], e));
478
478
  }
479
- function Qe(e, t, n, a, o) {
479
+ function Ve(e, t, n, a, o) {
480
480
  let s = {};
481
481
  return {
482
482
  clearQueue: () => s = {},
483
483
  onMessage: (r, i) => {
484
484
  var c, l;
485
485
  if ("content" in i)
486
- Ye(r, i, s, t, n.callbacks.onNewMessage), r === J.Answer && e.track("agent-message-received", {
486
+ Qe(r, i, s, t, n.callbacks.onNewMessage), r === J.Answer && e.track("agent-message-received", {
487
487
  messages: t.messages.length,
488
488
  mode: t.chatMode
489
489
  });
490
490
  else {
491
- const f = X, m = [f.StreamVideoDone, f.StreamVideoError, f.StreamVideoRejected], D = [f.StreamFailed, f.StreamVideoError, f.StreamVideoRejected], w = Fe(i, a, {
491
+ const u = Y, f = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], k = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], y = Fe(i, a, {
492
492
  mode: t.chatMode
493
493
  });
494
- if (r = r, r === f.StreamVideoCreated)
495
- e.linkTrack("agent-video", w, f.StreamVideoCreated, ["start"]);
496
- else if (m.includes(r)) {
494
+ if (r = r, r === u.StreamVideoCreated)
495
+ e.linkTrack("agent-video", y, u.StreamVideoCreated, ["start"]);
496
+ else if (f.includes(r)) {
497
497
  const C = r.split("/")[1];
498
- D.includes(r) ? e.track("agent-video", {
499
- ...w,
498
+ k.includes(r) ? e.track("agent-video", {
499
+ ...y,
500
500
  event: C
501
501
  }) : e.linkTrack("agent-video", {
502
- ...w,
502
+ ...y,
503
503
  event: C
504
504
  }, r, ["done"]);
505
505
  }
506
- D.includes(r) && ((l = (c = n.callbacks).onError) == null || l.call(c, new Error(`Stream failed with event ${r}`), {
506
+ k.includes(r) && ((l = (c = n.callbacks).onError) == null || l.call(c, new Error(`Stream failed with event ${r}`), {
507
507
  data: i
508
- })), i.event === f.StreamDone && o();
508
+ })), i.event === u.StreamDone && o();
509
509
  }
510
510
  }
511
511
  };
512
512
  }
513
- function Ve(e, t, n, a) {
514
- const o = G(e, `${t}/agents/${n}`, a);
513
+ function Ze(e, t, n, a) {
514
+ const o = O(e, `${t}/agents/${n}`, a);
515
515
  return {
516
516
  createStream(s) {
517
517
  return o.post("/streams", {
@@ -547,8 +547,8 @@ function Ve(e, t, n, a) {
547
547
  }
548
548
  };
549
549
  }
550
- function Ze(e, t, n, a) {
551
- const o = G(e, `${t}/agents/${n}`, a);
550
+ function Ge(e, t, n, a) {
551
+ const o = O(e, `${t}/agents/${n}`, a);
552
552
  return {
553
553
  createStream(s, r) {
554
554
  return o.post("/streams", {
@@ -587,7 +587,7 @@ function Ze(e, t, n, a) {
587
587
  }
588
588
  };
589
589
  }
590
- function Ge(e, t, n) {
590
+ function Oe(e, t, n) {
591
591
  const a = (t.timestamp - e.timestamp) / 1e3;
592
592
  return {
593
593
  duration: a,
@@ -607,7 +607,7 @@ function Ge(e, t, n) {
607
607
  lowFpsCount: n
608
608
  };
609
609
  }
610
- function Oe(e) {
610
+ function et(e) {
611
611
  return e.filter((t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0).map((t) => {
612
612
  const {
613
613
  timestamp: n,
@@ -619,7 +619,7 @@ function Oe(e) {
619
619
  };
620
620
  });
621
621
  }
622
- function et(e) {
622
+ function tt(e) {
623
623
  let t = "";
624
624
  for (const n of e.values())
625
625
  if (n && n.type === "codec" && n.mimeType.startsWith("video") && (t = n.mimeType.split("/")[1]), n && n.type === "inbound-rtp" && n.kind === "video")
@@ -643,7 +643,7 @@ function et(e) {
643
643
  };
644
644
  return {};
645
645
  }
646
- function tt(e, t, n) {
646
+ function rt(e, t, n) {
647
647
  const a = e.map((i, c) => c === 0 ? n ? {
648
648
  timestamp: i.timestamp,
649
649
  duration: 0,
@@ -692,11 +692,11 @@ function tt(e, t, n) {
692
692
  framesPerSecond: i.framesPerSecond,
693
693
  freezeCount: i.freezeCount - e[c - 1].freezeCount,
694
694
  freezeDuration: i.freezeDuration - e[c - 1].freezeDuration
695
- }), o = Oe(a), s = o.reduce((i, c) => i + (c.causes.includes("low fps") ? 1 : 0), 0), r = a.map((i) => i.avgJitterDelayInInterval);
695
+ }), o = et(a), s = o.reduce((i, c) => i + (c.causes.includes("low fps") ? 1 : 0), 0), r = a.map((i) => i.avgJitterDelayInInterval);
696
696
  return {
697
697
  webRTCStats: {
698
698
  anomalies: o,
699
- aggregateReport: Ge(e[0], e[e.length - 1], s),
699
+ aggregateReport: Oe(e[0], e[e.length - 1], s),
700
700
  minJitterDelayInInterval: Math.min(...r),
701
701
  maxJitterDelayInInterval: Math.max(...r),
702
702
  avgJitterDelayInInterval: Ne(r)
@@ -705,16 +705,16 @@ function tt(e, t, n) {
705
705
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
706
706
  };
707
707
  }
708
- const Z = 100, rt = Math.max(Math.ceil(400 / Z), 1), nt = 0.25, at = 0.28;
709
- function it() {
708
+ const G = 100, nt = Math.max(Math.ceil(400 / G), 1), at = 0.25, it = 0.28;
709
+ function st() {
710
710
  let e = 0, t, n, a = 0;
711
711
  return (o) => {
712
712
  for (const s of o.values())
713
713
  if (s && s.type === "inbound-rtp" && s.kind === "video") {
714
714
  const r = s.jitterBufferDelay, i = s.jitterBufferEmittedCount;
715
715
  if (n && i > n) {
716
- const f = r - t, m = i - n;
717
- a = f / m;
716
+ const u = r - t, f = i - n;
717
+ a = u / f;
718
718
  }
719
719
  t = r, n = i;
720
720
  const c = s.framesDecoded, l = c - e > 0;
@@ -730,46 +730,46 @@ function it() {
730
730
  };
731
731
  };
732
732
  }
733
- function st(e, t, n, a, o, s = !1) {
734
- let r = [], i, c = 0, l = !1, f = W.Unknown, m = W.Unknown, D = 0, w = 0;
735
- const C = it();
733
+ function ot(e, t, n, a, o, s = !1) {
734
+ let r = [], i, c = 0, l = !1, u = W.Unknown, f = W.Unknown, k = 0, y = 0;
735
+ const C = st();
736
736
  return setInterval(async () => {
737
- const R = await e.getStats(), {
738
- isReceiving: S,
739
- avgJitterDelayInInterval: P,
737
+ const S = await e.getStats(), {
738
+ isReceiving: B,
739
+ avgJitterDelayInInterval: M,
740
740
  freezeCount: d
741
- } = C(R), g = et(R);
742
- if (S)
743
- c = 0, D = d - w, m = P < nt ? W.Strong : P > at && D > 1 ? W.Weak : f, m !== f && (o == null || o(m), f = m, w += D, D = 0), l || (a == null || a(v.Start), i = r[r.length - 1], r = [], l = !0), r.push(g);
744
- else if (l && (c++, c >= rt)) {
745
- const y = tt(r, Z, i);
746
- a == null || a(v.Stop, y), t() || n(), l = !1;
741
+ } = C(S), w = tt(S);
742
+ if (B)
743
+ c = 0, k = d - y, f = M < at ? W.Strong : M > it && k > 1 ? W.Weak : u, f !== u && (o == null || o(f), u = f, y += k, k = 0), l || (a == null || a(v.Start), i = r[r.length - 1], r = [], l = !0), r.push(w);
744
+ else if (l && (c++, c >= nt)) {
745
+ const h = rt(r, G, i);
746
+ a == null || a(v.Stop, h), t() || n(), l = !1;
747
747
  }
748
- }, Z);
748
+ }, G);
749
749
  }
750
750
  let me = !1;
751
- const z = (e, t) => me && console.log(e, t), ot = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
751
+ const z = (e, t) => me && console.log(e, t), ct = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
752
752
  function re(e) {
753
753
  switch (e) {
754
754
  case "connected":
755
- return M.Connected;
755
+ return I.Connected;
756
756
  case "checking":
757
- return M.Connecting;
757
+ return I.Connecting;
758
758
  case "failed":
759
- return M.Fail;
759
+ return I.Fail;
760
760
  case "new":
761
- return M.New;
761
+ return I.New;
762
762
  case "closed":
763
- return M.Closed;
763
+ return I.Closed;
764
764
  case "disconnected":
765
- return M.Disconnected;
765
+ return I.Disconnected;
766
766
  case "completed":
767
- return M.Completed;
767
+ return I.Completed;
768
768
  default:
769
- return M.New;
769
+ return I.New;
770
770
  }
771
771
  }
772
- function ct({
772
+ function dt({
773
773
  statsSignal: e,
774
774
  dataChannelSignal: t,
775
775
  onVideoStateChange: n,
@@ -777,14 +777,14 @@ function ct({
777
777
  }) {
778
778
  e === v.Start && t === v.Start ? n == null || n(v.Start) : e === v.Stop && t === v.Stop && (n == null || n(v.Stop, a));
779
779
  }
780
- function dt({
780
+ function lt({
781
781
  statsSignal: e,
782
782
  dataChannelSignal: t,
783
783
  onVideoStateChange: n,
784
784
  onAgentActivityStateChange: a,
785
785
  report: o
786
786
  }) {
787
- e === v.Start ? n == null || n(v.Start) : e === v.Stop && (n == null || n(v.Stop, o)), t === v.Start ? a == null || a(H.Talking) : t === v.Stop && (a == null || a(H.Idle));
787
+ e === v.Start ? n == null || n(v.Start) : e === v.Stop && (n == null || n(v.Stop, o)), t === v.Start ? a == null || a(K.Talking) : t === v.Stop && (a == null || a(K.Idle));
788
788
  }
789
789
  function ne({
790
790
  statsSignal: e,
@@ -794,12 +794,12 @@ function ne({
794
794
  streamType: o,
795
795
  report: s
796
796
  }) {
797
- o === F.Legacy ? ct({
797
+ o === N.Legacy ? dt({
798
798
  statsSignal: e,
799
799
  dataChannelSignal: t,
800
800
  onVideoStateChange: n,
801
801
  report: s
802
- }) : o === F.Fluent && dt({
802
+ }) : o === N.Fluent && lt({
803
803
  statsSignal: e,
804
804
  dataChannelSignal: t,
805
805
  onVideoStateChange: n,
@@ -807,124 +807,129 @@ function ne({
807
807
  report: s
808
808
  });
809
809
  }
810
- async function lt(e, t, {
810
+ async function ut(e, t, {
811
811
  debug: n = !1,
812
812
  callbacks: a,
813
813
  auth: o,
814
- baseURL: s = K
814
+ baseURL: s = q,
815
+ analytics: r
815
816
  }) {
816
817
  me = n;
817
- let r = !1, i = !1, c = v.Stop, l = v.Stop, f = W.Unknown;
818
+ let i = !1, c = !1, l = v.Stop, u = v.Stop, f = W.Unknown;
818
819
  const {
819
- startConnection: m,
820
- sendStreamRequest: D,
821
- close: w,
822
- createStream: C,
823
- addIceCandidate: R
824
- } = t.videoType === ie.Clip ? Ve(o, s, e, a.onError) : Ze(o, s, e, a.onError), {
825
- id: S,
826
- offer: P,
827
- ice_servers: d,
828
- session_id: g,
829
- fluent: y
830
- } = await C(t), h = new ot({
831
- iceServers: d
832
- }), I = h.createDataChannel("JanusDataChannel");
833
- if (!g)
820
+ startConnection: k,
821
+ sendStreamRequest: y,
822
+ close: C,
823
+ createStream: S,
824
+ addIceCandidate: B
825
+ } = t.videoType === ie.Clip ? Ze(o, s, e, a.onError) : Ge(o, s, e, a.onError), {
826
+ id: M,
827
+ offer: d,
828
+ ice_servers: w,
829
+ session_id: h,
830
+ fluent: b
831
+ } = await S(t), g = new ct({
832
+ iceServers: w
833
+ }), D = g.createDataChannel("JanusDataChannel");
834
+ if (!h)
834
835
  throw new Error("Could not create session_id");
835
- const k = y ? F.Fluent : F.Legacy, T = t.stream_warmup && !y, $ = () => r, B = () => {
836
- var u;
837
- r = !0, i && ((u = a.onConnectionStateChange) == null || u.call(a, M.Connected));
838
- }, E = st(h, $, B, (u, p) => ne({
839
- statsSignal: l = u,
840
- dataChannelSignal: k === F.Legacy ? c : void 0,
836
+ const _ = b ? N.Fluent : N.Legacy;
837
+ r.enrich({
838
+ "stream-type": _
839
+ });
840
+ const P = t.stream_warmup && !b, L = () => i, R = () => {
841
+ var m;
842
+ i = !0, c && ((m = a.onConnectionStateChange) == null || m.call(a, I.Connected));
843
+ }, T = ot(g, L, R, (m, p) => ne({
844
+ statsSignal: u = m,
845
+ dataChannelSignal: _ === N.Legacy ? l : void 0,
841
846
  onVideoStateChange: a.onVideoStateChange,
842
847
  onAgentActivityStateChange: a.onAgentActivityStateChange,
843
848
  report: p,
844
- streamType: k
845
- }), (u) => {
849
+ streamType: _
850
+ }), (m) => {
846
851
  var p;
847
852
  return (p = a.onConnectivityStateChange) == null ? void 0 : p.call(a, f);
848
- }, T);
849
- h.onicecandidate = (u) => {
853
+ }, P);
854
+ g.onicecandidate = (m) => {
850
855
  var p;
851
- z("peerConnection.onicecandidate", u);
856
+ z("peerConnection.onicecandidate", m);
852
857
  try {
853
- u.candidate && u.candidate.sdpMid && u.candidate.sdpMLineIndex !== null ? R(S, {
854
- candidate: u.candidate.candidate,
855
- sdpMid: u.candidate.sdpMid,
856
- sdpMLineIndex: u.candidate.sdpMLineIndex
857
- }, g) : R(S, {
858
+ m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? B(M, {
859
+ candidate: m.candidate.candidate,
860
+ sdpMid: m.candidate.sdpMid,
861
+ sdpMLineIndex: m.candidate.sdpMLineIndex
862
+ }, h) : B(M, {
858
863
  candidate: null
859
- }, g);
860
- } catch (j) {
861
- (p = a.onError) == null || p.call(a, j, {
862
- streamId: S
864
+ }, h);
865
+ } catch ($) {
866
+ (p = a.onError) == null || p.call(a, $, {
867
+ streamId: M
863
868
  });
864
869
  }
865
- }, I.onopen = () => {
866
- i = !0, (!T || r) && B();
867
- }, I.onmessage = (u) => {
868
- u.data in te && (c = te[u.data], ne({
869
- statsSignal: k === F.Legacy ? l : void 0,
870
- dataChannelSignal: c,
870
+ }, D.onopen = () => {
871
+ c = !0, (!P || i) && R();
872
+ }, D.onmessage = (m) => {
873
+ m.data in te && (l = te[m.data], ne({
874
+ statsSignal: _ === N.Legacy ? u : void 0,
875
+ dataChannelSignal: l,
871
876
  onVideoStateChange: a.onVideoStateChange,
872
877
  onAgentActivityStateChange: a.onAgentActivityStateChange,
873
- streamType: k
878
+ streamType: _
874
879
  }));
875
- }, h.oniceconnectionstatechange = () => {
880
+ }, g.oniceconnectionstatechange = () => {
876
881
  var p;
877
- z("peerConnection.oniceconnectionstatechange => " + h.iceConnectionState);
878
- const u = re(h.iceConnectionState);
879
- u !== M.Connected && ((p = a.onConnectionStateChange) == null || p.call(a, u));
880
- }, h.ontrack = (u) => {
882
+ z("peerConnection.oniceconnectionstatechange => " + g.iceConnectionState);
883
+ const m = re(g.iceConnectionState);
884
+ m !== I.Connected && ((p = a.onConnectionStateChange) == null || p.call(a, m));
885
+ }, g.ontrack = (m) => {
881
886
  var p;
882
- z("peerConnection.ontrack", u), (p = a.onSrcObjectReady) == null || p.call(a, u.streams[0]);
883
- }, await h.setRemoteDescription(P), z("set remote description OK");
884
- const _ = await h.createAnswer();
885
- return z("create answer OK"), await h.setLocalDescription(_), z("set local description OK"), await m(S, _, g), z("start connection OK"), {
887
+ z("peerConnection.ontrack", m), (p = a.onSrcObjectReady) == null || p.call(a, m.streams[0]);
888
+ }, await g.setRemoteDescription(d), z("set remote description OK");
889
+ const E = await g.createAnswer();
890
+ return z("create answer OK"), await g.setLocalDescription(E), z("set local description OK"), await k(M, E, h), z("start connection OK"), {
886
891
  /**
887
892
  * Method to send request to server to get clip or talk depend on you payload
888
893
  * @param payload
889
894
  */
890
- speak(u) {
891
- return D(S, g, u);
895
+ speak(m) {
896
+ return y(M, h, m);
892
897
  },
893
898
  /**
894
899
  * Method to close RTC connection
895
900
  */
896
901
  async disconnect() {
897
- var u, p, j;
898
- if (S) {
899
- const L = re(h.iceConnectionState);
900
- if (h) {
901
- if (L === M.New) {
902
- (u = a.onVideoStateChange) == null || u.call(a, v.Stop), clearInterval(E);
902
+ var m, p, $;
903
+ if (M) {
904
+ const A = re(g.iceConnectionState);
905
+ if (g) {
906
+ if (A === I.New) {
907
+ (m = a.onVideoStateChange) == null || m.call(a, v.Stop), clearInterval(T);
903
908
  return;
904
909
  }
905
- h.close(), h.oniceconnectionstatechange = null, h.onnegotiationneeded = null, h.onicecandidate = null, h.ontrack = null;
910
+ g.close(), g.oniceconnectionstatechange = null, g.onnegotiationneeded = null, g.onicecandidate = null, g.ontrack = null;
906
911
  }
907
912
  try {
908
- L === M.Connected && await w(S, g).catch((A) => {
913
+ A === I.Connected && await C(M, h).catch((U) => {
909
914
  });
910
- } catch (A) {
911
- z("Error on close stream connection", A);
915
+ } catch (U) {
916
+ z("Error on close stream connection", U);
912
917
  }
913
- (p = a.onVideoStateChange) == null || p.call(a, v.Stop), (j = a.onAgentActivityStateChange) == null || j.call(a, H.Idle), clearInterval(E);
918
+ (p = a.onVideoStateChange) == null || p.call(a, v.Stop), ($ = a.onAgentActivityStateChange) == null || $.call(a, K.Idle), clearInterval(T);
914
919
  }
915
920
  },
916
921
  /**
917
922
  * Session identifier information, should be returned in the body of all streaming requests
918
923
  */
919
- sessionId: g,
924
+ sessionId: h,
920
925
  /**
921
926
  * Id of current RTC stream
922
927
  */
923
- streamId: S,
924
- streamType: k
928
+ streamId: M,
929
+ streamType: _
925
930
  };
926
931
  }
927
- function ut(e, t) {
932
+ function ft(e, t) {
928
933
  const {
929
934
  streamOptions: n
930
935
  } = t ?? {};
@@ -938,29 +943,29 @@ function ut(e, t) {
938
943
  };
939
944
  }
940
945
  function ae(e, t, n, a, o) {
941
- N.get() > 0 && (e === v.Start ? a.linkTrack("agent-video", {
946
+ x.get() > 0 && (e === v.Start ? a.linkTrack("agent-video", {
942
947
  event: "start",
943
- latency: N.get(!0),
948
+ latency: x.get(!0),
944
949
  "stream-type": o
945
- }, "start", [X.StreamVideoCreated]) : e === v.Stop && a.linkTrack("agent-video", {
950
+ }, "start", [Y.StreamVideoCreated]) : e === v.Stop && a.linkTrack("agent-video", {
946
951
  event: "stop",
947
952
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
948
953
  background: t.presenter.type === "clip" && t.presenter.background,
949
954
  "stream-type": o,
950
955
  ...n
951
- }, "done", [X.StreamVideoDone]));
956
+ }, "done", [Y.StreamVideoDone]));
952
957
  }
953
- function ft(e, t, n) {
954
- return N.reset(), new Promise(async (a, o) => {
958
+ function mt(e, t, n) {
959
+ return x.reset(), new Promise(async (a, o) => {
955
960
  try {
956
- const s = await lt(e.id, ut(e, t), {
961
+ const s = await ut(e.id, ft(e, t), {
957
962
  ...t,
958
963
  analytics: n,
959
964
  callbacks: {
960
965
  ...t.callbacks,
961
966
  onConnectionStateChange: (r) => {
962
967
  var i, c;
963
- (c = (i = t.callbacks).onConnectionStateChange) == null || c.call(i, r), r === M.Connected && a(s);
968
+ (c = (i = t.callbacks).onConnectionStateChange) == null || c.call(i, r), r === I.Connected && a(s);
964
969
  },
965
970
  onVideoStateChange: (r, i) => {
966
971
  var c, l;
@@ -968,7 +973,7 @@ function ft(e, t, n) {
968
973
  },
969
974
  onAgentActivityStateChange: (r) => {
970
975
  var i, c;
971
- (c = (i = t.callbacks).onAgentActivityStateChange) == null || c.call(i, r), ae(r === H.Talking ? v.Start : v.Stop, e, void 0, n, s.streamType);
976
+ (c = (i = t.callbacks).onAgentActivityStateChange) == null || c.call(i, r), ae(r === K.Talking ? v.Start : v.Stop, e, void 0, n, s.streamType);
972
977
  }
973
978
  }
974
979
  });
@@ -977,75 +982,75 @@ function ft(e, t, n) {
977
982
  }
978
983
  });
979
984
  }
980
- async function mt(e, t, n, a, o) {
981
- var c, l, f, m;
985
+ async function gt(e, t, n, a, o) {
986
+ var c, l, u, f;
982
987
  const {
983
988
  chat: s,
984
989
  chatMode: r
985
990
  } = await fe(e, n, a, t.mode, t.persistentChat, o);
986
- if (r && r !== t.mode && (t.mode = r, (l = (c = t.callbacks).onModeChange) == null || l.call(c, r), r === b.TextOnly))
987
- return (m = (f = t.callbacks).onError) == null || m.call(f, new pe(r)), {
991
+ if (r && r !== t.mode && (t.mode = r, (l = (c = t.callbacks).onModeChange) == null || l.call(c, r), r === j.TextOnly))
992
+ return (f = (u = t.callbacks).onError) == null || f.call(u, new pe(r)), {
988
993
  chat: s
989
994
  };
990
- const i = await ft(e, t, a);
995
+ const i = await mt(e, t, a);
991
996
  return {
992
997
  chat: s,
993
998
  streamingManager: i
994
999
  };
995
1000
  }
996
- async function ht(e, t) {
997
- var R, S, P;
1001
+ async function wt(e, t) {
1002
+ var S, B, M;
998
1003
  let n = !0;
999
- const a = t.mixpanelKey || Pe, o = t.wsURL || be, s = t.baseURL || K, r = {
1004
+ const a = t.mixpanelKey || Pe, o = t.wsURL || be, s = t.baseURL || q, r = {
1000
1005
  messages: [],
1001
- chatMode: t.mode || b.Functional
1002
- }, i = de(t.auth, s, t.callbacks.onError), c = await i.getById(e), l = Je({
1006
+ chatMode: t.mode || j.Functional
1007
+ }, i = de(t.auth, s, t.callbacks.onError), c = await i.getById(e), l = We({
1003
1008
  token: a,
1004
1009
  agent: c,
1005
1010
  isEnabled: t.enableAnalitics,
1006
1011
  distinctId: t.distinctId
1007
1012
  }), {
1008
- onMessage: f,
1009
- clearQueue: m
1010
- } = Qe(l, r, t, c, () => {
1013
+ onMessage: u,
1014
+ clearQueue: f
1015
+ } = Ve(l, r, t, c, () => {
1011
1016
  var d;
1012
1017
  return (d = r.socketManager) == null ? void 0 : d.disconnect();
1013
1018
  });
1014
- r.messages = Ue(t.initialMessages), (S = (R = t.callbacks).onNewMessage) == null || S.call(R, [...r.messages], "answer"), l.track("agent-sdk", {
1019
+ r.messages = He(t.initialMessages), (B = (S = t.callbacks).onNewMessage) == null || B.call(S, [...r.messages], "answer"), l.track("agent-sdk", {
1015
1020
  event: "loaded",
1016
- ...Ae(c)
1021
+ ...ze(c)
1017
1022
  });
1018
- async function D(d) {
1019
- var T, $, B, E, _, u, p;
1020
- ($ = (T = t.callbacks).onConnectionStateChange) == null || $.call(T, M.Connecting), N.reset(), d && !n && (delete r.chat, (E = (B = t.callbacks).onNewMessage) == null || E.call(B, [...r.messages], "answer"));
1021
- const g = t.mode === b.DirectPlayback ? Promise.resolve(void 0) : qe(t.auth, o, {
1022
- onMessage: f,
1023
+ async function k(d) {
1024
+ var _, P, L, R, T, E, m;
1025
+ (P = (_ = t.callbacks).onConnectionStateChange) == null || P.call(_, I.Connecting), x.reset(), d && !n && (delete r.chat, (R = (L = t.callbacks).onNewMessage) == null || R.call(L, [...r.messages], "answer"));
1026
+ const w = t.mode === j.DirectPlayback ? Promise.resolve(void 0) : Xe(t.auth, o, {
1027
+ onMessage: u,
1023
1028
  onError: t.callbacks.onError
1024
- }), y = V(() => mt(c, t, i, l, r.chat), {
1029
+ }), h = Z(() => gt(c, t, i, l, r.chat), {
1025
1030
  limit: 3,
1026
1031
  timeout: Te,
1027
1032
  timeoutErrorMessage: "Timeout initializing the stream",
1028
1033
  // Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
1029
- shouldRetryFn: (j) => (j == null ? void 0 : j.message) !== "Could not connect" && j.status !== 429,
1034
+ shouldRetryFn: (p) => (p == null ? void 0 : p.message) !== "Could not connect" && p.status !== 429,
1030
1035
  delayMs: 1e3
1031
- }).catch((j) => {
1032
- var L, A;
1033
- throw C(b.Maintenance), (A = (L = t.callbacks).onConnectionStateChange) == null || A.call(L, M.Fail), j;
1034
- }), [h, {
1035
- streamingManager: I,
1036
- chat: k
1037
- }] = await Promise.all([g, y]);
1038
- k && k.id !== ((_ = r.chat) == null ? void 0 : _.id) && ((p = (u = t.callbacks).onNewChat) == null || p.call(u, k.id)), r.streamingManager = I, r.socketManager = h, r.chat = k, n = !1, C((k == null ? void 0 : k.chat_mode) ?? t.mode ?? b.Functional);
1036
+ }).catch((p) => {
1037
+ var $, A;
1038
+ throw C(j.Maintenance), (A = ($ = t.callbacks).onConnectionStateChange) == null || A.call($, I.Fail), p;
1039
+ }), [b, {
1040
+ streamingManager: g,
1041
+ chat: D
1042
+ }] = await Promise.all([w, h]);
1043
+ D && D.id !== ((T = r.chat) == null ? void 0 : T.id) && ((m = (E = t.callbacks).onNewChat) == null || m.call(E, D.id)), r.streamingManager = g, r.socketManager = b, r.chat = D, n = !1, C((D == null ? void 0 : D.chat_mode) ?? t.mode ?? j.Functional);
1039
1044
  }
1040
- async function w() {
1041
- var d, g, y, h;
1042
- (d = r.socketManager) == null || d.disconnect(), await ((g = r.streamingManager) == null ? void 0 : g.disconnect()), delete r.streamingManager, delete r.socketManager, (h = (y = t.callbacks).onConnectionStateChange) == null || h.call(y, M.Disconnected);
1045
+ async function y() {
1046
+ var d, w, h, b;
1047
+ (d = r.socketManager) == null || d.disconnect(), await ((w = r.streamingManager) == null ? void 0 : w.disconnect()), delete r.streamingManager, delete r.socketManager, (b = (h = t.callbacks).onConnectionStateChange) == null || b.call(h, I.Disconnected);
1043
1048
  }
1044
1049
  async function C(d) {
1045
- var g, y;
1050
+ var w, h;
1046
1051
  d !== r.chatMode && (l.track("agent-mode-change", {
1047
1052
  mode: d
1048
- }), r.chatMode = d, r.chatMode !== b.Functional && await w(), (y = (g = t.callbacks).onModeChange) == null || y.call(g, d));
1053
+ }), r.chatMode = d, r.chatMode !== j.Functional && await y(), (h = (w = t.callbacks).onModeChange) == null || h.call(w, d));
1049
1054
  }
1050
1055
  return {
1051
1056
  agent: c,
@@ -1053,13 +1058,13 @@ async function ht(e, t) {
1053
1058
  var d;
1054
1059
  return (d = r.streamingManager) == null ? void 0 : d.streamType;
1055
1060
  },
1056
- starterMessages: ((P = c.knowledge) == null ? void 0 : P.starter_message) || [],
1061
+ starterMessages: ((M = c.knowledge) == null ? void 0 : M.starter_message) || [],
1057
1062
  getSTTToken: () => i.getSTTToken(c.id),
1058
1063
  changeMode: C,
1059
1064
  enrichAnalytics: l.enrich,
1060
1065
  async connect() {
1061
1066
  var d;
1062
- await D(!0), l.track("agent-chat", {
1067
+ await k(!0), l.track("agent-chat", {
1063
1068
  event: "connect",
1064
1069
  chatId: (d = r.chat) == null ? void 0 : d.id,
1065
1070
  agentId: c.id,
@@ -1068,7 +1073,7 @@ async function ht(e, t) {
1068
1073
  },
1069
1074
  async reconnect() {
1070
1075
  var d;
1071
- await w(), await D(!1), l.track("agent-chat", {
1076
+ await y(), await k(!1), l.track("agent-chat", {
1072
1077
  event: "reconnect",
1073
1078
  chatId: (d = r.chat) == null ? void 0 : d.id,
1074
1079
  agentId: c.id,
@@ -1077,7 +1082,7 @@ async function ht(e, t) {
1077
1082
  },
1078
1083
  async disconnect() {
1079
1084
  var d;
1080
- await w(), l.track("agent-chat", {
1085
+ await y(), l.track("agent-chat", {
1081
1086
  event: "disconnect",
1082
1087
  chatId: (d = r.chat) == null ? void 0 : d.id,
1083
1088
  agentId: c.id,
@@ -1085,132 +1090,132 @@ async function ht(e, t) {
1085
1090
  });
1086
1091
  },
1087
1092
  async chat(d) {
1088
- var I, k, T, $, B;
1089
- const g = () => {
1090
- if (t.mode === b.DirectPlayback)
1091
- throw new x("Direct playback is enabled, chat is disabled");
1093
+ var g, D, _, P, L;
1094
+ const w = () => {
1095
+ if (t.mode === j.DirectPlayback)
1096
+ throw new F("Direct playback is enabled, chat is disabled");
1092
1097
  if (d.length >= 800)
1093
- throw new x("Message cannot be more than 800 characters");
1098
+ throw new F("Message cannot be more than 800 characters");
1094
1099
  if (d.length === 0)
1095
- throw new x("Message cannot be empty");
1096
- if (r.chatMode === b.Maintenance)
1097
- throw new x("Chat is in maintenance mode");
1098
- if (![b.TextOnly, b.Playground].includes(r.chatMode)) {
1100
+ throw new F("Message cannot be empty");
1101
+ if (r.chatMode === j.Maintenance)
1102
+ throw new F("Chat is in maintenance mode");
1103
+ if (![j.TextOnly, j.Playground].includes(r.chatMode)) {
1099
1104
  if (!r.streamingManager)
1100
- throw new x("Streaming manager is not initialized");
1105
+ throw new F("Streaming manager is not initialized");
1101
1106
  if (!r.chat)
1102
- throw new x("Chat is not initialized");
1107
+ throw new F("Chat is not initialized");
1103
1108
  }
1104
- }, y = async () => {
1105
- var E, _;
1109
+ }, h = async () => {
1110
+ var R, T;
1106
1111
  if (!r.chat) {
1107
- const u = await fe(c, i, l, r.chatMode, t.persistentChat);
1108
- if (!u.chat)
1112
+ const E = await fe(c, i, l, r.chatMode, t.persistentChat);
1113
+ if (!E.chat)
1109
1114
  throw new we(r.chatMode, !!t.persistentChat);
1110
- r.chat = u.chat, (_ = (E = t.callbacks).onNewChat) == null || _.call(E, r.chat.id);
1115
+ r.chat = E.chat, (T = (R = t.callbacks).onNewChat) == null || T.call(R, r.chat.id);
1111
1116
  }
1112
1117
  return r.chat.id;
1113
- }, h = async (E, _) => V(() => {
1114
- var u, p;
1115
- return i.chat(c.id, _, {
1118
+ }, b = async (R, T) => Z(() => {
1119
+ var E, m;
1120
+ return i.chat(c.id, T, {
1116
1121
  chatMode: r.chatMode,
1117
- streamId: (u = r.streamingManager) == null ? void 0 : u.streamId,
1118
- sessionId: (p = r.streamingManager) == null ? void 0 : p.sessionId,
1119
- messages: E.map(({
1120
- matches: j,
1121
- ...L
1122
- }) => L)
1122
+ streamId: (E = r.streamingManager) == null ? void 0 : E.streamId,
1123
+ sessionId: (m = r.streamingManager) == null ? void 0 : m.sessionId,
1124
+ messages: R.map(({
1125
+ matches: p,
1126
+ ...$
1127
+ }) => $)
1123
1128
  }, {
1124
1129
  ...ue(r.chatMode),
1125
1130
  skipErrorHandler: !0
1126
1131
  });
1127
1132
  }, {
1128
1133
  limit: 2,
1129
- shouldRetryFn: (u) => {
1130
- var L, A, O, ee;
1131
- const p = (L = u == null ? void 0 : u.message) == null ? void 0 : L.includes("missing or invalid session_id");
1132
- return !((A = u == null ? void 0 : u.message) == null ? void 0 : A.includes("Stream Error")) && !p ? ((ee = (O = t.callbacks).onError) == null || ee.call(O, u), !1) : !0;
1134
+ shouldRetryFn: (E) => {
1135
+ var $, A, U, ee;
1136
+ const m = ($ = E == null ? void 0 : E.message) == null ? void 0 : $.includes("missing or invalid session_id");
1137
+ return !((A = E == null ? void 0 : E.message) == null ? void 0 : A.includes("Stream Error")) && !m ? ((ee = (U = t.callbacks).onError) == null || ee.call(U, E), !1) : !0;
1133
1138
  },
1134
1139
  onRetry: async () => {
1135
- await w(), await D(!1);
1140
+ await y(), await k(!1);
1136
1141
  }
1137
1142
  });
1138
1143
  try {
1139
- m(), g(), r.messages.push({
1140
- id: q(),
1144
+ f(), w(), r.messages.push({
1145
+ id: X(),
1141
1146
  role: "user",
1142
1147
  content: d,
1143
- created_at: new Date(N.update()).toISOString()
1144
- }), (k = (I = t.callbacks).onNewMessage) == null || k.call(I, [...r.messages], "user");
1145
- const E = await y(), _ = await h([...r.messages], E);
1148
+ created_at: new Date(x.update()).toISOString()
1149
+ }), (D = (g = t.callbacks).onNewMessage) == null || D.call(g, [...r.messages], "user");
1150
+ const R = await h(), T = await b([...r.messages], R);
1146
1151
  return r.messages.push({
1147
- id: q(),
1152
+ id: X(),
1148
1153
  role: "assistant",
1149
- content: _.result || "",
1154
+ content: T.result || "",
1150
1155
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1151
- context: _.context,
1152
- matches: _.matches
1156
+ context: T.context,
1157
+ matches: T.matches
1153
1158
  }), l.track("agent-message-send", {
1154
1159
  event: "success",
1155
1160
  mode: r.chatMode,
1156
1161
  messages: r.messages.length + 1
1157
- }), _.result && (($ = (T = t.callbacks).onNewMessage) == null || $.call(T, [...r.messages], "answer"), l.track("agent-message-received", {
1158
- latency: N.get(!0),
1162
+ }), T.result && ((P = (_ = t.callbacks).onNewMessage) == null || P.call(_, [...r.messages], "answer"), l.track("agent-message-received", {
1163
+ latency: x.get(!0),
1159
1164
  mode: r.chatMode,
1160
1165
  messages: r.messages.length
1161
- })), _;
1162
- } catch (E) {
1163
- throw ((B = r.messages[r.messages.length - 1]) == null ? void 0 : B.role) === "assistant" && r.messages.pop(), l.track("agent-message-send", {
1166
+ })), T;
1167
+ } catch (R) {
1168
+ throw ((L = r.messages[r.messages.length - 1]) == null ? void 0 : L.role) === "assistant" && r.messages.pop(), l.track("agent-message-send", {
1164
1169
  event: "error",
1165
1170
  mode: r.chatMode,
1166
1171
  messages: r.messages.length
1167
- }), E;
1172
+ }), R;
1168
1173
  }
1169
1174
  },
1170
- rate(d, g, y) {
1171
- var k, T, $, B;
1172
- const h = r.messages.find((E) => E.id === d);
1175
+ rate(d, w, h) {
1176
+ var D, _, P, L;
1177
+ const b = r.messages.find((R) => R.id === d);
1173
1178
  if (r.chat) {
1174
- if (!h)
1179
+ if (!b)
1175
1180
  throw new Error("Message not found");
1176
1181
  } else
1177
1182
  throw new Error("Chat is not initialized");
1178
- const I = ((k = h.matches) == null ? void 0 : k.map((E) => [E.document_id, E.id])) ?? [];
1183
+ const g = ((D = b.matches) == null ? void 0 : D.map((R) => [R.document_id, R.id])) ?? [];
1179
1184
  return l.track("agent-rate", {
1180
- event: y ? "update" : "create",
1181
- thumb: g === 1 ? "up" : "down",
1182
- knowledge_id: ((T = c.knowledge) == null ? void 0 : T.id) ?? "",
1185
+ event: h ? "update" : "create",
1186
+ thumb: w === 1 ? "up" : "down",
1187
+ knowledge_id: ((_ = c.knowledge) == null ? void 0 : _.id) ?? "",
1183
1188
  mode: r.chatMode,
1184
- matches: I,
1185
- score: g
1186
- }), y ? i.updateRating(c.id, r.chat.id, y, {
1187
- knowledge_id: (($ = c.knowledge) == null ? void 0 : $.id) ?? "",
1189
+ matches: g,
1190
+ score: w
1191
+ }), h ? i.updateRating(c.id, r.chat.id, h, {
1192
+ knowledge_id: ((P = c.knowledge) == null ? void 0 : P.id) ?? "",
1188
1193
  message_id: d,
1189
- matches: I,
1190
- score: g
1194
+ matches: g,
1195
+ score: w
1191
1196
  }) : i.createRating(c.id, r.chat.id, {
1192
- knowledge_id: ((B = c.knowledge) == null ? void 0 : B.id) ?? "",
1197
+ knowledge_id: ((L = c.knowledge) == null ? void 0 : L.id) ?? "",
1193
1198
  message_id: d,
1194
- matches: I,
1195
- score: g
1199
+ matches: g,
1200
+ score: w
1196
1201
  });
1197
1202
  },
1198
1203
  deleteRate(d) {
1199
- var g;
1204
+ var w;
1200
1205
  if (!r.chat)
1201
1206
  throw new Error("Chat is not initialized");
1202
1207
  return l.track("agent-rate-delete", {
1203
1208
  type: "text",
1204
- chat_id: (g = r.chat) == null ? void 0 : g.id,
1209
+ chat_id: (w = r.chat) == null ? void 0 : w.id,
1205
1210
  id: d,
1206
1211
  mode: r.chatMode
1207
1212
  }), i.deleteRating(c.id, r.chat.id, d);
1208
1213
  },
1209
- speak(d) {
1210
- var h, I, k, T;
1214
+ async speak(d) {
1215
+ var g, D, _, P;
1211
1216
  if (!r.streamingManager)
1212
1217
  throw new Error("Please connect to the agent first");
1213
- function g() {
1218
+ function w() {
1214
1219
  if (typeof d == "string") {
1215
1220
  if (!c.presenter.voice)
1216
1221
  throw new Error("Presenter voice is not initialized");
@@ -1233,53 +1238,58 @@ async function ht(e, t) {
1233
1238
  }
1234
1239
  return d;
1235
1240
  }
1236
- const y = g();
1237
- return l.track("agent-speak", y), N.update(), (h = r.chat) != null && h.id && y.type === "text" && (r.messages.push({
1238
- id: q(),
1241
+ const h = w();
1242
+ l.track("agent-speak", h), x.update(), (g = r.chat) != null && g.id && h.type === "text" && (r.messages.push({
1243
+ id: X(),
1239
1244
  role: "assistant",
1240
- content: y.input,
1241
- created_at: new Date(N.get(!0)).toISOString()
1242
- }), (k = (I = t.callbacks).onNewMessage) == null || k.call(I, [...r.messages], "answer")), r.streamingManager.speak({
1243
- script: y,
1245
+ content: h.input,
1246
+ created_at: new Date(x.get(!0)).toISOString()
1247
+ }), (_ = (D = t.callbacks).onNewMessage) == null || _.call(D, [...r.messages], "answer"));
1248
+ const b = Be(r.chatMode);
1249
+ return r.chat && b ? {
1250
+ duration: 0,
1251
+ status: "success"
1252
+ } : r.streamingManager.speak({
1253
+ script: h,
1244
1254
  metadata: {
1245
- chat_id: (T = r.chat) == null ? void 0 : T.id,
1255
+ chat_id: (P = r.chat) == null ? void 0 : P.id,
1246
1256
  agent_id: c.id
1247
1257
  }
1248
1258
  });
1249
1259
  }
1250
1260
  };
1251
1261
  }
1252
- function wt(e, t, n) {
1262
+ function pt(e, t, n) {
1253
1263
  const {
1254
1264
  getById: a
1255
- } = de(t, n || K);
1265
+ } = de(t, n || q);
1256
1266
  return a(e);
1257
1267
  }
1258
1268
  export {
1259
- H as AgentActivityState,
1260
- De as AgentStatus,
1269
+ K as AgentActivityState,
1270
+ Ce as AgentStatus,
1261
1271
  we as ChatCreationFailed,
1262
- b as ChatMode,
1272
+ j as ChatMode,
1263
1273
  pe as ChatModeDowngraded,
1264
1274
  J as ChatProgress,
1265
- M as ConnectionState,
1275
+ I as ConnectionState,
1266
1276
  W as ConnectivityState,
1267
1277
  te as DataChannelSignalMap,
1268
1278
  Se as DocumentType,
1269
1279
  Ee as KnowledgeType,
1270
1280
  ke as PlanGroup,
1271
1281
  _e as Providers,
1272
- Ce as RateState,
1273
- X as StreamEvents,
1274
- F as StreamType,
1282
+ De as RateState,
1283
+ Y as StreamEvents,
1284
+ N as StreamType,
1275
1285
  v as StreamingState,
1276
1286
  Re as Subject,
1277
1287
  ve as UserPlan,
1278
- x as ValidationError,
1288
+ F as ValidationError,
1279
1289
  ie as VideoType,
1280
1290
  Ie as VoiceAccess,
1281
1291
  ye as WsError,
1282
- ht as createAgentManager,
1283
- wt as getAgent,
1292
+ wt as createAgentManager,
1293
+ pt as getAgent,
1284
1294
  Me as mapVideoType
1285
1295
  };