@d-id/client-sdk 1.1.14-staging.59 → 1.1.14-staging.60

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,6 +1,6 @@
1
- var Ce = Object.defineProperty;
2
- var Re = (e, t, n) => t in e ? Ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var Z = (e, t, n) => Re(e, typeof t != "symbol" ? t + "" : t, n);
1
+ var Se = Object.defineProperty;
2
+ var Ie = (e, t, n) => t in e ? Se(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var Z = (e, t, n) => Ie(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  class te extends Error {
5
5
  constructor({ kind: n, description: r, error: i }) {
6
6
  super(JSON.stringify({ kind: n, description: r }));
@@ -10,7 +10,7 @@ class te extends Error {
10
10
  this.kind = n, this.description = r, this.error = i;
11
11
  }
12
12
  }
13
- class Se extends te {
13
+ class Ee extends te {
14
14
  constructor(t, n) {
15
15
  super({
16
16
  kind: "ChatCreationFailed",
@@ -18,7 +18,7 @@ class Se extends te {
18
18
  });
19
19
  }
20
20
  }
21
- class Ie extends te {
21
+ class Me extends te {
22
22
  constructor(t) {
23
23
  super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
24
24
  }
@@ -30,13 +30,13 @@ class H extends te {
30
30
  this.key = r;
31
31
  }
32
32
  }
33
- class Ee extends te {
33
+ class _e extends te {
34
34
  constructor(t) {
35
35
  super({ kind: "WSError", description: t });
36
36
  }
37
37
  }
38
- var Me = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Me || {}), _e = /* @__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))(_e || {}), Te = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Te || {}), Ae = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ae || {}), E = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(E || {}), V = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(V || {}), je = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(je || {}), be = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(be || {}), Pe = /* @__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))(Pe || {}), ue = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(ue || {});
39
- const Pt = (e) => {
38
+ var Te = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Te || {}), Ae = /* @__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))(Ae || {}), je = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(je || {}), Pe = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Pe || {}), E = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(E || {}), V = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(V || {}), be = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(be || {}), Le = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Le || {}), Be = /* @__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))(Be || {}), me = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(me || {});
39
+ const bt = (e) => {
40
40
  switch (e) {
41
41
  case "clip":
42
42
  return "clip";
@@ -46,12 +46,12 @@ const Pt = (e) => {
46
46
  throw new Error(`Unknown video type: ${e}`);
47
47
  }
48
48
  };
49
- var w = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(w || {}), G = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(G || {}), O = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(O || {}), j = /* @__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.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(j || {}), R = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(R || {}), J = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(J || {}), oe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(oe || {}), Le = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Le || {}), Be = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Be || {});
50
- const $e = 45 * 1e3, xe = "X-Playground-Chat", ee = "https://api.d-id.com", ze = "wss://notifications.d-id.com", Fe = "79f81a83a67430be2bc0fd61042b8faa", fe = (e) => new Promise((t) => setTimeout(t, e)), q = (e = 16) => {
49
+ var w = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(w || {}), G = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(G || {}), O = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(O || {}), L = /* @__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.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(L || {}), R = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(R || {}), U = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(U || {}), ce = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(ce || {}), $e = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))($e || {}), xe = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(xe || {});
50
+ const ze = 45 * 1e3, Fe = "X-Playground-Chat", ee = "https://api.d-id.com", Ne = "wss://notifications.d-id.com", Je = "79f81a83a67430be2bc0fd61042b8faa", ge = (e) => new Promise((t) => setTimeout(t, e)), q = (e = 16) => {
51
51
  const t = new Uint8Array(e);
52
52
  return window.crypto.getRandomValues(t), Array.from(t, (n) => n.toString(16).padStart(2, "0")).join("").slice(0, 13);
53
- }, Ne = (e) => [E.TextOnly, E.Playground, E.Maintenance].includes(e), me = (e) => e && [E.DirectPlayback, E.Off].includes(e);
54
- function Je(e, t) {
53
+ }, We = (e) => [E.TextOnly, E.Playground, E.Maintenance].includes(e), he = (e) => e && [E.DirectPlayback, E.Off].includes(e);
54
+ function Ue(e, t) {
55
55
  let n;
56
56
  return {
57
57
  promise: new Promise((i, s) => {
@@ -75,16 +75,16 @@ async function ne(e, t) {
75
75
  try {
76
76
  if (!n.timeout)
77
77
  return await e();
78
- const { promise: s, clear: c } = Je(n.timeout, n.timeoutErrorMessage), a = e().finally(c);
78
+ const { promise: s, clear: c } = Ue(n.timeout, n.timeoutErrorMessage), a = e().finally(c);
79
79
  return await Promise.race([a, s]);
80
80
  } catch (s) {
81
81
  if (r = s, !n.shouldRetryFn(s) || i >= n.limit)
82
82
  throw s;
83
- await fe(n.delayMs), n.onRetry(s);
83
+ await ge(n.delayMs), n.onRetry(s);
84
84
  }
85
85
  throw r;
86
86
  }
87
- function ge() {
87
+ function we() {
88
88
  let e = window.localStorage.getItem("did_external_key_id");
89
89
  if (!e) {
90
90
  let t = q();
@@ -92,30 +92,30 @@ function ge() {
92
92
  }
93
93
  return e;
94
94
  }
95
- let We = q();
96
- function he(e) {
95
+ let Ke = q();
96
+ function pe(e) {
97
97
  if (e.type === "bearer")
98
98
  return `Bearer ${e.token}`;
99
99
  if (e.type === "basic")
100
100
  return `Basic ${btoa(`${e.username}:${e.password}`)}`;
101
101
  if (e.type === "key")
102
- return `Client-Key ${e.clientKey}.${ge()}_${We}`;
102
+ return `Client-Key ${e.clientKey}.${we()}_${Ke}`;
103
103
  throw new Error(`Unknown auth type: ${e}`);
104
104
  }
105
- const Ue = (e) => ne(e, {
105
+ const He = (e) => ne(e, {
106
106
  limit: 3,
107
107
  delayMs: 1e3,
108
108
  timeout: 0,
109
109
  shouldRetryFn: (t) => t.status === 429
110
110
  });
111
- function we(e, t = ee, n) {
111
+ function ve(e, t = ee, n) {
112
112
  const r = async (i, s) => {
113
- const { skipErrorHandler: c, ...a } = s || {}, o = await Ue(
113
+ const { skipErrorHandler: c, ...a } = s || {}, o = await He(
114
114
  () => fetch(t + (i != null && i.startsWith("/") ? i : `/${i}`), {
115
115
  ...a,
116
116
  headers: {
117
117
  ...a.headers,
118
- Authorization: he(e),
118
+ Authorization: pe(e),
119
119
  "Content-Type": "application/json"
120
120
  }
121
121
  })
@@ -142,8 +142,8 @@ function we(e, t = ee, n) {
142
142
  }
143
143
  };
144
144
  }
145
- function pe(e, t = ee, n) {
146
- const r = we(e, `${t}/agents`, n);
145
+ function ye(e, t = ee, n) {
146
+ const r = ve(e, `${t}/agents`, n);
147
147
  return {
148
148
  create(i, s) {
149
149
  return r.post("/", i, s);
@@ -180,8 +180,8 @@ function pe(e, t = ee, n) {
180
180
  }
181
181
  };
182
182
  }
183
- const ve = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Ke = (e) => e === ue.Expressive;
184
- function He(e) {
183
+ const ke = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, De = (e) => e === me.Expressive;
184
+ function Ve(e) {
185
185
  var i, s, c, a;
186
186
  const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", n = () => {
187
187
  const o = navigator.platform;
@@ -192,18 +192,18 @@ function He(e) {
192
192
  isMobile: `${t() == "Mobile"}`,
193
193
  browser: navigator.userAgent,
194
194
  origin: window.location.origin,
195
- agentType: ve(r),
195
+ agentType: ke(r),
196
196
  agentVoice: {
197
197
  voiceId: (s = (i = e.presenter) == null ? void 0 : i.voice) == null ? void 0 : s.voice_id,
198
198
  provider: (a = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : a.type
199
199
  }
200
200
  };
201
201
  }
202
- function Ve(e) {
202
+ function qe(e) {
203
203
  var n, r, i, s, c, a;
204
204
  const t = (n = e.llm) == null ? void 0 : n.prompt_customization;
205
205
  return {
206
- agentType: ve(e.presenter),
206
+ agentType: ke(e.presenter),
207
207
  owner_id: e.owner_id ?? "",
208
208
  promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
209
209
  behavior: {
@@ -222,8 +222,8 @@ function Ve(e) {
222
222
  ...e.access === "public" ? { from: "agent-template" } : {}
223
223
  };
224
224
  }
225
- const qe = (e) => e.reduce((t, n) => t + n, 0), ce = (e) => qe(e) / e.length;
226
- function Oe(e, t, n) {
225
+ const Oe = (e) => e.reduce((t, n) => t + n, 0), de = (e) => Oe(e) / e.length;
226
+ function Xe(e, t, n) {
227
227
  var o, d, l;
228
228
  const { event: r, ...i } = e, { template: s } = (t == null ? void 0 : t.llm) || {}, { language: c } = ((o = t == null ? void 0 : t.presenter) == null ? void 0 : o.voice) || {};
229
229
  return {
@@ -235,12 +235,12 @@ function Oe(e, t, n) {
235
235
  };
236
236
  }
237
237
  let re = {};
238
- const Xe = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
239
- function Ye(e) {
238
+ const Ye = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
239
+ function Qe(e) {
240
240
  const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk";
241
241
  return {
242
242
  token: e.token || "testKey",
243
- distinct_id: e.distinctId || ge(),
243
+ distinct_id: e.distinctId || we(),
244
244
  agentId: e.agentId,
245
245
  additionalProperties: {
246
246
  id: e.distinctId,
@@ -281,7 +281,7 @@ function Ye(e) {
281
281
  })
282
282
  };
283
283
  try {
284
- return await fetch(Xe, c).then((a) => a.json());
284
+ return await fetch(Ye, c).then((a) => a.json());
285
285
  } catch (a) {
286
286
  return console.error(a);
287
287
  }
@@ -302,7 +302,7 @@ function Ye(e) {
302
302
  }
303
303
  };
304
304
  }
305
- function ye() {
305
+ function Ce() {
306
306
  let e = 0;
307
307
  return {
308
308
  reset: () => e = 0,
@@ -310,13 +310,13 @@ function ye() {
310
310
  get: (t = !1) => t ? Date.now() - e : e
311
311
  };
312
312
  }
313
- const x = ye(), ae = ye();
314
- function ke(e) {
315
- return e === E.Playground ? { headers: { [xe]: "true" } } : {};
313
+ const N = Ce(), ae = Ce();
314
+ function Re(e) {
315
+ return e === E.Playground ? { headers: { [Fe]: "true" } } : {};
316
316
  }
317
- async function De(e, t, n, r, i = !1, s) {
317
+ async function ie(e, t, n, r, i = !1, s) {
318
318
  try {
319
- return !s && !me(r) && (s = await t.newChat(e.id, { persist: i }, ke(r)), n.track("agent-chat", {
319
+ return !s && !he(r) && (s = await t.newChat(e.id, { persist: i }, Re(r)), n.track("agent-chat", {
320
320
  event: "created",
321
321
  chatId: s.id,
322
322
  mode: r
@@ -332,30 +332,30 @@ async function De(e, t, n, r, i = !1, s) {
332
332
  throw new Error("Cannot create new chat");
333
333
  }
334
334
  }
335
- function Qe(e) {
335
+ function Ze(e) {
336
336
  return e && e.length > 0 ? e : [];
337
337
  }
338
- function Ze(e, t, n) {
338
+ function Ge(e, t, n) {
339
339
  if (!e)
340
340
  throw new Error("Please connect to the agent first");
341
341
  if (!e.interruptAvailable)
342
342
  throw new Error("Interrupt is not enabled for this stream");
343
- if (t !== J.Fluent)
343
+ if (t !== U.Fluent)
344
344
  throw new Error("Interrupt only available for Fluent streams");
345
345
  if (!n)
346
346
  throw new Error("No active video to interrupt");
347
347
  }
348
- async function Ge(e, t) {
348
+ async function et(e, t) {
349
349
  const n = {
350
- type: j.StreamInterrupt,
350
+ type: L.StreamInterrupt,
351
351
  videoId: t,
352
352
  timestamp: Date.now()
353
353
  };
354
354
  e.sendDataChannelMessage(JSON.stringify(n));
355
355
  }
356
- function et(e) {
356
+ function tt(e) {
357
357
  return new Promise((t, n) => {
358
- const { callbacks: r, host: i, auth: s } = e, { onMessage: c = null, onOpen: a = null, onClose: o = null, onError: d = null } = r || {}, l = new WebSocket(`${i}?authorization=${he(s)}`);
358
+ const { callbacks: r, host: i, auth: s } = e, { onMessage: c = null, onOpen: a = null, onClose: o = null, onError: d = null } = r || {}, l = new WebSocket(`${i}?authorization=${pe(s)}`);
359
359
  l.onmessage = c, l.onclose = o, l.onerror = (v) => {
360
360
  console.error(v), d == null || d("Websocket failed to connect", v), n(v);
361
361
  }, l.onopen = (v) => {
@@ -363,27 +363,27 @@ function et(e) {
363
363
  };
364
364
  });
365
365
  }
366
- async function tt(e) {
366
+ async function rt(e) {
367
367
  const { retries: t = 1 } = e;
368
368
  let n = null;
369
369
  for (let r = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; r++)
370
370
  try {
371
- n = await et(e);
371
+ n = await tt(e);
372
372
  } catch (i) {
373
373
  if (r === t)
374
374
  throw i;
375
- await fe(r * 500);
375
+ await ge(r * 500);
376
376
  }
377
377
  return n;
378
378
  }
379
- async function rt(e, t, n) {
380
- const r = n != null && n.onMessage ? [n.onMessage] : [], i = await tt({
379
+ async function nt(e, t, n) {
380
+ const r = n != null && n.onMessage ? [n.onMessage] : [], i = await rt({
381
381
  auth: e,
382
382
  host: t,
383
383
  callbacks: {
384
384
  onError: (s) => {
385
385
  var c;
386
- return (c = n.onError) == null ? void 0 : c.call(n, new Ee(s));
386
+ return (c = n.onError) == null ? void 0 : c.call(n, new _e(s));
387
387
  },
388
388
  onMessage(s) {
389
389
  const c = JSON.parse(s.data);
@@ -397,7 +397,7 @@ async function rt(e, t, n) {
397
397
  subscribeToEvents: (s) => r.push(s)
398
398
  };
399
399
  }
400
- function nt(e) {
400
+ function at(e) {
401
401
  if (e.answer !== void 0)
402
402
  return e.answer;
403
403
  let t = 0, n = "";
@@ -405,41 +405,41 @@ function nt(e) {
405
405
  n += e[t++];
406
406
  return n;
407
407
  }
408
- function at(e, t, n, r, i) {
408
+ function it(e, t, n, r, i) {
409
409
  const s = r.messages[r.messages.length - 1];
410
410
  if (!(e === V.Partial || e === V.Answer) || (s == null ? void 0 : s.role) !== "assistant")
411
411
  return;
412
412
  const { content: c, sequence: a } = t;
413
413
  e === V.Partial ? n[a] = c : n.answer = c;
414
- const o = nt(n);
414
+ const o = at(n);
415
415
  (s.content !== o || e === V.Answer) && (s.content = o, i == null || i([...r.messages], e));
416
416
  }
417
- function it(e, t, n, r, i) {
417
+ function st(e, t, n, r, i) {
418
418
  let s = {};
419
419
  return {
420
420
  clearQueue: () => s = {},
421
421
  onMessage: (c, a) => {
422
422
  var o, d;
423
423
  if ("content" in a)
424
- at(c, a, s, t, n.callbacks.onNewMessage), c === V.Answer && e.track("agent-message-received", {
424
+ it(c, a, s, t, n.callbacks.onNewMessage), c === V.Answer && e.track("agent-message-received", {
425
425
  messages: t.messages.length,
426
426
  mode: t.chatMode
427
427
  });
428
428
  else {
429
- const l = j, v = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], M = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], b = Oe(a, r, { mode: t.chatMode });
429
+ const l = L, v = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], M = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], A = Xe(a, r, { mode: t.chatMode });
430
430
  if (c = c, c === l.StreamVideoCreated)
431
- e.linkTrack("agent-video", b, l.StreamVideoCreated, ["start"]);
431
+ e.linkTrack("agent-video", A, l.StreamVideoCreated, ["start"]);
432
432
  else if (v.includes(c)) {
433
- const B = c.split("/")[1];
434
- M.includes(c) ? e.track("agent-video", { ...b, event: B }) : e.linkTrack("agent-video", { ...b, event: B }, c, ["done"]);
433
+ const b = c.split("/")[1];
434
+ M.includes(c) ? e.track("agent-video", { ...A, event: b }) : e.linkTrack("agent-video", { ...A, event: b }, c, ["done"]);
435
435
  }
436
436
  M.includes(c) && ((d = (o = n.callbacks).onError) == null || d.call(o, new Error(`Stream failed with event ${c}`), { data: a })), a.event === l.StreamDone && i();
437
437
  }
438
438
  }
439
439
  };
440
440
  }
441
- function st(e, t, n, r) {
442
- const i = we(e, `${t}/agents/${n}`, r);
441
+ function ot(e, t, n, r) {
442
+ const i = ve(e, `${t}/agents/${n}`, r);
443
443
  return {
444
444
  createStream(s) {
445
445
  return i.post("/streams", s);
@@ -467,8 +467,8 @@ function st(e, t, n, r) {
467
467
  }
468
468
  };
469
469
  }
470
- const ot = (e, t) => (n, r) => e && console.log(`[${t}] ${n}`, r ?? "");
471
- function ct(e, t, n) {
470
+ const ct = (e, t) => (n, r) => e && console.log(`[${t}] ${n}`, r ?? "");
471
+ function dt(e, t, n) {
472
472
  const r = (t.timestamp - e.timestamp) / 1e3;
473
473
  return {
474
474
  duration: r,
@@ -488,7 +488,7 @@ function ct(e, t, n) {
488
488
  lowFpsCount: n
489
489
  };
490
490
  }
491
- function dt(e) {
491
+ function lt(e) {
492
492
  return e.filter(
493
493
  (t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
494
494
  ).map((t) => {
@@ -499,7 +499,7 @@ function dt(e) {
499
499
  };
500
500
  });
501
501
  }
502
- function lt(e) {
502
+ function ut(e) {
503
503
  let t = "", n = 0;
504
504
  for (const r of e.values())
505
505
  if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair" && (n = r.currentRoundTripTime), r && r.type === "inbound-rtp" && r.kind === "video")
@@ -524,7 +524,7 @@ function lt(e) {
524
524
  };
525
525
  return {};
526
526
  }
527
- function ut(e, t, n) {
527
+ function ft(e, t, n) {
528
528
  const r = e.map((o, d) => d === 0 ? n ? {
529
529
  timestamp: o.timestamp,
530
530
  duration: 0,
@@ -576,24 +576,24 @@ function ut(e, t, n) {
576
576
  framesPerSecond: o.framesPerSecond,
577
577
  freezeCount: o.freezeCount - e[d - 1].freezeCount,
578
578
  freezeDuration: o.freezeDuration - e[d - 1].freezeDuration
579
- }), i = dt(r), s = i.reduce((o, d) => o + (d.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((o) => !!o.avgJitterDelayInInterval).map((o) => o.avgJitterDelayInInterval), a = r.filter((o) => !!o.rtt).map((o) => o.rtt);
579
+ }), i = lt(r), s = i.reduce((o, d) => o + (d.causes.includes("low fps") ? 1 : 0), 0), c = r.filter((o) => !!o.avgJitterDelayInInterval).map((o) => o.avgJitterDelayInInterval), a = r.filter((o) => !!o.rtt).map((o) => o.rtt);
580
580
  return {
581
581
  webRTCStats: {
582
582
  anomalies: i,
583
583
  minRtt: Math.min(...a),
584
- avgRtt: ce(a),
584
+ avgRtt: de(a),
585
585
  maxRtt: Math.max(...a),
586
- aggregateReport: ct(e[0], e[e.length - 1], s),
586
+ aggregateReport: dt(e[0], e[e.length - 1], s),
587
587
  minJitterDelayInInterval: Math.min(...c),
588
588
  maxJitterDelayInInterval: Math.max(...c),
589
- avgJitterDelayInInterval: ce(c)
589
+ avgJitterDelayInInterval: de(c)
590
590
  },
591
591
  codec: e[0].codec,
592
592
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
593
593
  };
594
594
  }
595
- const ie = 100, ft = Math.max(Math.ceil(400 / ie), 1), mt = 0.25, gt = 0.28;
596
- function ht() {
595
+ const se = 100, mt = Math.max(Math.ceil(400 / se), 1), gt = 0.25, ht = 0.28;
596
+ function wt() {
597
597
  let e = 0, t, n, r = 0;
598
598
  return (i) => {
599
599
  for (const s of i.values())
@@ -610,21 +610,21 @@ function ht() {
610
610
  return { isReceiving: !1, avgJitterDelayInInterval: r };
611
611
  };
612
612
  }
613
- function wt(e, t, n, r, i, s = !1) {
614
- let c = [], a, o = 0, d = !1, l = G.Unknown, v = G.Unknown, M = 0, b = 0;
615
- const B = ht();
613
+ function pt(e, t, n, r, i, s = !1) {
614
+ let c = [], a, o = 0, d = !1, l = G.Unknown, v = G.Unknown, M = 0, A = 0;
615
+ const b = wt();
616
616
  return setInterval(async () => {
617
- const z = await e.getStats(), { isReceiving: U, avgJitterDelayInInterval: W, freezeCount: C } = B(z), K = lt(z);
618
- if (U)
619
- o = 0, M = C - b, v = W < mt ? G.Strong : W > gt && M > 1 ? G.Weak : l, v !== l && (i == null || i(v), l = v, b += M, M = 0), d || (r == null || r(w.Start), a = c[c.length - 1], c = [], d = !0), c.push(K);
620
- else if (d && (o++, o >= ft)) {
621
- const u = ut(c, ie, a);
622
- r == null || r(w.Stop, u), t() || n(), b = C, d = !1;
617
+ const j = await e.getStats(), { isReceiving: B, avgJitterDelayInInterval: z, freezeCount: y } = b(j), K = ut(j);
618
+ if (B)
619
+ o = 0, M = y - A, v = z < gt ? G.Strong : z > ht && M > 1 ? G.Weak : l, v !== l && (i == null || i(v), l = v, A += M, M = 0), d || (r == null || r(w.Start), a = c[c.length - 1], c = [], d = !0), c.push(K);
620
+ else if (d && (o++, o >= mt)) {
621
+ const u = ft(c, se, a);
622
+ r == null || r(w.Stop, u), t() || n(), A = y, d = !1;
623
623
  }
624
- }, ie);
624
+ }, se);
625
625
  }
626
- const pt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
627
- function de(e) {
626
+ const vt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
627
+ function le(e) {
628
628
  switch (e) {
629
629
  case "connected":
630
630
  return R.Connected;
@@ -644,7 +644,7 @@ function de(e) {
644
644
  return R.New;
645
645
  }
646
646
  }
647
- const vt = (e) => (t) => {
647
+ const yt = (e) => (t) => {
648
648
  const [n, r = ""] = t.split(/:(.+)/);
649
649
  try {
650
650
  const i = JSON.parse(r);
@@ -653,7 +653,7 @@ const vt = (e) => (t) => {
653
653
  return e("Failed to parse data channel message, returning data as string", { subject: n, rawData: r, error: i }), { subject: n, data: r };
654
654
  }
655
655
  };
656
- function yt({
656
+ function kt({
657
657
  statsSignal: e,
658
658
  dataChannelSignal: t,
659
659
  onVideoStateChange: n,
@@ -661,7 +661,7 @@ function yt({
661
661
  }) {
662
662
  e === w.Start && t === w.Start ? n == null || n(w.Start) : e === w.Stop && t === w.Stop && (n == null || n(w.Stop, r));
663
663
  }
664
- function kt({
664
+ function Dt({
665
665
  statsSignal: e,
666
666
  dataChannelSignal: t,
667
667
  onVideoStateChange: n,
@@ -670,7 +670,7 @@ function kt({
670
670
  }) {
671
671
  e === w.Start ? n == null || n(w.Start) : e === w.Stop && (n == null || n(w.Stop, i)), t === w.Start ? r == null || r(O.Talking) : t === w.Stop && (r == null || r(O.Idle));
672
672
  }
673
- function le({
673
+ function ue({
674
674
  statsSignal: e,
675
675
  dataChannelSignal: t,
676
676
  onVideoStateChange: n,
@@ -678,7 +678,7 @@ function le({
678
678
  streamType: i,
679
679
  report: s
680
680
  }) {
681
- i === J.Legacy ? yt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: n, report: s }) : i === J.Fluent && kt({
681
+ i === U.Legacy ? kt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: n, report: s }) : i === U.Fluent && Dt({
682
682
  statsSignal: e,
683
683
  dataChannelSignal: t,
684
684
  onVideoStateChange: n,
@@ -686,42 +686,42 @@ function le({
686
686
  report: s
687
687
  });
688
688
  }
689
- async function Dt(e, t, { debug: n = !1, callbacks: r, auth: i, baseURL: s = ee, analytics: c }) {
689
+ async function Ct(e, t, { debug: n = !1, callbacks: r, auth: i, baseURL: s = ee, analytics: c }) {
690
690
  var Y;
691
- const a = ot(n, "WebRTCStreamingManager"), o = vt(a);
691
+ const a = ct(n, "WebRTCStreamingManager"), o = yt(a);
692
692
  let d = !1, l = !1, v = w.Stop, M = w.Stop;
693
- const { startConnection: b, sendStreamRequest: B, close: z, createStream: U, addIceCandidate: W } = st(
693
+ const { startConnection: A, sendStreamRequest: b, close: j, createStream: B, addIceCandidate: z } = ot(
694
694
  i,
695
695
  s,
696
696
  e,
697
697
  r.onError
698
698
  ), {
699
- id: C,
699
+ id: y,
700
700
  offer: K,
701
701
  ice_servers: u,
702
702
  session_id: h,
703
703
  fluent: p,
704
704
  interrupt_enabled: _,
705
- triggers_enabled: y
706
- } = await U(t);
707
- (Y = r.onStreamCreated) == null || Y.call(r, { stream_id: C, session_id: h, agent_id: e });
708
- const f = new pt({ iceServers: u }), S = f.createDataChannel("JanusDataChannel");
705
+ triggers_enabled: k
706
+ } = await B(t);
707
+ (Y = r.onStreamCreated) == null || Y.call(r, { stream_id: y, session_id: h, agent_id: e });
708
+ const f = new vt({ iceServers: u }), S = f.createDataChannel("JanusDataChannel");
709
709
  if (!h)
710
710
  throw new Error("Could not create session_id");
711
- const T = p ? J.Fluent : J.Legacy;
711
+ const T = p ? U.Fluent : U.Legacy;
712
712
  c.enrich({
713
713
  "stream-type": T
714
714
  });
715
- const P = t.stream_warmup && !p, D = () => d, I = () => {
715
+ const $ = t.stream_warmup && !p, C = () => d, I = () => {
716
716
  var m;
717
717
  d = !0, l && ((m = r.onConnectionStateChange) == null || m.call(r, R.Connected));
718
- }, k = wt(
718
+ }, D = pt(
719
719
  f,
720
- D,
720
+ C,
721
721
  I,
722
- (m, g) => le({
722
+ (m, g) => ue({
723
723
  statsSignal: M = m,
724
- dataChannelSignal: T === J.Legacy ? v : void 0,
724
+ dataChannelSignal: T === U.Legacy ? v : void 0,
725
725
  onVideoStateChange: r.onVideoStateChange,
726
726
  onAgentActivityStateChange: r.onAgentActivityStateChange,
727
727
  report: g,
@@ -731,113 +731,113 @@ async function Dt(e, t, { debug: n = !1, callbacks: r, auth: i, baseURL: s = ee,
731
731
  var g;
732
732
  return (g = r.onConnectivityStateChange) == null ? void 0 : g.call(r, m);
733
733
  },
734
- P
734
+ $
735
735
  );
736
736
  f.onicecandidate = (m) => {
737
737
  var g;
738
738
  a("peerConnection.onicecandidate", m);
739
739
  try {
740
- m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? W(
741
- C,
740
+ m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? z(
741
+ y,
742
742
  {
743
743
  candidate: m.candidate.candidate,
744
744
  sdpMid: m.candidate.sdpMid,
745
745
  sdpMLineIndex: m.candidate.sdpMLineIndex
746
746
  },
747
747
  h
748
- ) : W(C, { candidate: null }, h);
749
- } catch (A) {
750
- (g = r.onError) == null || g.call(r, A, { streamId: C });
748
+ ) : z(y, { candidate: null }, h);
749
+ } catch (P) {
750
+ (g = r.onError) == null || g.call(r, P, { streamId: y });
751
751
  }
752
752
  }, S.onopen = () => {
753
- l = !0, (!P || d) && I();
753
+ l = !0, (!$ || d) && I();
754
754
  };
755
- const $ = (m) => {
755
+ const F = (m) => {
756
756
  var g;
757
757
  (g = r.onVideoIdChange) == null || g.call(r, m);
758
758
  };
759
- function L(m, g) {
760
- if (m === j.StreamStarted && typeof g == "object" && "metadata" in g) {
761
- const A = g.metadata;
762
- $(A.videoId);
759
+ function x(m, g) {
760
+ if (m === L.StreamStarted && typeof g == "object" && "metadata" in g) {
761
+ const P = g.metadata;
762
+ F(P.videoId);
763
763
  }
764
- m === j.StreamDone && $(null), v = m === j.StreamStarted ? w.Start : w.Stop, le({
765
- statsSignal: T === J.Legacy ? M : void 0,
764
+ m === L.StreamDone && F(null), v = m === L.StreamStarted ? w.Start : w.Stop, ue({
765
+ statsSignal: T === U.Legacy ? M : void 0,
766
766
  dataChannelSignal: v,
767
767
  onVideoStateChange: r.onVideoStateChange,
768
768
  onAgentActivityStateChange: r.onAgentActivityStateChange,
769
769
  streamType: T
770
770
  });
771
771
  }
772
- function F(m, g) {
773
- const A = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
774
- A && c.enrich({ streamMetadata: A }), c.track("agent-chat", { event: "ready" });
772
+ function J(m, g) {
773
+ const P = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
774
+ P && c.enrich({ streamMetadata: P }), c.track("agent-chat", { event: "ready" });
775
775
  }
776
- const N = {
777
- [j.StreamStarted]: L,
778
- [j.StreamDone]: L,
779
- [j.StreamReady]: F
776
+ const W = {
777
+ [L.StreamStarted]: x,
778
+ [L.StreamDone]: x,
779
+ [L.StreamReady]: J
780
780
  };
781
781
  S.onmessage = (m) => {
782
782
  var Q;
783
- const { subject: g, data: A } = o(m.data);
784
- (Q = N[g]) == null || Q.call(N, g, A);
783
+ const { subject: g, data: P } = o(m.data);
784
+ (Q = W[g]) == null || Q.call(W, g, P);
785
785
  }, f.oniceconnectionstatechange = () => {
786
786
  var g;
787
787
  a("peerConnection.oniceconnectionstatechange => " + f.iceConnectionState);
788
- const m = de(f.iceConnectionState);
788
+ const m = le(f.iceConnectionState);
789
789
  m !== R.Connected && ((g = r.onConnectionStateChange) == null || g.call(r, m));
790
790
  }, f.ontrack = (m) => {
791
791
  var g;
792
792
  a("peerConnection.ontrack", m), (g = r.onSrcObjectReady) == null || g.call(r, m.streams[0]);
793
793
  }, await f.setRemoteDescription(K), a("set remote description OK");
794
794
  const X = await f.createAnswer();
795
- return a("create answer OK"), await f.setLocalDescription(X), a("set local description OK"), await b(C, X, h), a("start connection OK"), {
795
+ return a("create answer OK"), await f.setLocalDescription(X), a("set local description OK"), await A(y, X, h), a("start connection OK"), {
796
796
  /**
797
797
  * Method to send request to server to get clip or talk depend on you payload
798
798
  * @param payload
799
799
  */
800
800
  speak(m) {
801
- return B(C, h, m);
801
+ return b(y, h, m);
802
802
  },
803
803
  /**
804
804
  * Method to close RTC connection
805
805
  */
806
806
  async disconnect() {
807
807
  var m;
808
- if (C) {
809
- const g = de(f.iceConnectionState);
808
+ if (y) {
809
+ const g = le(f.iceConnectionState);
810
810
  if (f) {
811
811
  if (g === R.New) {
812
- clearInterval(k);
812
+ clearInterval(D);
813
813
  return;
814
814
  }
815
815
  f.close(), f.oniceconnectionstatechange = null, f.onnegotiationneeded = null, f.onicecandidate = null, f.ontrack = null;
816
816
  }
817
817
  try {
818
- g === R.Connected && await z(C, h).catch((A) => {
818
+ g === R.Connected && await j(y, h).catch((P) => {
819
819
  });
820
- } catch (A) {
821
- a("Error on close stream connection", A);
820
+ } catch (P) {
821
+ a("Error on close stream connection", P);
822
822
  }
823
- (m = r.onAgentActivityStateChange) == null || m.call(r, O.Idle), clearInterval(k);
823
+ (m = r.onAgentActivityStateChange) == null || m.call(r, O.Idle), clearInterval(D);
824
824
  }
825
825
  },
826
826
  /**
827
827
  * Method to send data channel messages to the server
828
828
  */
829
829
  sendDataChannelMessage(m) {
830
- var g, A;
830
+ var g, P;
831
831
  if (!d || S.readyState !== "open") {
832
832
  a("Data channel is not ready for sending messages"), (g = r.onError) == null || g.call(r, new Error("Data channel is not ready for sending messages"), {
833
- streamId: C
833
+ streamId: y
834
834
  });
835
835
  return;
836
836
  }
837
837
  try {
838
838
  S.send(m);
839
839
  } catch (Q) {
840
- a("Error sending data channel message", Q), (A = r.onError) == null || A.call(r, Q, { streamId: C });
840
+ a("Error sending data channel message", Q), (P = r.onError) == null || P.call(r, Q, { streamId: y });
841
841
  }
842
842
  },
843
843
  /**
@@ -847,25 +847,25 @@ async function Dt(e, t, { debug: n = !1, callbacks: r, auth: i, baseURL: s = ee,
847
847
  /**
848
848
  * Id of current RTC stream
849
849
  */
850
- streamId: C,
850
+ streamId: y,
851
851
  streamType: T,
852
852
  interruptAvailable: _ ?? !1,
853
- triggersAvailable: y ?? !1
853
+ triggersAvailable: k ?? !1
854
854
  };
855
855
  }
856
- var se = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(se || {});
857
- async function Ct(e, t, n) {
856
+ var oe = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(oe || {});
857
+ async function Rt(e, t, n) {
858
858
  const r = e.id;
859
859
  switch (t.version) {
860
860
  case "v1": {
861
861
  const { version: i, ...s } = t;
862
- return Dt(r, s, n);
862
+ return Ct(r, s, n);
863
863
  }
864
864
  case "v2": {
865
865
  const { version: i, ...s } = t;
866
866
  switch (s.transport_provider) {
867
- case oe.Livekit:
868
- const { createLiveKitStreamingManager: c } = await import("./livekit-manager-D5uOirhd.js");
867
+ case ce.Livekit:
868
+ const { createLiveKitStreamingManager: c } = await import("./livekit-manager-tsiAM1XU.js");
869
869
  return c(r, s, n);
870
870
  default:
871
871
  throw new Error(`Unsupported transport provider: ${s.transport_provider}`);
@@ -875,13 +875,13 @@ async function Ct(e, t, n) {
875
875
  throw new Error(`Invalid stream version: ${t.version}`);
876
876
  }
877
877
  }
878
- function Rt(e) {
878
+ function St(e) {
879
879
  return {
880
- transport_provider: oe.Livekit,
880
+ transport_provider: ce.Livekit,
881
881
  chat_id: e == null ? void 0 : e.chatId
882
882
  };
883
883
  }
884
- function St(e) {
884
+ function It(e) {
885
885
  var i, s, c;
886
886
  const { streamOptions: t } = e ?? {}, n = e != null && e.distinctId || ((i = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : i.plan) !== void 0 ? {
887
887
  ...e != null && e.distinctId ? { distinct_id: e.distinctId } : {},
@@ -895,13 +895,13 @@ function St(e) {
895
895
  fluent: t == null ? void 0 : t.fluent
896
896
  }, ...n && { end_user_data: n } };
897
897
  }
898
- function It(e, t) {
899
- return Ke(e.presenter.type) ? { version: se.V2, ...Rt(t) } : { version: se.V1, ...St(t) };
900
- }
901
- function Et(e, t, n, r, i) {
902
- i === J.Fluent ? Mt(e, t, n, r, i) : Tt(e, t, n, r, i);
898
+ function Et(e, t) {
899
+ return De(e.presenter.type) ? { version: oe.V2, ...St(t) } : { version: oe.V1, ...It(t) };
903
900
  }
904
901
  function Mt(e, t, n, r, i) {
902
+ i === U.Fluent ? _t(e, t, n, r, i) : At(e, t, n, r, i);
903
+ }
904
+ function _t(e, t, n, r, i) {
905
905
  e === w.Start ? r.track("stream-session", { event: "start", "stream-type": i }) : e === w.Stop && r.track("stream-session", {
906
906
  event: "stop",
907
907
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
@@ -910,12 +910,12 @@ function Mt(e, t, n, r, i) {
910
910
  ...n
911
911
  });
912
912
  }
913
- function _t(e, t, n, r) {
914
- x.get() <= 0 || (e === w.Start ? n.linkTrack(
913
+ function Tt(e, t, n, r) {
914
+ N.get() <= 0 || (e === w.Start ? n.linkTrack(
915
915
  "agent-video",
916
- { event: "start", latency: x.get(!0), "stream-type": r },
916
+ { event: "start", latency: N.get(!0), "stream-type": r },
917
917
  "start",
918
- [j.StreamVideoCreated]
918
+ [L.StreamVideoCreated]
919
919
  ) : e === w.Stop && n.linkTrack(
920
920
  "agent-video",
921
921
  {
@@ -925,15 +925,15 @@ function _t(e, t, n, r) {
925
925
  "stream-type": r
926
926
  },
927
927
  "done",
928
- [j.StreamVideoDone]
928
+ [L.StreamVideoDone]
929
929
  ));
930
930
  }
931
- function Tt(e, t, n, r, i) {
932
- x.get() <= 0 || (e === w.Start ? r.linkTrack(
931
+ function At(e, t, n, r, i) {
932
+ N.get() <= 0 || (e === w.Start ? r.linkTrack(
933
933
  "agent-video",
934
- { event: "start", latency: x.get(!0), "stream-type": i },
934
+ { event: "start", latency: N.get(!0), "stream-type": i },
935
935
  "start",
936
- [j.StreamVideoCreated]
936
+ [L.StreamVideoCreated]
937
937
  ) : e === w.Stop && r.linkTrack(
938
938
  "agent-video",
939
939
  {
@@ -944,14 +944,14 @@ function Tt(e, t, n, r, i) {
944
944
  ...n
945
945
  },
946
946
  "done",
947
- [j.StreamVideoDone]
947
+ [L.StreamVideoDone]
948
948
  ));
949
949
  }
950
- function At(e, t, n) {
951
- return x.reset(), new Promise(async (r, i) => {
950
+ function fe(e, t, n) {
951
+ return N.reset(), new Promise(async (r, i) => {
952
952
  try {
953
953
  let s;
954
- s = await Ct(e, It(e, t), {
954
+ s = await Rt(e, Et(e, t), {
955
955
  ...t,
956
956
  analytics: n,
957
957
  callbacks: {
@@ -962,7 +962,7 @@ function At(e, t, n) {
962
962
  },
963
963
  onVideoStateChange: (c, a) => {
964
964
  var o, d;
965
- (d = (o = t.callbacks).onVideoStateChange) == null || d.call(o, c), Et(
965
+ (d = (o = t.callbacks).onVideoStateChange) == null || d.call(o, c), Mt(
966
966
  c,
967
967
  e,
968
968
  a,
@@ -972,7 +972,7 @@ function At(e, t, n) {
972
972
  },
973
973
  onAgentActivityStateChange: (c) => {
974
974
  var a, o;
975
- (o = (a = t.callbacks).onAgentActivityStateChange) == null || o.call(a, c), c === O.Talking ? ae.update() : ae.reset(), _t(
975
+ (o = (a = t.callbacks).onAgentActivityStateChange) == null || o.call(a, c), c === O.Talking ? ae.update() : ae.reset(), Tt(
976
976
  c === O.Talking ? w.Start : w.Stop,
977
977
  e,
978
978
  n,
@@ -987,17 +987,44 @@ function At(e, t, n) {
987
987
  });
988
988
  }
989
989
  async function jt(e, t, n, r, i) {
990
- var d, l, v, M;
991
- const s = await De(e, n, r, t.mode, t.persistentChat, i), { chat: c, chatMode: a } = s, o = await At(e, { ...t, chatId: c == null ? void 0 : c.id }, r);
992
- return a && a !== t.mode && (t.mode = a, (l = (d = t.callbacks).onModeChange) == null || l.call(d, a), a !== E.Functional) ? ((M = (v = t.callbacks).onError) == null || M.call(v, new Ie(a)), o == null || o.disconnect(), { chat: c }) : { chat: c, streamingManager: o };
990
+ var l, v, M, A;
991
+ const s = async () => {
992
+ var b;
993
+ if (De(e.presenter.type)) {
994
+ const j = await ie(
995
+ e,
996
+ n,
997
+ r,
998
+ t.mode,
999
+ t.persistentChat,
1000
+ i
1001
+ ), B = await fe(
1002
+ e,
1003
+ { ...t, chatId: (b = j.chat) == null ? void 0 : b.id },
1004
+ r
1005
+ );
1006
+ return { chatResult: j, streamingManager: B };
1007
+ } else {
1008
+ const j = ie(
1009
+ e,
1010
+ n,
1011
+ r,
1012
+ t.mode,
1013
+ t.persistentChat,
1014
+ i
1015
+ ), B = fe(e, t, r), [z, y] = await Promise.all([j, B]);
1016
+ return { chatResult: z, streamingManager: y };
1017
+ }
1018
+ }, { chatResult: c, streamingManager: a } = await s(), { chat: o, chatMode: d } = c;
1019
+ return d && d !== t.mode && (t.mode = d, (v = (l = t.callbacks).onModeChange) == null || v.call(l, d), d !== E.Functional) ? ((A = (M = t.callbacks).onError) == null || A.call(M, new Me(d)), a == null || a.disconnect(), { chat: o }) : { chat: o, streamingManager: a };
993
1020
  }
994
1021
  async function Lt(e, t) {
995
- var W, C, K;
1022
+ var z, y, K;
996
1023
  let n = !0, r = null;
997
- const i = t.mixpanelKey || Fe, s = t.wsURL || ze, c = t.baseURL || ee, a = {
1024
+ const i = t.mixpanelKey || Je, s = t.wsURL || Ne, c = t.baseURL || ee, a = {
998
1025
  messages: [],
999
1026
  chatMode: t.mode || E.Functional
1000
- }, o = Ye({
1027
+ }, o = Qe({
1001
1028
  token: i,
1002
1029
  agentId: e,
1003
1030
  isEnabled: t.enableAnalitics,
@@ -1005,9 +1032,9 @@ async function Lt(e, t) {
1005
1032
  mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
1006
1033
  });
1007
1034
  o.track("agent-sdk", { event: "init" });
1008
- const d = pe(t.auth, c, t.callbacks.onError), l = await d.getById(e);
1009
- o.enrich(Ve(l));
1010
- const { onMessage: v, clearQueue: M } = it(
1035
+ const d = ye(t.auth, c, t.callbacks.onError), l = await d.getById(e);
1036
+ o.enrich(qe(l));
1037
+ const { onMessage: v, clearQueue: M } = st(
1011
1038
  o,
1012
1039
  a,
1013
1040
  t,
@@ -1017,47 +1044,47 @@ async function Lt(e, t) {
1017
1044
  return (u = a.socketManager) == null ? void 0 : u.disconnect();
1018
1045
  }
1019
1046
  );
1020
- a.messages = Qe(t.initialMessages), (C = (W = t.callbacks).onNewMessage) == null || C.call(W, [...a.messages], "answer");
1021
- const b = (u) => {
1047
+ a.messages = Ze(t.initialMessages), (y = (z = t.callbacks).onNewMessage) == null || y.call(z, [...a.messages], "answer");
1048
+ const A = (u) => {
1022
1049
  r = u;
1023
1050
  };
1024
- o.track("agent-sdk", { event: "loaded", ...He(l) });
1025
- async function B(u) {
1026
- var S, T, P, D, I, k, $;
1027
- (T = (S = t.callbacks).onConnectionStateChange) == null || T.call(S, R.Connecting), x.reset(), u && !n && (delete a.chat, (D = (P = t.callbacks).onNewMessage) == null || D.call(P, [...a.messages], "answer"));
1028
- const h = t.mode === E.DirectPlayback ? Promise.resolve(void 0) : rt(t.auth, s, { onMessage: v, onError: t.callbacks.onError }), p = ne(
1051
+ o.track("agent-sdk", { event: "loaded", ...Ve(l) });
1052
+ async function b(u) {
1053
+ var S, T, $, C, I, D, F;
1054
+ (T = (S = t.callbacks).onConnectionStateChange) == null || T.call(S, R.Connecting), N.reset(), u && !n && (delete a.chat, (C = ($ = t.callbacks).onNewMessage) == null || C.call($, [...a.messages], "answer"));
1055
+ const h = t.mode === E.DirectPlayback ? Promise.resolve(void 0) : nt(t.auth, s, { onMessage: v, onError: t.callbacks.onError }), p = ne(
1029
1056
  () => jt(
1030
1057
  l,
1031
- { ...t, callbacks: { ...t.callbacks, onVideoIdChange: b } },
1058
+ { ...t, callbacks: { ...t.callbacks, onVideoIdChange: A } },
1032
1059
  d,
1033
1060
  o,
1034
1061
  a.chat
1035
1062
  ),
1036
1063
  {
1037
1064
  limit: 3,
1038
- timeout: $e,
1065
+ timeout: ze,
1039
1066
  timeoutErrorMessage: "Timeout initializing the stream",
1040
1067
  // Retry on all errors except for connection errors and rate limit errors, these are already handled in client level.
1041
- shouldRetryFn: (L) => (L == null ? void 0 : L.message) !== "Could not connect" && L.status !== 429,
1068
+ shouldRetryFn: (x) => (x == null ? void 0 : x.message) !== "Could not connect" && x.status !== 429,
1042
1069
  delayMs: 1e3
1043
1070
  }
1044
- ).catch((L) => {
1045
- var F, N;
1046
- throw U(E.Maintenance), (N = (F = t.callbacks).onConnectionStateChange) == null || N.call(F, R.Fail), L;
1047
- }), [_, { streamingManager: y, chat: f }] = await Promise.all([h, p]);
1048
- f && f.id !== ((I = a.chat) == null ? void 0 : I.id) && (($ = (k = t.callbacks).onNewChat) == null || $.call(k, f.id)), a.streamingManager = y, a.socketManager = _, a.chat = f, n = !1, o.enrich({
1071
+ ).catch((x) => {
1072
+ var J, W;
1073
+ throw B(E.Maintenance), (W = (J = t.callbacks).onConnectionStateChange) == null || W.call(J, R.Fail), x;
1074
+ }), [_, { streamingManager: k, chat: f }] = await Promise.all([h, p]);
1075
+ f && f.id !== ((I = a.chat) == null ? void 0 : I.id) && ((F = (D = t.callbacks).onNewChat) == null || F.call(D, f.id)), a.streamingManager = k, a.socketManager = _, a.chat = f, n = !1, o.enrich({
1049
1076
  chatId: f == null ? void 0 : f.id,
1050
- streamId: y == null ? void 0 : y.streamId,
1077
+ streamId: k == null ? void 0 : k.streamId,
1051
1078
  mode: a.chatMode
1052
- }), U((f == null ? void 0 : f.chat_mode) ?? t.mode ?? E.Functional);
1079
+ }), B((f == null ? void 0 : f.chat_mode) ?? t.mode ?? E.Functional);
1053
1080
  }
1054
- async function z() {
1081
+ async function j() {
1055
1082
  var u, h, p, _;
1056
1083
  (u = a.socketManager) == null || u.disconnect(), await ((h = a.streamingManager) == null ? void 0 : h.disconnect()), delete a.streamingManager, delete a.socketManager, (_ = (p = t.callbacks).onConnectionStateChange) == null || _.call(p, R.Disconnected);
1057
1084
  }
1058
- async function U(u) {
1085
+ async function B(u) {
1059
1086
  var h, p;
1060
- u !== a.chatMode && (o.track("agent-mode-change", { mode: u }), a.chatMode = u, a.chatMode !== E.Functional && await z(), (p = (h = t.callbacks).onModeChange) == null || p.call(h, u));
1087
+ u !== a.chatMode && (o.track("agent-mode-change", { mode: u }), a.chatMode = u, a.chatMode !== E.Functional && await j(), (p = (h = t.callbacks).onModeChange) == null || p.call(h, u));
1061
1088
  }
1062
1089
  return {
1063
1090
  agent: l,
@@ -1075,30 +1102,30 @@ async function Lt(e, t) {
1075
1102
  },
1076
1103
  starterMessages: ((K = l.knowledge) == null ? void 0 : K.starter_message) || [],
1077
1104
  getSTTToken: () => d.getSTTToken(l.id),
1078
- changeMode: U,
1105
+ changeMode: B,
1079
1106
  enrichAnalytics: o.enrich,
1080
1107
  async connect() {
1081
- await B(!0), o.track("agent-chat", {
1108
+ await b(!0), o.track("agent-chat", {
1082
1109
  event: "connect",
1083
1110
  mode: a.chatMode
1084
1111
  });
1085
1112
  },
1086
1113
  async reconnect() {
1087
- await z(), await B(!1), o.track("agent-chat", {
1114
+ await j(), await b(!1), o.track("agent-chat", {
1088
1115
  event: "reconnect",
1089
1116
  mode: a.chatMode
1090
1117
  });
1091
1118
  },
1092
1119
  async disconnect() {
1093
- await z(), o.track("agent-chat", {
1120
+ await j(), o.track("agent-chat", {
1094
1121
  event: "disconnect",
1095
1122
  mode: a.chatMode
1096
1123
  });
1097
1124
  },
1098
1125
  async chat(u) {
1099
- var y, f, S, T, P;
1126
+ var k, f, S, T, $;
1100
1127
  const h = () => {
1101
- if (me(t.mode))
1128
+ if (he(t.mode))
1102
1129
  throw new H(`${t.mode} is enabled, chat is disabled`);
1103
1130
  if (u.length >= 800)
1104
1131
  throw new H("Message cannot be more than 800 characters");
@@ -1113,47 +1140,47 @@ async function Lt(e, t) {
1113
1140
  throw new H("Chat is not initialized");
1114
1141
  }
1115
1142
  }, p = async () => {
1116
- var D, I;
1143
+ var C, I;
1117
1144
  if (!a.chat) {
1118
- const k = await De(
1145
+ const D = await ie(
1119
1146
  l,
1120
1147
  d,
1121
1148
  o,
1122
1149
  a.chatMode,
1123
1150
  t.persistentChat
1124
1151
  );
1125
- if (!k.chat)
1126
- throw new Se(a.chatMode, !!t.persistentChat);
1127
- a.chat = k.chat, (I = (D = t.callbacks).onNewChat) == null || I.call(D, a.chat.id);
1152
+ if (!D.chat)
1153
+ throw new Ee(a.chatMode, !!t.persistentChat);
1154
+ a.chat = D.chat, (I = (C = t.callbacks).onNewChat) == null || I.call(C, a.chat.id);
1128
1155
  }
1129
1156
  return a.chat.id;
1130
- }, _ = async (D, I) => ne(
1157
+ }, _ = async (C, I) => ne(
1131
1158
  () => {
1132
- var k, $;
1159
+ var D, F;
1133
1160
  return d.chat(
1134
1161
  l.id,
1135
1162
  I,
1136
1163
  {
1137
1164
  chatMode: a.chatMode,
1138
- streamId: (k = a.streamingManager) == null ? void 0 : k.streamId,
1139
- sessionId: ($ = a.streamingManager) == null ? void 0 : $.sessionId,
1140
- messages: D.map(({ matches: L, ...F }) => F)
1165
+ streamId: (D = a.streamingManager) == null ? void 0 : D.streamId,
1166
+ sessionId: (F = a.streamingManager) == null ? void 0 : F.sessionId,
1167
+ messages: C.map(({ matches: x, ...J }) => J)
1141
1168
  },
1142
1169
  {
1143
- ...ke(a.chatMode),
1170
+ ...Re(a.chatMode),
1144
1171
  skipErrorHandler: !0
1145
1172
  }
1146
1173
  );
1147
1174
  },
1148
1175
  {
1149
1176
  limit: 2,
1150
- shouldRetryFn: (k) => {
1151
- var F, N, X, Y;
1152
- const $ = (F = k == null ? void 0 : k.message) == null ? void 0 : F.includes("missing or invalid session_id");
1153
- return !((N = k == null ? void 0 : k.message) == null ? void 0 : N.includes("Stream Error")) && !$ ? ((Y = (X = t.callbacks).onError) == null || Y.call(X, k), !1) : !0;
1177
+ shouldRetryFn: (D) => {
1178
+ var J, W, X, Y;
1179
+ const F = (J = D == null ? void 0 : D.message) == null ? void 0 : J.includes("missing or invalid session_id");
1180
+ return !((W = D == null ? void 0 : D.message) == null ? void 0 : W.includes("Stream Error")) && !F ? ((Y = (X = t.callbacks).onError) == null || Y.call(X, D), !1) : !0;
1154
1181
  },
1155
1182
  onRetry: async () => {
1156
- await z(), await B(!1);
1183
+ await j(), await b(!1);
1157
1184
  }
1158
1185
  }
1159
1186
  );
@@ -1162,9 +1189,9 @@ async function Lt(e, t) {
1162
1189
  id: q(),
1163
1190
  role: "user",
1164
1191
  content: u,
1165
- created_at: new Date(x.update()).toISOString()
1166
- }), (f = (y = t.callbacks).onNewMessage) == null || f.call(y, [...a.messages], "user");
1167
- const D = await p(), I = await _([...a.messages], D);
1192
+ created_at: new Date(N.update()).toISOString()
1193
+ }), (f = (k = t.callbacks).onNewMessage) == null || f.call(k, [...a.messages], "user");
1194
+ const C = await p(), I = await _([...a.messages], C);
1168
1195
  return a.messages.push({
1169
1196
  id: q(),
1170
1197
  role: "assistant",
@@ -1176,39 +1203,39 @@ async function Lt(e, t) {
1176
1203
  event: "success",
1177
1204
  messages: a.messages.length + 1
1178
1205
  }), I.result && ((T = (S = t.callbacks).onNewMessage) == null || T.call(S, [...a.messages], "answer"), o.track("agent-message-received", {
1179
- latency: x.get(!0),
1206
+ latency: N.get(!0),
1180
1207
  messages: a.messages.length
1181
1208
  })), I;
1182
- } catch (D) {
1183
- throw ((P = a.messages[a.messages.length - 1]) == null ? void 0 : P.role) === "assistant" && a.messages.pop(), o.track("agent-message-send", {
1209
+ } catch (C) {
1210
+ throw (($ = a.messages[a.messages.length - 1]) == null ? void 0 : $.role) === "assistant" && a.messages.pop(), o.track("agent-message-send", {
1184
1211
  event: "error",
1185
1212
  messages: a.messages.length
1186
- }), D;
1213
+ }), C;
1187
1214
  }
1188
1215
  },
1189
1216
  rate(u, h, p) {
1190
- var f, S, T, P;
1191
- const _ = a.messages.find((D) => D.id === u);
1217
+ var f, S, T, $;
1218
+ const _ = a.messages.find((C) => C.id === u);
1192
1219
  if (a.chat) {
1193
1220
  if (!_)
1194
1221
  throw new Error("Message not found");
1195
1222
  } else throw new Error("Chat is not initialized");
1196
- const y = ((f = _.matches) == null ? void 0 : f.map((D) => [D.document_id, D.id])) ?? [];
1223
+ const k = ((f = _.matches) == null ? void 0 : f.map((C) => [C.document_id, C.id])) ?? [];
1197
1224
  return o.track("agent-rate", {
1198
1225
  event: p ? "update" : "create",
1199
1226
  thumb: h === 1 ? "up" : "down",
1200
1227
  knowledge_id: ((S = l.knowledge) == null ? void 0 : S.id) ?? "",
1201
- matches: y,
1228
+ matches: k,
1202
1229
  score: h
1203
1230
  }), p ? d.updateRating(l.id, a.chat.id, p, {
1204
1231
  knowledge_id: ((T = l.knowledge) == null ? void 0 : T.id) ?? "",
1205
1232
  message_id: u,
1206
- matches: y,
1233
+ matches: k,
1207
1234
  score: h
1208
1235
  }) : d.createRating(l.id, a.chat.id, {
1209
- knowledge_id: ((P = l.knowledge) == null ? void 0 : P.id) ?? "",
1236
+ knowledge_id: (($ = l.knowledge) == null ? void 0 : $.id) ?? "",
1210
1237
  message_id: u,
1211
- matches: y,
1238
+ matches: k,
1212
1239
  score: h
1213
1240
  });
1214
1241
  },
@@ -1218,7 +1245,7 @@ async function Lt(e, t) {
1218
1245
  return o.track("agent-rate-delete", { type: "text" }), d.deleteRating(l.id, a.chat.id, u);
1219
1246
  },
1220
1247
  async speak(u) {
1221
- var y, f, S;
1248
+ var k, f, S;
1222
1249
  function h() {
1223
1250
  if (typeof u == "string") {
1224
1251
  if (!l.presenter.voice)
@@ -1243,12 +1270,12 @@ async function Lt(e, t) {
1243
1270
  return u;
1244
1271
  }
1245
1272
  const p = h();
1246
- if (o.track("agent-speak", p), x.update(), a.messages && p.type === "text" && (a.messages.push({
1273
+ if (o.track("agent-speak", p), N.update(), a.messages && p.type === "text" && (a.messages.push({
1247
1274
  id: q(),
1248
1275
  role: "assistant",
1249
1276
  content: p.input,
1250
1277
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1251
- }), (f = (y = t.callbacks).onNewMessage) == null || f.call(y, [...a.messages], "answer")), Ne(a.chatMode))
1278
+ }), (f = (k = t.callbacks).onNewMessage) == null || f.call(k, [...a.messages], "answer")), We(a.chatMode))
1252
1279
  return {
1253
1280
  duration: 0,
1254
1281
  video_id: "",
@@ -1262,49 +1289,49 @@ async function Lt(e, t) {
1262
1289
  });
1263
1290
  },
1264
1291
  async interrupt({ type: u }) {
1265
- var p, _, y;
1266
- Ze(a.streamingManager, (p = a.streamingManager) == null ? void 0 : p.streamType, r);
1292
+ var p, _, k;
1293
+ Ge(a.streamingManager, (p = a.streamingManager) == null ? void 0 : p.streamType, r);
1267
1294
  const h = a.messages[a.messages.length - 1];
1268
1295
  o.track("agent-video-interrupt", {
1269
1296
  type: u || "click",
1270
1297
  video_duration_to_interrupt: ae.get(!0),
1271
- message_duration_to_interrupt: x.get(!0)
1272
- }), h.interrupted = !0, (y = (_ = t.callbacks).onNewMessage) == null || y.call(_, [...a.messages], "answer"), Ge(a.streamingManager, r);
1298
+ message_duration_to_interrupt: N.get(!0)
1299
+ }), h.interrupted = !0, (k = (_ = t.callbacks).onNewMessage) == null || k.call(_, [...a.messages], "answer"), et(a.streamingManager, r);
1273
1300
  }
1274
1301
  };
1275
1302
  }
1276
1303
  function Bt(e, t, n) {
1277
- const { getById: r } = pe(t, n || ee);
1304
+ const { getById: r } = ye(t, n || ee);
1278
1305
  return r(e);
1279
1306
  }
1280
1307
  export {
1281
1308
  O as A,
1282
1309
  R as C,
1283
- Pe as D,
1284
- be as K,
1285
- _e as P,
1286
- Ae as R,
1287
- J as S,
1288
- oe as T,
1289
- Me as U,
1310
+ Be as D,
1311
+ Le as K,
1312
+ Ae as P,
1313
+ Pe as R,
1314
+ U as S,
1315
+ ce as T,
1316
+ Te as U,
1290
1317
  H as V,
1291
- Ee as W,
1292
- ot as a,
1318
+ _e as W,
1319
+ ct as a,
1293
1320
  G as b,
1294
- we as c,
1321
+ ve as c,
1295
1322
  w as d,
1296
- j as e,
1323
+ L as e,
1297
1324
  ee as f,
1298
- Se as g,
1299
- Ie as h,
1325
+ Ee as g,
1326
+ Me as h,
1300
1327
  Lt as i,
1301
1328
  Bt as j,
1302
- Te as k,
1329
+ je as k,
1303
1330
  E as l,
1304
1331
  V as m,
1305
- je as n,
1306
- ue as o,
1307
- Pt as p,
1308
- Le as q,
1309
- Be as r
1332
+ be as n,
1333
+ me as o,
1334
+ bt as p,
1335
+ $e as q,
1336
+ xe as r
1310
1337
  };