@d-id/client-sdk 1.1.22-staging.103 → 1.1.22-staging.104

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.
@@ -23,20 +23,20 @@ class Te extends te {
23
23
  super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
24
24
  }
25
25
  }
26
- class X extends te {
26
+ class Y extends te {
27
27
  constructor(n, r) {
28
28
  super({ kind: "ValidationError", description: n });
29
29
  G(this, "key");
30
30
  this.key = r;
31
31
  }
32
32
  }
33
- class Ae extends te {
33
+ class be extends te {
34
34
  constructor(t) {
35
35
  super({ kind: "WSError", description: t });
36
36
  }
37
37
  }
38
- var Pe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Pe || {}), je = /* @__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))(je || {}), be = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(be || {}), Le = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Le || {}), E = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(E || {}), Y = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Complete = "done", e))(Y || {}), xe = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(xe || {}), $e = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))($e || {}), 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 || {}), ve = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(ve || {});
39
- const zt = (e) => {
38
+ var Ae = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Ae || {}), Pe = /* @__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))(Pe || {}), je = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(je || {}), Le = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Le || {}), E = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(E || {}), J = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(J || {}), $e = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))($e || {}), xe = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(xe || {}), 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 || {}), ye = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(ye || {});
39
+ const Ft = (e) => {
40
40
  switch (e) {
41
41
  case "clip":
42
42
  return "clip";
@@ -48,11 +48,11 @@ const zt = (e) => {
48
48
  throw new Error(`Unknown video type: ${e}`);
49
49
  }
50
50
  };
51
- var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}), ee = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ee || {}), Z = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(Z || {}), 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.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e))(x || {}), _ = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(_ || {}), K = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(K || {}), de = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(de || {}), ze = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(ze || {}), Fe = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Fe || {});
52
- const Ne = 45 * 1e3, Je = "X-Playground-Chat", re = "https://api.d-id.com", We = "wss://notifications.d-id.com", Ue = "79f81a83a67430be2bc0fd61042b8faa", ye = (e) => new Promise((t) => setTimeout(t, e)), Q = (e = 16) => {
51
+ var p = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(p || {}), ee = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ee || {}), Z = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(Z || {}), P = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", 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))(P || {}), _ = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(_ || {}), H = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(H || {}), de = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(de || {}), ze = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(ze || {}), Fe = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Fe || {});
52
+ const Ne = 45 * 1e3, Je = "X-Playground-Chat", re = "https://api.d-id.com", We = "wss://notifications.d-id.com", Ue = "79f81a83a67430be2bc0fd61042b8faa", ve = (e) => new Promise((t) => setTimeout(t, e)), Q = (e = 16) => {
53
53
  const t = new Uint8Array(e);
54
54
  return window.crypto.getRandomValues(t), Array.from(t, (n) => n.toString(16).padStart(2, "0")).join("").slice(0, 13);
55
- }, ke = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, le = (e) => e === ve.Expressive, Ke = (e) => [E.TextOnly, E.Playground, E.Maintenance].includes(e), Re = (e) => e && [E.DirectPlayback, E.Off].includes(e);
55
+ }, ke = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, le = (e) => e === ye.Expressive, Ke = (e) => [E.TextOnly, E.Playground, E.Maintenance].includes(e), Se = (e) => e && [E.DirectPlayback, E.Off].includes(e);
56
56
  function He(e, t) {
57
57
  let n;
58
58
  return {
@@ -82,7 +82,7 @@ async function ae(e, t) {
82
82
  } catch (s) {
83
83
  if (r = s, !n.shouldRetryFn(s) || c >= n.limit)
84
84
  throw s;
85
- await ye(n.delayMs), n.onRetry(s);
85
+ await ve(n.delayMs), n.onRetry(s);
86
86
  }
87
87
  throw r;
88
88
  }
@@ -125,9 +125,9 @@ function De(e, t = re, n, r) {
125
125
  })
126
126
  );
127
127
  if (!d.ok) {
128
- let u = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
129
- const l = new Error(u);
130
- throw n && !a && n(l, { url: s, options: i, headers: d.headers }), l;
128
+ let l = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
129
+ const u = new Error(l);
130
+ throw n && !a && n(u, { url: s, options: i, headers: d.headers }), u;
131
131
  }
132
132
  return d.json();
133
133
  };
@@ -227,13 +227,13 @@ function Ye(e) {
227
227
  }
228
228
  const Qe = (e) => e.reduce((t, n) => t + n, 0), me = (e) => Qe(e) / e.length;
229
229
  function Ze(e, t, n) {
230
- var i, d, u;
230
+ var i, d, l;
231
231
  const { event: r, ...c } = e, { template: s } = (t == null ? void 0 : t.llm) || {}, { language: o } = ((i = t == null ? void 0 : t.presenter) == null ? void 0 : i.voice) || {};
232
232
  return {
233
233
  ...c,
234
234
  llm: { ...c.llm, template: s },
235
235
  script: { ...c.script, provider: { ...(d = c == null ? void 0 : c.script) == null ? void 0 : d.provider, language: o } },
236
- stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (u = t == null ? void 0 : t.presenter) == null ? void 0 : u.stitch : void 0,
236
+ stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (l = t == null ? void 0 : t.presenter) == null ? void 0 : l.stitch : void 0,
237
237
  ...n
238
238
  };
239
239
  }
@@ -297,7 +297,7 @@ function et(e) {
297
297
  if (o.events[c] = { props: r }, o.resolvedDependencies.push(c), s.every(
298
298
  (i) => o.resolvedDependencies.includes(i)
299
299
  )) {
300
- const i = s.reduce((d, u) => o.events[u] ? { ...d, ...o.events[u].props } : d, {});
300
+ const i = s.reduce((d, l) => o.events[l] ? { ...d, ...o.events[l].props } : d, {});
301
301
  this.track(n, i), o.resolvedDependencies = o.resolvedDependencies.filter(
302
302
  (d) => !s.includes(d)
303
303
  ), s.forEach((d) => {
@@ -315,13 +315,13 @@ function ue() {
315
315
  get: (t = !1) => t ? Date.now() - e : e
316
316
  };
317
317
  }
318
- const J = ue(), se = ue(), ge = ue();
319
- function Se(e) {
318
+ const W = ue(), se = ue(), ge = ue();
319
+ function Re(e) {
320
320
  return e === E.Playground ? { headers: { [Je]: "true" } } : {};
321
321
  }
322
322
  async function Ie(e, t, n, r, c = !1, s) {
323
323
  try {
324
- return !s && !Re(r) && (s = await t.newChat(e.id, { persist: c }, Se(r)), n.track("agent-chat", {
324
+ return !s && !Se(r) && (s = await t.newChat(e.id, { persist: c }, Re(r)), n.track("agent-chat", {
325
325
  event: "created",
326
326
  chatId: s.id,
327
327
  mode: r
@@ -346,14 +346,14 @@ function nt(e, t, n) {
346
346
  throw new Error("Please connect to the agent first");
347
347
  if (!e.interruptAvailable)
348
348
  throw new Error("Interrupt is not enabled for this stream");
349
- if (t !== K.Fluent)
349
+ if (t !== H.Fluent)
350
350
  throw new Error("Interrupt only available for Fluent streams");
351
351
  if (!n)
352
352
  throw new Error("No active video to interrupt");
353
353
  }
354
354
  async function at(e, t) {
355
355
  const n = {
356
- type: x.StreamInterrupt,
356
+ type: P.StreamInterrupt,
357
357
  videoId: t,
358
358
  timestamp: Date.now()
359
359
  };
@@ -361,11 +361,11 @@ async function at(e, t) {
361
361
  }
362
362
  function it(e) {
363
363
  return new Promise((t, n) => {
364
- const { callbacks: r, host: c, auth: s, externalId: o } = e, { onMessage: a = null, onOpen: i = null, onClose: d = null, onError: u = null } = r || {}, l = new WebSocket(`${c}?authorization=${encodeURIComponent(Ce(s, o))}`);
365
- l.onmessage = a, l.onclose = d, l.onerror = (v) => {
366
- console.error(v), u == null || u("Websocket failed to connect", v), n(v);
367
- }, l.onopen = (v) => {
368
- i == null || i(v), t(l);
364
+ const { callbacks: r, host: c, auth: s, externalId: o } = e, { onMessage: a = null, onOpen: i = null, onClose: d = null, onError: l = null } = r || {}, u = new WebSocket(`${c}?authorization=${encodeURIComponent(Ce(s, o))}`);
365
+ u.onmessage = a, u.onclose = d, u.onerror = (y) => {
366
+ console.error(y), l == null || l("Websocket failed to connect", y), n(y);
367
+ }, u.onopen = (y) => {
368
+ i == null || i(y), t(u);
369
369
  };
370
370
  });
371
371
  }
@@ -378,7 +378,7 @@ async function st(e) {
378
378
  } catch (c) {
379
379
  if (r === t)
380
380
  throw c;
381
- await ye(r * 500);
381
+ await ve(r * 500);
382
382
  }
383
383
  return n;
384
384
  }
@@ -390,7 +390,7 @@ async function ot(e, t, n, r) {
390
390
  callbacks: {
391
391
  onError: (o) => {
392
392
  var a;
393
- return (a = n.onError) == null ? void 0 : a.call(n, new Ae(o));
393
+ return (a = n.onError) == null ? void 0 : a.call(n, new be(o));
394
394
  },
395
395
  onMessage(o) {
396
396
  const a = JSON.parse(o.data);
@@ -412,40 +412,69 @@ function ct(e) {
412
412
  n += e[t++];
413
413
  return n;
414
414
  }
415
- function dt(e, t, n, r, c) {
416
- const s = r.messages[r.messages.length - 1];
417
- if (!(e === Y.Partial || e === Y.Answer) || (s == null ? void 0 : s.role) !== "assistant")
415
+ function dt(e, t, n) {
416
+ if (!e.content)
418
417
  return;
419
- const { content: o, sequence: a } = t;
420
- e === Y.Partial ? n[a] = o : n.answer = o;
421
- const i = ct(n);
422
- (s.content !== i || e === Y.Answer) && (s.content = i, c == null || c([...r.messages], e));
418
+ const r = {
419
+ id: e.id || `user-${Date.now()}`,
420
+ role: e.role,
421
+ content: e.content,
422
+ created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
423
+ transcribed: !0
424
+ };
425
+ t.messages.push(r), n == null || n([...t.messages], "user");
423
426
  }
424
427
  function lt(e, t, n, r, c) {
428
+ if (e === J.Transcribe && t.content) {
429
+ dt(t, r, c);
430
+ return;
431
+ }
432
+ if (!(e === J.Partial || e === J.Answer))
433
+ return;
434
+ const s = r.messages[r.messages.length - 1];
435
+ let o;
436
+ if (s != null && s.transcribed && s.role === "user")
437
+ e === J.Answer && t.content, o = {
438
+ id: t.id || `assistant-${Date.now()}`,
439
+ role: t.role || "assistant",
440
+ content: t.content || "",
441
+ created_at: t.created_at || (/* @__PURE__ */ new Date()).toISOString()
442
+ }, r.messages.push(o);
443
+ else if ((s == null ? void 0 : s.role) === "assistant")
444
+ o = s;
445
+ else
446
+ return;
447
+ const { content: a, sequence: i } = t;
448
+ e === J.Partial ? n[i] = a : n.answer = a;
449
+ const d = ct(n);
450
+ (o.content !== d || e === J.Answer) && (o.content = d, c == null || c([...r.messages], e));
451
+ }
452
+ function ut(e, t, n, r, c) {
425
453
  let s = {};
426
454
  return {
427
455
  clearQueue: () => s = {},
428
456
  onMessage: (o, a) => {
429
457
  var i, d;
430
- if ("content" in a)
431
- dt(o, a, s, t, n.callbacks.onNewMessage), o === Y.Answer && e.track("agent-message-received", {
458
+ if ("content" in a) {
459
+ const l = o === P.ChatAnswer ? J.Answer : o === P.ChatAudioTranscribed ? J.Transcribe : o;
460
+ lt(l, a, s, t, n.callbacks.onNewMessage), l === J.Answer && e.track("agent-message-received", {
432
461
  messages: t.messages.length,
433
462
  mode: t.chatMode
434
463
  });
435
- else {
436
- const u = x, l = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], v = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], j = Ze(a, r, { mode: t.chatMode });
437
- if (o = o, o === u.StreamVideoCreated)
438
- e.linkTrack("agent-video", j, u.StreamVideoCreated, ["start"]);
439
- else if (l.includes(o)) {
440
- const A = o.split("/")[1];
441
- v.includes(o) ? e.track("agent-video", { ...j, event: A }) : e.linkTrack("agent-video", { ...j, event: A }, o, ["done"]);
464
+ } else {
465
+ const l = P, u = [l.StreamVideoDone, l.StreamVideoError, l.StreamVideoRejected], y = [l.StreamFailed, l.StreamVideoError, l.StreamVideoRejected], j = Ze(a, r, { mode: t.chatMode });
466
+ if (o = o, o === l.StreamVideoCreated)
467
+ e.linkTrack("agent-video", j, l.StreamVideoCreated, ["start"]);
468
+ else if (u.includes(o)) {
469
+ const b = o.split("/")[1];
470
+ y.includes(o) ? e.track("agent-video", { ...j, event: b }) : e.linkTrack("agent-video", { ...j, event: b }, o, ["done"]);
442
471
  }
443
- v.includes(o) && ((d = (i = n.callbacks).onError) == null || d.call(i, new Error(`Stream failed with event ${o}`), { data: a })), a.event === u.StreamDone && c();
472
+ y.includes(o) && ((d = (i = n.callbacks).onError) == null || d.call(i, new Error(`Stream failed with event ${o}`), { data: a })), a.event === l.StreamDone && c();
444
473
  }
445
474
  }
446
475
  };
447
476
  }
448
- function ut(e, t, n, r) {
477
+ function mt(e, t, n, r) {
449
478
  const c = De(e, `${t}/agents/${n}`, r);
450
479
  return {
451
480
  createStream(s, o) {
@@ -482,8 +511,8 @@ function ut(e, t, n, r) {
482
511
  }
483
512
  };
484
513
  }
485
- const mt = (e, t) => (n, r) => e && console.log(`[${t}] ${n}`, r ?? "");
486
- function ft(e, t, n) {
514
+ const ft = (e, t) => (n, r) => e && console.log(`[${t}] ${n}`, r ?? "");
515
+ function gt(e, t, n) {
487
516
  const r = (t.timestamp - e.timestamp) / 1e3;
488
517
  return {
489
518
  duration: r,
@@ -503,7 +532,7 @@ function ft(e, t, n) {
503
532
  lowFpsCount: n
504
533
  };
505
534
  }
506
- function gt(e) {
535
+ function ht(e) {
507
536
  return e.filter(
508
537
  (t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
509
538
  ).map((t) => {
@@ -514,7 +543,7 @@ function gt(e) {
514
543
  };
515
544
  });
516
545
  }
517
- function ht(e) {
546
+ function pt(e) {
518
547
  let t = "", n = 0;
519
548
  for (const r of e.values()) {
520
549
  if (r && r.type === "codec" && r.mimeType.startsWith("video") && (t = r.mimeType.split("/")[1]), r && r.type === "candidate-pair") {
@@ -544,7 +573,7 @@ function ht(e) {
544
573
  }
545
574
  return {};
546
575
  }
547
- function pt(e, t, n) {
576
+ function wt(e, t, n) {
548
577
  const r = e.map((i, d) => d === 0 ? n ? {
549
578
  timestamp: i.timestamp,
550
579
  duration: 0,
@@ -596,14 +625,14 @@ function pt(e, t, n) {
596
625
  framesPerSecond: i.framesPerSecond,
597
626
  freezeCount: i.freezeCount - e[d - 1].freezeCount,
598
627
  freezeDuration: i.freezeDuration - e[d - 1].freezeDuration
599
- }), c = gt(r), s = c.reduce((i, d) => i + (d.causes.includes("low fps") ? 1 : 0), 0), o = r.filter((i) => !!i.avgJitterDelayInInterval).map((i) => i.avgJitterDelayInInterval), a = r.filter((i) => !!i.rtt).map((i) => i.rtt);
628
+ }), c = ht(r), s = c.reduce((i, d) => i + (d.causes.includes("low fps") ? 1 : 0), 0), o = r.filter((i) => !!i.avgJitterDelayInInterval).map((i) => i.avgJitterDelayInInterval), a = r.filter((i) => !!i.rtt).map((i) => i.rtt);
600
629
  return {
601
630
  webRTCStats: {
602
631
  anomalies: c,
603
632
  minRtt: Math.min(...a),
604
633
  avgRtt: me(a),
605
634
  maxRtt: Math.max(...a),
606
- aggregateReport: ft(e[0], e[e.length - 1], s),
635
+ aggregateReport: gt(e[0], e[e.length - 1], s),
607
636
  minJitterDelayInInterval: Math.min(...o),
608
637
  maxJitterDelayInInterval: Math.max(...o),
609
638
  avgJitterDelayInInterval: me(o)
@@ -612,16 +641,16 @@ function pt(e, t, n) {
612
641
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
613
642
  };
614
643
  }
615
- const oe = 100, wt = Math.max(Math.ceil(400 / oe), 1), vt = 0.25, yt = 0.28;
616
- function kt() {
644
+ const oe = 100, yt = Math.max(Math.ceil(400 / oe), 1), vt = 0.25, kt = 0.28;
645
+ function St() {
617
646
  let e = 0, t, n, r = 0;
618
647
  return (c) => {
619
648
  for (const s of c.values())
620
649
  if (s && s.type === "inbound-rtp" && s.kind === "video") {
621
650
  const o = s.jitterBufferDelay, a = s.jitterBufferEmittedCount;
622
651
  if (n && a > n) {
623
- const u = o - t, l = a - n;
624
- r = u / l;
652
+ const l = o - t, u = a - n;
653
+ r = l / u;
625
654
  }
626
655
  t = o, n = a;
627
656
  const i = s.framesDecoded, d = i - e > 0;
@@ -630,20 +659,20 @@ function kt() {
630
659
  return { isReceiving: !1, avgJitterDelayInInterval: r };
631
660
  };
632
661
  }
633
- function Rt(e, t, n, r, c) {
634
- let s = [], o, a = 0, i = !1, d = ee.Unknown, u = ee.Unknown, l = 0, v = 0;
635
- const j = kt();
662
+ function Ct(e, t, n, r, c) {
663
+ let s = [], o, a = 0, i = !1, d = ee.Unknown, l = ee.Unknown, u = 0, y = 0;
664
+ const j = St();
636
665
  return setInterval(async () => {
637
- const A = await e.getStats(), { isReceiving: W, avgJitterDelayInInterval: P, freezeCount: b } = j(A), $ = ht(A);
638
- if (W)
639
- a = 0, l = b - v, u = P < vt ? ee.Strong : P > yt && l > 1 ? ee.Weak : d, u !== d && (c == null || c(u), d = u, v += l, l = 0), i || (r == null || r(p.Start), o = s[s.length - 1], s = [], i = !0), s.push($);
640
- else if (i && (a++, a >= wt)) {
641
- const S = pt(s, oe, o);
642
- r == null || r(p.Stop, S), t() || n(), v = b, i = !1;
666
+ const b = await e.getStats(), { isReceiving: U, avgJitterDelayInInterval: A, freezeCount: L } = j(b), x = pt(b);
667
+ if (U)
668
+ a = 0, u = L - y, l = A < vt ? ee.Strong : A > kt && u > 1 ? ee.Weak : d, l !== d && (c == null || c(l), d = l, y += u, u = 0), i || (r == null || r(p.Start), o = s[s.length - 1], s = [], i = !0), s.push(x);
669
+ else if (i && (a++, a >= yt)) {
670
+ const R = wt(s, oe, o);
671
+ r == null || r(p.Stop, R), t() || n(), y = L, i = !1;
643
672
  }
644
673
  }, oe);
645
674
  }
646
- const Ct = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
675
+ const Dt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
647
676
  function he(e) {
648
677
  switch (e) {
649
678
  case "connected":
@@ -664,7 +693,7 @@ function he(e) {
664
693
  return _.New;
665
694
  }
666
695
  }
667
- const Dt = (e) => (t) => {
696
+ const Rt = (e) => (t) => {
668
697
  const [n, r = ""] = t.split(/:(.+)/);
669
698
  try {
670
699
  const c = JSON.parse(r);
@@ -673,7 +702,7 @@ const Dt = (e) => (t) => {
673
702
  return e("Failed to parse data channel message, returning data as string", { subject: n, rawData: r, error: c }), { subject: n, data: r };
674
703
  }
675
704
  };
676
- function St({
705
+ function It({
677
706
  statsSignal: e,
678
707
  dataChannelSignal: t,
679
708
  onVideoStateChange: n,
@@ -681,7 +710,7 @@ function St({
681
710
  }) {
682
711
  e === p.Start && t === p.Start ? n == null || n(p.Start) : e === p.Stop && t === p.Stop && (n == null || n(p.Stop, r));
683
712
  }
684
- function It({
713
+ function Et({
685
714
  statsSignal: e,
686
715
  dataChannelSignal: t,
687
716
  onVideoStateChange: n,
@@ -698,7 +727,7 @@ function pe({
698
727
  streamType: c,
699
728
  report: s
700
729
  }) {
701
- c === K.Legacy ? St({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: n, report: s }) : c === K.Fluent && It({
730
+ c === H.Legacy ? It({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: n, report: s }) : c === H.Fluent && Et({
702
731
  statsSignal: e,
703
732
  dataChannelSignal: t,
704
733
  onVideoStateChange: n,
@@ -706,42 +735,42 @@ function pe({
706
735
  report: s
707
736
  });
708
737
  }
709
- async function Et(e, t, { debug: n = !1, callbacks: r, auth: c, baseURL: s = re, analytics: o }, a) {
738
+ async function Mt(e, t, { debug: n = !1, callbacks: r, auth: c, baseURL: s = re, analytics: o }, a) {
710
739
  var N;
711
- const i = mt(n, "WebRTCStreamingManager"), d = Dt(i);
712
- let u = !1, l = !1, v = p.Stop, j = p.Stop;
713
- const { startConnection: A, sendStreamRequest: W, close: P, createStream: b, addIceCandidate: $ } = ut(
740
+ const i = ft(n, "WebRTCStreamingManager"), d = Rt(i);
741
+ let l = !1, u = !1, y = p.Stop, j = p.Stop;
742
+ const { startConnection: b, sendStreamRequest: U, close: A, createStream: L, addIceCandidate: x } = mt(
714
743
  c,
715
744
  s,
716
745
  e,
717
746
  r.onError
718
747
  ), {
719
- id: S,
720
- offer: O,
721
- ice_servers: V,
748
+ id: R,
749
+ offer: X,
750
+ ice_servers: q,
722
751
  session_id: B,
723
752
  fluent: m,
724
- interrupt_enabled: C,
725
- triggers_enabled: y
726
- } = await b(t, a);
727
- (N = r.onStreamCreated) == null || N.call(r, { stream_id: S, session_id: B, agent_id: e });
728
- const h = new Ct({ iceServers: V }), k = h.createDataChannel("JanusDataChannel");
753
+ interrupt_enabled: v,
754
+ triggers_enabled: k
755
+ } = await L(t, a);
756
+ (N = r.onStreamCreated) == null || N.call(r, { stream_id: R, session_id: B, agent_id: e });
757
+ const h = new Dt({ iceServers: q }), S = h.createDataChannel("JanusDataChannel");
729
758
  if (!B)
730
759
  throw new Error("Could not create session_id");
731
- const w = m ? K.Fluent : K.Legacy;
760
+ const w = m ? H.Fluent : H.Legacy;
732
761
  o.enrich({
733
762
  "stream-type": w
734
763
  });
735
- const L = t.stream_warmup && !m, F = () => u, z = () => {
764
+ const $ = t.stream_warmup && !m, F = () => l, z = () => {
736
765
  var f;
737
- u = !0, l && ((f = r.onConnectionStateChange) == null || f.call(r, _.Connected));
738
- }, I = Rt(
766
+ l = !0, u && ((f = r.onConnectionStateChange) == null || f.call(r, _.Connected));
767
+ }, I = Ct(
739
768
  h,
740
769
  F,
741
770
  z,
742
771
  (f, g) => pe({
743
772
  statsSignal: j = f,
744
- dataChannelSignal: w === K.Legacy ? v : void 0,
773
+ dataChannelSignal: w === H.Legacy ? y : void 0,
745
774
  onVideoStateChange: r.onVideoStateChange,
746
775
  onAgentActivityStateChange: r.onAgentActivityStateChange,
747
776
  report: g,
@@ -756,8 +785,8 @@ async function Et(e, t, { debug: n = !1, callbacks: r, auth: c, baseURL: s = re,
756
785
  var g;
757
786
  i("peerConnection.onicecandidate", f);
758
787
  try {
759
- f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? $(
760
- S,
788
+ f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? x(
789
+ R,
761
790
  {
762
791
  candidate: f.candidate.candidate,
763
792
  sdpMid: f.candidate.sdpMid,
@@ -765,44 +794,44 @@ async function Et(e, t, { debug: n = !1, callbacks: r, auth: c, baseURL: s = re,
765
794
  },
766
795
  B,
767
796
  a
768
- ) : $(S, { candidate: null }, B, a);
797
+ ) : x(R, { candidate: null }, B, a);
769
798
  } catch (M) {
770
- (g = r.onError) == null || g.call(r, M, { streamId: S });
799
+ (g = r.onError) == null || g.call(r, M, { streamId: R });
771
800
  }
772
- }, k.onopen = () => {
773
- l = !0, (!L || u) && z();
801
+ }, S.onopen = () => {
802
+ u = !0, (!$ || l) && z();
774
803
  };
775
804
  const T = (f) => {
776
805
  var g;
777
806
  (g = r.onVideoIdChange) == null || g.call(r, f);
778
807
  };
779
- function U(f, g) {
780
- if (f === x.StreamStarted && typeof g == "object" && "metadata" in g) {
808
+ function K(f, g) {
809
+ if (f === P.StreamStarted && typeof g == "object" && "metadata" in g) {
781
810
  const M = g.metadata;
782
811
  T(M.videoId);
783
812
  }
784
- f === x.StreamDone && T(null), v = f === x.StreamStarted ? p.Start : p.Stop, pe({
785
- statsSignal: w === K.Legacy ? j : void 0,
786
- dataChannelSignal: v,
813
+ f === P.StreamDone && T(null), y = f === P.StreamStarted ? p.Start : p.Stop, pe({
814
+ statsSignal: w === H.Legacy ? j : void 0,
815
+ dataChannelSignal: y,
787
816
  onVideoStateChange: r.onVideoStateChange,
788
817
  onAgentActivityStateChange: r.onAgentActivityStateChange,
789
818
  streamType: w
790
819
  });
791
820
  }
792
821
  function D(f, g) {
793
- var H;
822
+ var V;
794
823
  const M = typeof g == "string" ? g : g == null ? void 0 : g.metadata;
795
- M && o.enrich({ streamMetadata: M }), (H = r.onStreamReady) == null || H.call(r);
824
+ M && o.enrich({ streamMetadata: M }), (V = r.onStreamReady) == null || V.call(r);
796
825
  }
797
- const R = {
798
- [x.StreamStarted]: U,
799
- [x.StreamDone]: U,
800
- [x.StreamReady]: D
826
+ const C = {
827
+ [P.StreamStarted]: K,
828
+ [P.StreamDone]: K,
829
+ [P.StreamReady]: D
801
830
  };
802
- k.onmessage = (f) => {
803
- var H;
831
+ S.onmessage = (f) => {
832
+ var V;
804
833
  const { subject: g, data: M } = d(f.data);
805
- (H = R[g]) == null || H.call(R, g, M);
834
+ (V = C[g]) == null || V.call(C, g, M);
806
835
  }, h.oniceconnectionstatechange = () => {
807
836
  var g;
808
837
  i("peerConnection.oniceconnectionstatechange => " + h.iceConnectionState);
@@ -811,22 +840,22 @@ async function Et(e, t, { debug: n = !1, callbacks: r, auth: c, baseURL: s = re,
811
840
  }, h.ontrack = (f) => {
812
841
  var g;
813
842
  i("peerConnection.ontrack", f), (g = r.onSrcObjectReady) == null || g.call(r, f.streams[0]);
814
- }, await h.setRemoteDescription(O), i("set remote description OK");
815
- const q = await h.createAnswer();
816
- return i("create answer OK"), await h.setLocalDescription(q), i("set local description OK"), await A(S, q, B, a), i("start connection OK"), {
843
+ }, await h.setRemoteDescription(X), i("set remote description OK");
844
+ const O = await h.createAnswer();
845
+ return i("create answer OK"), await h.setLocalDescription(O), i("set local description OK"), await b(R, O, B, a), i("start connection OK"), {
817
846
  /**
818
847
  * Method to send request to server to get clip or talk depend on you payload
819
848
  * @param payload
820
849
  */
821
850
  speak(f) {
822
- return W(S, B, f);
851
+ return U(R, B, f);
823
852
  },
824
853
  /**
825
854
  * Method to close RTC connection
826
855
  */
827
856
  async disconnect() {
828
857
  var f;
829
- if (S) {
858
+ if (R) {
830
859
  const g = he(h.iceConnectionState);
831
860
  if (h) {
832
861
  if (g === _.New) {
@@ -836,7 +865,7 @@ async function Et(e, t, { debug: n = !1, callbacks: r, auth: c, baseURL: s = re,
836
865
  h.close(), h.oniceconnectionstatechange = null, h.onnegotiationneeded = null, h.onicecandidate = null, h.ontrack = null;
837
866
  }
838
867
  try {
839
- g === _.Connected && await P(S, B).catch((M) => {
868
+ g === _.Connected && await A(R, B).catch((M) => {
840
869
  });
841
870
  } catch (M) {
842
871
  i("Error on close stream connection", M);
@@ -849,16 +878,16 @@ async function Et(e, t, { debug: n = !1, callbacks: r, auth: c, baseURL: s = re,
849
878
  */
850
879
  sendDataChannelMessage(f) {
851
880
  var g, M;
852
- if (!u || k.readyState !== "open") {
881
+ if (!l || S.readyState !== "open") {
853
882
  i("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"), {
854
- streamId: S
883
+ streamId: R
855
884
  });
856
885
  return;
857
886
  }
858
887
  try {
859
- k.send(f);
860
- } catch (H) {
861
- i("Error sending data channel message", H), (M = r.onError) == null || M.call(r, H, { streamId: S });
888
+ S.send(f);
889
+ } catch (V) {
890
+ i("Error sending data channel message", V), (M = r.onError) == null || M.call(r, V, { streamId: R });
862
891
  }
863
892
  },
864
893
  /**
@@ -868,25 +897,25 @@ async function Et(e, t, { debug: n = !1, callbacks: r, auth: c, baseURL: s = re,
868
897
  /**
869
898
  * Id of current RTC stream
870
899
  */
871
- streamId: S,
900
+ streamId: R,
872
901
  streamType: w,
873
- interruptAvailable: C ?? !1,
874
- triggersAvailable: y ?? !1
902
+ interruptAvailable: v ?? !1,
903
+ triggersAvailable: k ?? !1
875
904
  };
876
905
  }
877
906
  var ce = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(ce || {});
878
- async function Mt(e, t, n, r) {
907
+ async function _t(e, t, n, r) {
879
908
  const c = e.id;
880
909
  switch (t.version) {
881
910
  case "v1": {
882
911
  const { version: s, ...o } = t;
883
- return Et(c, o, n, r);
912
+ return Mt(c, o, n, r);
884
913
  }
885
914
  case "v2": {
886
915
  const { version: s, ...o } = t;
887
916
  switch (o.transport_provider) {
888
917
  case de.Livekit:
889
- const { createLiveKitStreamingManager: a } = await import("./livekit-manager-BKZAOT9G.js");
918
+ const { createLiveKitStreamingManager: a } = await import("./livekit-manager-Cv9nty3S.js");
890
919
  return a(c, o, n);
891
920
  default:
892
921
  throw new Error(`Unsupported transport provider: ${o.transport_provider}`);
@@ -896,8 +925,8 @@ async function Mt(e, t, n, r) {
896
925
  throw new Error(`Invalid stream version: ${t.version}`);
897
926
  }
898
927
  }
899
- const _t = "cht";
900
- function Tt() {
928
+ const Tt = "cht";
929
+ function bt() {
901
930
  return {
902
931
  transport_provider: de.Livekit
903
932
  };
@@ -916,12 +945,12 @@ function At(e) {
916
945
  }, ...n && { end_user_data: n } };
917
946
  }
918
947
  function Pt(e, t) {
919
- return le(e.presenter.type) ? { version: ce.V2, ...Tt() } : { version: ce.V1, ...At(t) };
948
+ return le(e.presenter.type) ? { version: ce.V2, ...bt() } : { version: ce.V1, ...At(t) };
920
949
  }
921
950
  function jt(e, t, n, r, c) {
922
- c === K.Fluent ? bt(e, t, n, r, c) : xt(e, t, n, r, c);
951
+ c === H.Fluent ? Lt(e, t, n, r, c) : xt(e, t, n, r, c);
923
952
  }
924
- function bt(e, t, n, r, c) {
953
+ function Lt(e, t, n, r, c) {
925
954
  e === p.Start ? r.track("stream-session", { event: "start", "stream-type": c }) : e === p.Stop && r.track("stream-session", {
926
955
  event: "stop",
927
956
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
@@ -930,12 +959,12 @@ function bt(e, t, n, r, c) {
930
959
  ...n
931
960
  });
932
961
  }
933
- function Lt(e, t, n, r) {
934
- J.get() <= 0 || (e === p.Start ? n.linkTrack(
962
+ function $t(e, t, n, r) {
963
+ W.get() <= 0 || (e === p.Start ? n.linkTrack(
935
964
  "agent-video",
936
- { event: "start", latency: J.get(!0), "stream-type": r },
965
+ { event: "start", latency: W.get(!0), "stream-type": r },
937
966
  "start",
938
- [x.StreamVideoCreated]
967
+ [P.StreamVideoCreated]
939
968
  ) : e === p.Stop && n.linkTrack(
940
969
  "agent-video",
941
970
  {
@@ -945,15 +974,15 @@ function Lt(e, t, n, r) {
945
974
  "stream-type": r
946
975
  },
947
976
  "done",
948
- [x.StreamVideoDone]
977
+ [P.StreamVideoDone]
949
978
  ));
950
979
  }
951
980
  function xt(e, t, n, r, c) {
952
- J.get() <= 0 || (e === p.Start ? r.linkTrack(
981
+ W.get() <= 0 || (e === p.Start ? r.linkTrack(
953
982
  "agent-video",
954
- { event: "start", latency: J.get(!0), "stream-type": c },
983
+ { event: "start", latency: W.get(!0), "stream-type": c },
955
984
  "start",
956
- [x.StreamVideoCreated]
985
+ [P.StreamVideoCreated]
957
986
  ) : e === p.Stop && r.linkTrack(
958
987
  "agent-video",
959
988
  {
@@ -964,17 +993,17 @@ function xt(e, t, n, r, c) {
964
993
  ...n
965
994
  },
966
995
  "done",
967
- [x.StreamVideoDone]
996
+ [P.StreamVideoDone]
968
997
  ));
969
998
  }
970
999
  function we(e, t, n, r) {
971
- return J.reset(), ge.update(), new Promise(async (c, s) => {
1000
+ return W.reset(), ge.update(), new Promise(async (c, s) => {
972
1001
  try {
973
1002
  let o, a = !1;
974
1003
  const i = Pt(e, t);
975
1004
  n.enrich({
976
1005
  "stream-version": i.version.toString()
977
- }), o = await Mt(
1006
+ }), o = await _t(
978
1007
  e,
979
1008
  i,
980
1009
  {
@@ -983,22 +1012,22 @@ function we(e, t, n, r) {
983
1012
  callbacks: {
984
1013
  ...t.callbacks,
985
1014
  onConnectionStateChange: (d) => {
986
- var u, l;
987
- (l = (u = t.callbacks).onConnectionStateChange) == null || l.call(u, d), d === _.Connected && (o ? c(o) : a = !0);
1015
+ var l, u;
1016
+ (u = (l = t.callbacks).onConnectionStateChange) == null || u.call(l, d), d === _.Connected && (o ? c(o) : a = !0);
988
1017
  },
989
- onVideoStateChange: (d, u) => {
990
- var l, v;
991
- (v = (l = t.callbacks).onVideoStateChange) == null || v.call(l, d), jt(
1018
+ onVideoStateChange: (d, l) => {
1019
+ var u, y;
1020
+ (y = (u = t.callbacks).onVideoStateChange) == null || y.call(u, d), jt(
992
1021
  d,
993
1022
  e,
994
- u,
1023
+ l,
995
1024
  n,
996
1025
  o.streamType
997
1026
  );
998
1027
  },
999
1028
  onAgentActivityStateChange: (d) => {
1000
- var u, l;
1001
- (l = (u = t.callbacks).onAgentActivityStateChange) == null || l.call(u, d), d === Z.Talking ? se.update() : se.reset(), Lt(
1029
+ var l, u;
1030
+ (u = (l = t.callbacks).onAgentActivityStateChange) == null || u.call(l, d), d === Z.Talking ? se.update() : se.reset(), $t(
1002
1031
  d === Z.Talking ? p.Start : p.Stop,
1003
1032
  e,
1004
1033
  n,
@@ -1018,48 +1047,48 @@ function we(e, t, n, r) {
1018
1047
  }
1019
1048
  });
1020
1049
  }
1021
- async function $t(e, t, n, r, c) {
1022
- var u, l, v, j;
1050
+ async function Bt(e, t, n, r, c) {
1051
+ var l, u, y, j;
1023
1052
  const s = async () => {
1024
1053
  if (le(e.presenter.type)) {
1025
- const A = await we(e, t, r), W = `${_t}_${A.sessionId}`, P = (/* @__PURE__ */ new Date()).toISOString();
1054
+ const b = await we(e, t, r), U = `${Tt}_${b.sessionId}`, A = (/* @__PURE__ */ new Date()).toISOString();
1026
1055
  return { chatResult: {
1027
1056
  chatMode: E.Functional,
1028
1057
  chat: {
1029
- id: W,
1058
+ id: U,
1030
1059
  agent_id: e.id,
1031
1060
  owner_id: e.owner_id ?? "",
1032
- created: P,
1033
- modified: P,
1034
- agent_id__created_at: P,
1035
- agent_id__modified_at: P,
1061
+ created: A,
1062
+ modified: A,
1063
+ agent_id__created_at: A,
1064
+ agent_id__modified_at: A,
1036
1065
  chat_mode: E.Functional,
1037
1066
  messages: []
1038
1067
  }
1039
- }, streamingManager: A };
1068
+ }, streamingManager: b };
1040
1069
  } else {
1041
- const A = new AbortController(), W = A.signal;
1042
- let P;
1070
+ const b = new AbortController(), U = b.signal;
1071
+ let A;
1043
1072
  try {
1044
- const b = Ie(
1073
+ const L = Ie(
1045
1074
  e,
1046
1075
  n,
1047
1076
  r,
1048
1077
  t.mode,
1049
1078
  t.persistentChat,
1050
1079
  c
1051
- ), $ = we(e, t, r, W).then((V) => (P = V, V)), [S, O] = await Promise.all([b, $]);
1052
- return { chatResult: S, streamingManager: O };
1053
- } catch (b) {
1054
- throw A.abort(), P && await P.disconnect().catch(() => {
1055
- }), b;
1080
+ ), x = we(e, t, r, U).then((q) => (A = q, q)), [R, X] = await Promise.all([L, x]);
1081
+ return { chatResult: R, streamingManager: X };
1082
+ } catch (L) {
1083
+ throw b.abort(), A && await A.disconnect().catch(() => {
1084
+ }), L;
1056
1085
  }
1057
1086
  }
1058
1087
  }, { chatResult: o, streamingManager: a } = await s(), { chat: i, chatMode: d } = o;
1059
- return d && d !== t.mode && (t.mode = d, (l = (u = t.callbacks).onModeChange) == null || l.call(u, d), d !== E.Functional) ? ((j = (v = t.callbacks).onError) == null || j.call(v, new Te(d)), a == null || a.disconnect(), { chat: i }) : { chat: i, streamingManager: a };
1088
+ return d && d !== t.mode && (t.mode = d, (u = (l = t.callbacks).onModeChange) == null || u.call(l, d), d !== E.Functional) ? ((j = (y = t.callbacks).onError) == null || j.call(y, new Te(d)), a == null || a.disconnect(), { chat: i }) : { chat: i, streamingManager: a };
1060
1089
  }
1061
- async function Ft(e, t) {
1062
- var O, V, B;
1090
+ async function Nt(e, t) {
1091
+ var X, q, B;
1063
1092
  let n = !0, r = null;
1064
1093
  const c = t.mixpanelKey || Ue, s = t.wsURL || We, o = t.baseURL || re, a = {
1065
1094
  messages: [],
@@ -1074,41 +1103,41 @@ async function Ft(e, t) {
1074
1103
  fe(() => {
1075
1104
  i.track("agent-sdk", { event: "init" }, d);
1076
1105
  });
1077
- const u = Oe(t.auth, o, t.callbacks.onError, t.externalId), l = await u.getById(e), v = le(l.presenter.type);
1078
- i.enrich(Ye(l));
1079
- const { onMessage: j, clearQueue: A } = lt(
1106
+ const l = Oe(t.auth, o, t.callbacks.onError, t.externalId), u = await l.getById(e), y = le(u.presenter.type);
1107
+ i.enrich(Ye(u));
1108
+ const { onMessage: j, clearQueue: b } = ut(
1080
1109
  i,
1081
1110
  a,
1082
1111
  t,
1083
- l,
1112
+ u,
1084
1113
  () => {
1085
1114
  var m;
1086
1115
  return (m = a.socketManager) == null ? void 0 : m.disconnect();
1087
1116
  }
1088
1117
  );
1089
- a.messages = rt(t.initialMessages), (V = (O = t.callbacks).onNewMessage) == null || V.call(O, [...a.messages], "answer");
1090
- const W = (m) => {
1118
+ a.messages = rt(t.initialMessages), (q = (X = t.callbacks).onNewMessage) == null || q.call(X, [...a.messages], "answer");
1119
+ const U = (m) => {
1091
1120
  r = m;
1092
- }, P = Date.now();
1121
+ }, A = Date.now();
1093
1122
  fe(() => {
1094
- i.track("agent-sdk", { event: "loaded", ...Xe(l) }, P);
1123
+ i.track("agent-sdk", { event: "loaded", ...Xe(u) }, A);
1095
1124
  });
1096
- async function b(m) {
1097
- var L, F, z, I, T, U, D;
1098
- (F = (L = t.callbacks).onConnectionStateChange) == null || F.call(L, _.Connecting), J.reset(), m && !n && (delete a.chat, (I = (z = t.callbacks).onNewMessage) == null || I.call(z, [...a.messages], "answer"));
1099
- const C = t.mode === E.DirectPlayback || v ? Promise.resolve(void 0) : ot(
1125
+ async function L(m) {
1126
+ var $, F, z, I, T, K, D;
1127
+ (F = ($ = t.callbacks).onConnectionStateChange) == null || F.call($, _.Connecting), W.reset(), m && !n && (delete a.chat, (I = (z = t.callbacks).onNewMessage) == null || I.call(z, [...a.messages], "answer"));
1128
+ const v = t.mode === E.DirectPlayback || y ? Promise.resolve(void 0) : ot(
1100
1129
  t.auth,
1101
1130
  s,
1102
1131
  { onMessage: j, onError: t.callbacks.onError },
1103
1132
  t.externalId
1104
- ), y = ae(
1105
- () => $t(
1106
- l,
1133
+ ), k = ae(
1134
+ () => Bt(
1135
+ u,
1107
1136
  {
1108
1137
  ...t,
1109
- callbacks: { ...t.callbacks, onVideoIdChange: W, onMessage: j }
1138
+ callbacks: { ...t.callbacks, onVideoIdChange: U, onMessage: j }
1110
1139
  },
1111
- u,
1140
+ l,
1112
1141
  i,
1113
1142
  a.chat
1114
1143
  ),
@@ -1116,29 +1145,29 @@ async function Ft(e, t) {
1116
1145
  limit: 3,
1117
1146
  timeout: Ne,
1118
1147
  timeoutErrorMessage: "Timeout initializing the stream",
1119
- shouldRetryFn: (R) => (R == null ? void 0 : R.message) !== "Could not connect" && R.status !== 429 && (R == null ? void 0 : R.message) !== "InsufficientCreditsError",
1148
+ shouldRetryFn: (C) => (C == null ? void 0 : C.message) !== "Could not connect" && C.status !== 429 && (C == null ? void 0 : C.message) !== "InsufficientCreditsError",
1120
1149
  delayMs: 1e3
1121
1150
  }
1122
- ).catch((R) => {
1123
- var q, N;
1124
- throw S(E.Maintenance), (N = (q = t.callbacks).onConnectionStateChange) == null || N.call(q, _.Fail), R;
1125
- }), [h, { streamingManager: k, chat: w }] = await Promise.all([C, y]);
1126
- w && w.id !== ((T = a.chat) == null ? void 0 : T.id) && ((D = (U = t.callbacks).onNewChat) == null || D.call(U, w.id)), a.streamingManager = k, a.socketManager = h, a.chat = w, n = !1, i.enrich({
1151
+ ).catch((C) => {
1152
+ var O, N;
1153
+ throw R(E.Maintenance), (N = (O = t.callbacks).onConnectionStateChange) == null || N.call(O, _.Fail), C;
1154
+ }), [h, { streamingManager: S, chat: w }] = await Promise.all([v, k]);
1155
+ w && w.id !== ((T = a.chat) == null ? void 0 : T.id) && ((D = (K = t.callbacks).onNewChat) == null || D.call(K, w.id)), a.streamingManager = S, a.socketManager = h, a.chat = w, n = !1, i.enrich({
1127
1156
  chatId: w == null ? void 0 : w.id,
1128
- streamId: k == null ? void 0 : k.streamId,
1157
+ streamId: S == null ? void 0 : S.streamId,
1129
1158
  mode: a.chatMode
1130
- }), S((w == null ? void 0 : w.chat_mode) ?? t.mode ?? E.Functional);
1159
+ }), R((w == null ? void 0 : w.chat_mode) ?? t.mode ?? E.Functional);
1131
1160
  }
1132
- async function $() {
1133
- var m, C, y, h;
1134
- (m = a.socketManager) == null || m.disconnect(), await ((C = a.streamingManager) == null ? void 0 : C.disconnect()), delete a.streamingManager, delete a.socketManager, (h = (y = t.callbacks).onConnectionStateChange) == null || h.call(y, _.Disconnected);
1161
+ async function x() {
1162
+ var m, v, k, h;
1163
+ (m = a.socketManager) == null || m.disconnect(), await ((v = a.streamingManager) == null ? void 0 : v.disconnect()), delete a.streamingManager, delete a.socketManager, (h = (k = t.callbacks).onConnectionStateChange) == null || h.call(k, _.Disconnected);
1135
1164
  }
1136
- async function S(m) {
1137
- var C, y;
1138
- m !== a.chatMode && (i.track("agent-mode-change", { mode: m }), a.chatMode = m, a.chatMode !== E.Functional && await $(), (y = (C = t.callbacks).onModeChange) == null || y.call(C, m));
1165
+ async function R(m) {
1166
+ var v, k;
1167
+ m !== a.chatMode && (i.track("agent-mode-change", { mode: m }), a.chatMode = m, a.chatMode !== E.Functional && await x(), (k = (v = t.callbacks).onModeChange) == null || k.call(v, m));
1139
1168
  }
1140
1169
  return {
1141
- agent: l,
1170
+ agent: u,
1142
1171
  getStreamType: () => {
1143
1172
  var m;
1144
1173
  return (m = a.streamingManager) == null ? void 0 : m.streamType;
@@ -1151,76 +1180,88 @@ async function Ft(e, t) {
1151
1180
  var m;
1152
1181
  return ((m = a.streamingManager) == null ? void 0 : m.triggersAvailable) ?? !1;
1153
1182
  },
1154
- starterMessages: ((B = l.knowledge) == null ? void 0 : B.starter_message) || [],
1155
- getSTTToken: () => u.getSTTToken(l.id),
1156
- changeMode: S,
1183
+ starterMessages: ((B = u.knowledge) == null ? void 0 : B.starter_message) || [],
1184
+ getSTTToken: () => l.getSTTToken(u.id),
1185
+ changeMode: R,
1157
1186
  enrichAnalytics: i.enrich,
1158
1187
  async connect() {
1159
- await b(!0), i.track("agent-chat", {
1188
+ await L(!0), i.track("agent-chat", {
1160
1189
  event: "connect",
1161
1190
  mode: a.chatMode
1162
1191
  });
1163
1192
  },
1164
1193
  async reconnect() {
1165
- await $(), await b(!1), i.track("agent-chat", {
1194
+ await x(), await L(!1), i.track("agent-chat", {
1166
1195
  event: "reconnect",
1167
1196
  mode: a.chatMode
1168
1197
  });
1169
1198
  },
1170
1199
  async disconnect() {
1171
- await $(), i.track("agent-chat", {
1200
+ await x(), i.track("agent-chat", {
1172
1201
  event: "disconnect",
1173
1202
  mode: a.chatMode
1174
1203
  });
1175
1204
  },
1205
+ async publishMicrophoneStream(m) {
1206
+ var v;
1207
+ if (!((v = a.streamingManager) != null && v.publishMicrophoneStream))
1208
+ throw new Error("publishMicrophoneStream is not available for this streaming manager");
1209
+ return a.streamingManager.publishMicrophoneStream(m);
1210
+ },
1211
+ async unpublishMicrophoneStream() {
1212
+ var m;
1213
+ if (!((m = a.streamingManager) != null && m.unpublishMicrophoneStream))
1214
+ throw new Error("unpublishMicrophoneStream is not available for this streaming manager");
1215
+ return a.streamingManager.unpublishMicrophoneStream();
1216
+ },
1176
1217
  async chat(m) {
1177
- var k, w, L, F, z;
1178
- const C = () => {
1179
- if (Re(t.mode))
1180
- throw new X(`${t.mode} is enabled, chat is disabled`);
1218
+ var S, w, $, F, z;
1219
+ const v = () => {
1220
+ if (Se(t.mode))
1221
+ throw new Y(`${t.mode} is enabled, chat is disabled`);
1181
1222
  if (m.length >= 800)
1182
- throw new X("Message cannot be more than 800 characters");
1223
+ throw new Y("Message cannot be more than 800 characters");
1183
1224
  if (m.length === 0)
1184
- throw new X("Message cannot be empty");
1225
+ throw new Y("Message cannot be empty");
1185
1226
  if (a.chatMode === E.Maintenance)
1186
- throw new X("Chat is in maintenance mode");
1227
+ throw new Y("Chat is in maintenance mode");
1187
1228
  if (![E.TextOnly, E.Playground].includes(a.chatMode)) {
1188
1229
  if (!a.streamingManager)
1189
- throw new X("Streaming manager is not initialized");
1230
+ throw new Y("Streaming manager is not initialized");
1190
1231
  if (!a.chat)
1191
- throw new X("Chat is not initialized");
1232
+ throw new Y("Chat is not initialized");
1192
1233
  }
1193
- }, y = async () => {
1234
+ }, k = async () => {
1194
1235
  var I, T;
1195
1236
  if (!a.chat) {
1196
- const U = await Ie(
1197
- l,
1237
+ const K = await Ie(
1198
1238
  u,
1239
+ l,
1199
1240
  i,
1200
1241
  a.chatMode,
1201
1242
  t.persistentChat
1202
1243
  );
1203
- if (!U.chat)
1244
+ if (!K.chat)
1204
1245
  throw new _e(a.chatMode, !!t.persistentChat);
1205
- a.chat = U.chat, (T = (I = t.callbacks).onNewChat) == null || T.call(I, a.chat.id);
1246
+ a.chat = K.chat, (T = (I = t.callbacks).onNewChat) == null || T.call(I, a.chat.id);
1206
1247
  }
1207
1248
  return a.chat.id;
1208
- }, h = async (I, T) => ae(v ? async () => {
1209
- var D, R;
1210
- return await ((R = (D = a.streamingManager) == null ? void 0 : D.sendTextMessage) == null ? void 0 : R.call(D, m)), Promise.resolve({});
1249
+ }, h = async (I, T) => ae(y ? async () => {
1250
+ var D, C;
1251
+ return await ((C = (D = a.streamingManager) == null ? void 0 : D.sendTextMessage) == null ? void 0 : C.call(D, m)), Promise.resolve({});
1211
1252
  } : async () => {
1212
- var D, R;
1213
- return u.chat(
1214
- l.id,
1253
+ var D, C;
1254
+ return l.chat(
1255
+ u.id,
1215
1256
  T,
1216
1257
  {
1217
1258
  chatMode: a.chatMode,
1218
1259
  streamId: (D = a.streamingManager) == null ? void 0 : D.streamId,
1219
- sessionId: (R = a.streamingManager) == null ? void 0 : R.sessionId,
1220
- messages: I.map(({ matches: q, ...N }) => N)
1260
+ sessionId: (C = a.streamingManager) == null ? void 0 : C.sessionId,
1261
+ messages: I.map(({ matches: O, ...N }) => N)
1221
1262
  },
1222
1263
  {
1223
- ...Se(a.chatMode),
1264
+ ...Re(a.chatMode),
1224
1265
  skipErrorHandler: !0
1225
1266
  }
1226
1267
  );
@@ -1228,21 +1269,21 @@ async function Ft(e, t) {
1228
1269
  limit: 2,
1229
1270
  shouldRetryFn: (D) => {
1230
1271
  var N, f, g, M;
1231
- const R = (N = D == null ? void 0 : D.message) == null ? void 0 : N.includes("missing or invalid session_id");
1232
- return !((f = D == null ? void 0 : D.message) == null ? void 0 : f.includes("Stream Error")) && !R ? ((M = (g = t.callbacks).onError) == null || M.call(g, D), !1) : !0;
1272
+ const C = (N = D == null ? void 0 : D.message) == null ? void 0 : N.includes("missing or invalid session_id");
1273
+ return !((f = D == null ? void 0 : D.message) == null ? void 0 : f.includes("Stream Error")) && !C ? ((M = (g = t.callbacks).onError) == null || M.call(g, D), !1) : !0;
1233
1274
  },
1234
1275
  onRetry: async () => {
1235
- await $(), await b(!1);
1276
+ await x(), await L(!1);
1236
1277
  }
1237
1278
  });
1238
1279
  try {
1239
- A(), C(), a.messages.push({
1280
+ b(), v(), a.messages.push({
1240
1281
  id: Q(),
1241
1282
  role: "user",
1242
1283
  content: m,
1243
- created_at: new Date(J.update()).toISOString()
1244
- }), (w = (k = t.callbacks).onNewMessage) == null || w.call(k, [...a.messages], "user");
1245
- const I = await y(), T = await h([...a.messages], I);
1284
+ created_at: new Date(W.update()).toISOString()
1285
+ }), (w = (S = t.callbacks).onNewMessage) == null || w.call(S, [...a.messages], "user");
1286
+ const I = await k(), T = await h([...a.messages], I);
1246
1287
  return a.messages.push({
1247
1288
  id: Q(),
1248
1289
  role: "assistant",
@@ -1253,8 +1294,8 @@ async function Ft(e, t) {
1253
1294
  }), i.track("agent-message-send", {
1254
1295
  event: "success",
1255
1296
  messages: a.messages.length + 1
1256
- }), T.result && ((F = (L = t.callbacks).onNewMessage) == null || F.call(L, [...a.messages], "answer"), i.track("agent-message-received", {
1257
- latency: J.get(!0),
1297
+ }), T.result && ((F = ($ = t.callbacks).onNewMessage) == null || F.call($, [...a.messages], "answer"), i.track("agent-message-received", {
1298
+ latency: W.get(!0),
1258
1299
  messages: a.messages.length
1259
1300
  })), T;
1260
1301
  } catch (I) {
@@ -1264,69 +1305,69 @@ async function Ft(e, t) {
1264
1305
  }), I;
1265
1306
  }
1266
1307
  },
1267
- rate(m, C, y) {
1268
- var w, L, F, z;
1308
+ rate(m, v, k) {
1309
+ var w, $, F, z;
1269
1310
  const h = a.messages.find((I) => I.id === m);
1270
1311
  if (a.chat) {
1271
1312
  if (!h)
1272
1313
  throw new Error("Message not found");
1273
1314
  } else throw new Error("Chat is not initialized");
1274
- const k = ((w = h.matches) == null ? void 0 : w.map((I) => [I.document_id, I.id])) ?? [];
1315
+ const S = ((w = h.matches) == null ? void 0 : w.map((I) => [I.document_id, I.id])) ?? [];
1275
1316
  return i.track("agent-rate", {
1276
- event: y ? "update" : "create",
1277
- thumb: C === 1 ? "up" : "down",
1278
- knowledge_id: ((L = l.knowledge) == null ? void 0 : L.id) ?? "",
1279
- matches: k,
1280
- score: C
1281
- }), y ? u.updateRating(l.id, a.chat.id, y, {
1282
- knowledge_id: ((F = l.knowledge) == null ? void 0 : F.id) ?? "",
1317
+ event: k ? "update" : "create",
1318
+ thumb: v === 1 ? "up" : "down",
1319
+ knowledge_id: (($ = u.knowledge) == null ? void 0 : $.id) ?? "",
1320
+ matches: S,
1321
+ score: v
1322
+ }), k ? l.updateRating(u.id, a.chat.id, k, {
1323
+ knowledge_id: ((F = u.knowledge) == null ? void 0 : F.id) ?? "",
1283
1324
  message_id: m,
1284
- matches: k,
1285
- score: C
1286
- }) : u.createRating(l.id, a.chat.id, {
1287
- knowledge_id: ((z = l.knowledge) == null ? void 0 : z.id) ?? "",
1325
+ matches: S,
1326
+ score: v
1327
+ }) : l.createRating(u.id, a.chat.id, {
1328
+ knowledge_id: ((z = u.knowledge) == null ? void 0 : z.id) ?? "",
1288
1329
  message_id: m,
1289
- matches: k,
1290
- score: C
1330
+ matches: S,
1331
+ score: v
1291
1332
  });
1292
1333
  },
1293
1334
  deleteRate(m) {
1294
1335
  if (!a.chat)
1295
1336
  throw new Error("Chat is not initialized");
1296
- return i.track("agent-rate-delete", { type: "text" }), u.deleteRating(l.id, a.chat.id, m);
1337
+ return i.track("agent-rate-delete", { type: "text" }), l.deleteRating(u.id, a.chat.id, m);
1297
1338
  },
1298
1339
  async speak(m) {
1299
- var k, w, L;
1300
- function C() {
1340
+ var S, w, $;
1341
+ function v() {
1301
1342
  if (typeof m == "string") {
1302
- if (!l.presenter.voice)
1343
+ if (!u.presenter.voice)
1303
1344
  throw new Error("Presenter voice is not initialized");
1304
1345
  return {
1305
1346
  type: "text",
1306
- provider: l.presenter.voice,
1347
+ provider: u.presenter.voice,
1307
1348
  input: m,
1308
1349
  ssml: !1
1309
1350
  };
1310
1351
  }
1311
1352
  if (m.type === "text" && !m.provider) {
1312
- if (!l.presenter.voice)
1353
+ if (!u.presenter.voice)
1313
1354
  throw new Error("Presenter voice is not initialized");
1314
1355
  return {
1315
1356
  type: "text",
1316
- provider: l.presenter.voice,
1357
+ provider: u.presenter.voice,
1317
1358
  input: m.input,
1318
1359
  ssml: m.ssml
1319
1360
  };
1320
1361
  }
1321
1362
  return m;
1322
1363
  }
1323
- const y = C();
1324
- if (i.track("agent-speak", y), J.update(), a.messages && y.type === "text" && (a.messages.push({
1364
+ const k = v();
1365
+ if (i.track("agent-speak", k), W.update(), a.messages && k.type === "text" && (a.messages.push({
1325
1366
  id: Q(),
1326
1367
  role: "assistant",
1327
- content: y.input,
1368
+ content: k.input,
1328
1369
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1329
- }), (w = (k = t.callbacks).onNewMessage) == null || w.call(k, [...a.messages], "answer")), Ke(a.chatMode))
1370
+ }), (w = (S = t.callbacks).onNewMessage) == null || w.call(S, [...a.messages], "answer")), Ke(a.chatMode))
1330
1371
  return {
1331
1372
  duration: 0,
1332
1373
  video_id: "",
@@ -1335,19 +1376,19 @@ async function Ft(e, t) {
1335
1376
  if (!a.streamingManager)
1336
1377
  throw new Error("Please connect to the agent first");
1337
1378
  return a.streamingManager.speak({
1338
- script: y,
1339
- metadata: { chat_id: (L = a.chat) == null ? void 0 : L.id, agent_id: l.id }
1379
+ script: k,
1380
+ metadata: { chat_id: ($ = a.chat) == null ? void 0 : $.id, agent_id: u.id }
1340
1381
  });
1341
1382
  },
1342
1383
  async interrupt({ type: m }) {
1343
- var y, h, k;
1344
- nt(a.streamingManager, (y = a.streamingManager) == null ? void 0 : y.streamType, r);
1345
- const C = a.messages[a.messages.length - 1];
1384
+ var k, h, S;
1385
+ nt(a.streamingManager, (k = a.streamingManager) == null ? void 0 : k.streamType, r);
1386
+ const v = a.messages[a.messages.length - 1];
1346
1387
  i.track("agent-video-interrupt", {
1347
1388
  type: m || "click",
1348
1389
  video_duration_to_interrupt: se.get(!0),
1349
- message_duration_to_interrupt: J.get(!0)
1350
- }), C.interrupted = !0, (k = (h = t.callbacks).onNewMessage) == null || k.call(h, [...a.messages], "answer"), at(a.streamingManager, r);
1390
+ message_duration_to_interrupt: W.get(!0)
1391
+ }), v.interrupted = !0, (S = (h = t.callbacks).onNewMessage) == null || S.call(h, [...a.messages], "answer"), at(a.streamingManager, r);
1351
1392
  }
1352
1393
  };
1353
1394
  }
@@ -1355,29 +1396,29 @@ export {
1355
1396
  Z as A,
1356
1397
  _ as C,
1357
1398
  Be as D,
1358
- $e as K,
1359
- je as P,
1399
+ xe as K,
1400
+ Pe as P,
1360
1401
  Le as R,
1361
- K as S,
1402
+ H as S,
1362
1403
  de as T,
1363
- Pe as U,
1364
- X as V,
1365
- Ae as W,
1366
- mt as a,
1404
+ Ae as U,
1405
+ Y as V,
1406
+ be as W,
1407
+ ft as a,
1367
1408
  ee as b,
1368
1409
  De as c,
1369
1410
  re as d,
1370
1411
  p as e,
1371
- x as f,
1372
- Y as g,
1412
+ P as f,
1413
+ J as g,
1373
1414
  _e as h,
1374
1415
  Te as i,
1375
- Ft as j,
1376
- be as k,
1416
+ Nt as j,
1417
+ je as k,
1377
1418
  E as l,
1378
- xe as m,
1379
- ve as n,
1380
- zt as o,
1419
+ $e as m,
1420
+ ye as n,
1421
+ Ft as o,
1381
1422
  ze as p,
1382
1423
  Fe as q
1383
1424
  };