@d-id/client-sdk 1.1.26-staging.117 → 1.1.26-staging.120

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- var Oe = Object.defineProperty;
2
- var Ve = (e, t, i) => t in e ? Oe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
- var ue = (e, t, i) => Ve(e, typeof t != "symbol" ? t + "" : t, i);
4
- class ge extends Error {
1
+ var Ve = Object.defineProperty;
2
+ var Oe = (e, t, i) => t in e ? Ve(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
+ var fe = (e, t, i) => Oe(e, typeof t != "symbol" ? t + "" : t, i);
4
+ class pe extends Error {
5
5
  constructor({ kind: i, description: n, error: c }) {
6
6
  super(JSON.stringify({ kind: i, description: n }));
7
- ue(this, "kind");
8
- ue(this, "description");
9
- ue(this, "error");
7
+ fe(this, "kind");
8
+ fe(this, "description");
9
+ fe(this, "error");
10
10
  this.kind = i, this.description = n, this.error = c;
11
11
  }
12
12
  }
13
- class He extends ge {
13
+ class He extends pe {
14
14
  constructor(t, i) {
15
15
  super({
16
16
  kind: "ChatCreationFailed",
@@ -18,24 +18,24 @@ class He extends ge {
18
18
  });
19
19
  }
20
20
  }
21
- class qe extends ge {
21
+ class qe extends pe {
22
22
  constructor(t) {
23
23
  super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
24
24
  }
25
25
  }
26
- class se extends ge {
26
+ class ce extends pe {
27
27
  constructor(i, n) {
28
28
  super({ kind: "ValidationError", description: i });
29
- ue(this, "key");
29
+ fe(this, "key");
30
30
  this.key = n;
31
31
  }
32
32
  }
33
- class Qe extends ge {
33
+ class Qe extends pe {
34
34
  constructor(t) {
35
35
  super({ kind: "WSError", description: t });
36
36
  }
37
37
  }
38
- var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__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))(Ye || {}), Ze = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ze || {}), Ge = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ge || {}), U = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(U || {}), Y = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(Y || {}), et = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(et || {}), tt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(tt || {}), nt = /* @__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))(nt || {}), Be = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Be || {});
38
+ var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__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))(Ye || {}), Ze = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ze || {}), Ge = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ge || {}), J = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(J || {}), Y = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(Y || {}), et = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(et || {}), tt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(tt || {}), nt = /* @__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))(nt || {}), Be = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Be || {});
39
39
  const dn = (e) => {
40
40
  switch (e) {
41
41
  case "clip":
@@ -48,11 +48,11 @@ const dn = (e) => {
48
48
  throw new Error(`Unknown video type: ${e}`);
49
49
  }
50
50
  };
51
- var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), ee = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ee || {}), ae = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(ae || {}), N = /* @__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))(N || {}), S = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(S || {}), ne = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ne || {}), he = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(he || {}), rt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(rt || {}), it = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(it || {});
52
- const at = 45 * 1e3, ot = "X-Playground-Chat", fe = "https://api.d-id.com", st = "wss://notifications.d-id.com", ct = "79f81a83a67430be2bc0fd61042b8faa", Fe = (e) => new Promise((t) => setTimeout(t, e)), ce = (e = 16) => {
51
+ var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), G = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(G || {}), ae = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Talking = "TALKING", e))(ae || {}), z = /* @__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))(z || {}), S = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(S || {}), te = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(te || {}), we = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(we || {}), rt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(rt || {}), it = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(it || {});
52
+ const at = 45 * 1e3, ot = "X-Playground-Chat", ge = "https://api.d-id.com", st = "wss://notifications.d-id.com", ct = "79f81a83a67430be2bc0fd61042b8faa", Fe = (e) => new Promise((t) => setTimeout(t, e)), de = (e = 16) => {
53
53
  const t = new Uint8Array(e);
54
54
  return window.crypto.getRandomValues(t), Array.from(t, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
55
- }, ze = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Ee = (e) => e === Be.Expressive, dt = (e) => [U.TextOnly, U.Playground, U.Maintenance].includes(e), Ne = (e) => e && [U.DirectPlayback, U.Off].includes(e);
55
+ }, ze = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Ee = (e) => e === Be.Expressive, dt = (e) => [J.TextOnly, J.Playground, J.Maintenance].includes(e), Ne = (e) => e && [J.DirectPlayback, J.Off].includes(e);
56
56
  function ut(e, t) {
57
57
  let i;
58
58
  return {
@@ -62,7 +62,7 @@ function ut(e, t) {
62
62
  clear: () => clearTimeout(i)
63
63
  };
64
64
  }
65
- async function ve(e, t) {
65
+ async function Se(e, t) {
66
66
  const i = {
67
67
  limit: (t == null ? void 0 : t.limit) ?? 3,
68
68
  delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
@@ -86,33 +86,33 @@ async function ve(e, t) {
86
86
  }
87
87
  throw n;
88
88
  }
89
- function Se(e) {
89
+ function Ce(e) {
90
90
  if (e !== void 0)
91
91
  return window.localStorage.setItem("did_external_key_id", e), e;
92
92
  let t = window.localStorage.getItem("did_external_key_id");
93
93
  if (!t) {
94
- let i = ce();
94
+ let i = de();
95
95
  window.localStorage.setItem("did_external_key_id", i), t = i;
96
96
  }
97
97
  return t;
98
98
  }
99
- let lt = ce();
99
+ let lt = de();
100
100
  function Ke(e, t) {
101
101
  if (e.type === "bearer")
102
102
  return `Bearer ${e.token}`;
103
103
  if (e.type === "basic")
104
104
  return `Basic ${btoa(`${e.username}:${e.password}`)}`;
105
105
  if (e.type === "key")
106
- return `Client-Key ${e.clientKey}.${Se(t)}_${lt}`;
106
+ return `Client-Key ${e.clientKey}.${Ce(t)}_${lt}`;
107
107
  throw new Error(`Unknown auth type: ${e}`);
108
108
  }
109
- const ft = (e) => ve(e, {
109
+ const ft = (e) => Se(e, {
110
110
  limit: 3,
111
111
  delayMs: 1e3,
112
112
  timeout: 0,
113
113
  shouldRetryFn: (t) => t.status === 429
114
114
  });
115
- function Me(e, t = fe, i, n) {
115
+ function Ie(e, t = ge, i, n) {
116
116
  const c = async (o, s) => {
117
117
  const { skipErrorHandler: a, ...r } = s || {}, d = await ft(
118
118
  () => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
@@ -146,8 +146,8 @@ function Me(e, t = fe, i, n) {
146
146
  }
147
147
  };
148
148
  }
149
- function mt(e, t = fe, i, n) {
150
- const c = Me(e, `${t}/agents`, i, n);
149
+ function mt(e, t = ge, i, n) {
150
+ const c = Ie(e, `${t}/agents`, i, n);
151
151
  return {
152
152
  create(o, s) {
153
153
  return c.post("/", o, s);
@@ -240,20 +240,20 @@ function wt(e, t, i) {
240
240
  function be(e) {
241
241
  "requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
242
242
  }
243
- let we = {};
243
+ let ye = {};
244
244
  const yt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
245
245
  function vt(e) {
246
246
  const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk";
247
247
  return {
248
248
  token: e.token || "testKey",
249
- distinct_id: Se(e.externalId),
249
+ distinct_id: Ce(e.externalId),
250
250
  agentId: e.agentId,
251
251
  additionalProperties: {
252
- id: Se(e.externalId),
252
+ id: Ce(e.externalId),
253
253
  ...e.mixpanelAdditionalProperties || {}
254
254
  },
255
255
  isEnabled: e.isEnabled ?? !0,
256
- getRandom: ce,
256
+ getRandom: de,
257
257
  enrich(i) {
258
258
  this.additionalProperties = { ...this.additionalProperties, ...i };
259
259
  },
@@ -292,8 +292,8 @@ function vt(e) {
292
292
  }).catch((d) => console.error("Analytics tracking error:", d)), Promise.resolve();
293
293
  },
294
294
  linkTrack(i, n, c, o) {
295
- we[i] || (we[i] = { events: {}, resolvedDependencies: [] }), o.includes(c) || o.push(c);
296
- const s = we[i];
295
+ ye[i] || (ye[i] = { events: {}, resolvedDependencies: [] }), o.includes(c) || o.push(c);
296
+ const s = ye[i];
297
297
  if (s.events[c] = { props: n }, s.resolvedDependencies.push(c), o.every(
298
298
  (r) => s.resolvedDependencies.includes(r)
299
299
  )) {
@@ -307,7 +307,7 @@ function vt(e) {
307
307
  }
308
308
  };
309
309
  }
310
- function Ie() {
310
+ function Te() {
311
311
  let e = 0;
312
312
  return {
313
313
  reset: () => e = 0,
@@ -315,9 +315,9 @@ function Ie() {
315
315
  get: (t = !1) => t ? Date.now() - e : e
316
316
  };
317
317
  }
318
- const te = Ie(), Ce = Ie(), je = Ie();
318
+ const ee = Te(), ke = Te(), je = Te();
319
319
  function Je(e) {
320
- return e === U.Playground ? { headers: { [ot]: "true" } } : {};
320
+ return e === J.Playground ? { headers: { [ot]: "true" } } : {};
321
321
  }
322
322
  async function Ue(e, t, i, n, c = !1, o) {
323
323
  try {
@@ -342,7 +342,7 @@ function Ct(e) {
342
342
  return e && e.length > 0 ? e : [];
343
343
  }
344
344
  function kt(e, t, i, n) {
345
- const c = Me(e, `${t}/v2/agents/${i}`, n);
345
+ const c = Ie(e, `${t}/v2/agents/${i}`, n);
346
346
  return {
347
347
  async createStream(o) {
348
348
  return c.post("/sessions", o);
@@ -350,7 +350,7 @@ function kt(e, t, i, n) {
350
350
  };
351
351
  }
352
352
  const We = (e, t) => (i, n) => e && console.log(`[${t}] ${i}`, n ?? "");
353
- async function ye() {
353
+ async function ve() {
354
354
  try {
355
355
  return await import("./livekit-client.esm-C1GRQdZY.js");
356
356
  } catch {
@@ -360,92 +360,92 @@ async function ye() {
360
360
  }
361
361
  }
362
362
  const Rt = {
363
- excellent: ee.Strong,
364
- good: ee.Strong,
365
- poor: ee.Weak,
366
- lost: ee.Unknown,
367
- unknown: ee.Unknown
368
- }, le = JSON.stringify({
363
+ excellent: G.Strong,
364
+ good: G.Strong,
365
+ poor: G.Weak,
366
+ lost: G.Unknown,
367
+ unknown: G.Unknown
368
+ }, me = JSON.stringify({
369
369
  kind: "InternalServerError",
370
370
  description: "Stream Error"
371
371
  });
372
- var Te = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Te || {});
373
- function ke(e, t, i, n) {
372
+ var _e = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(_e || {});
373
+ function Re(e, t, i, n) {
374
374
  var c, o;
375
375
  throw t("Failed to connect to LiveKit room:", e), n(), (c = i.onConnectionStateChange) == null || c.call(i, S.Fail), (o = i.onError) == null || o.call(i, e, { sessionId: "" }), e;
376
376
  }
377
377
  async function Dt(e, t, i) {
378
- var _e, Ae;
379
- const n = We(i.debug || !1, "LiveKitStreamingManager"), { Room: c, RoomEvent: o, ConnectionState: s } = await ye(), { callbacks: a, auth: r, baseURL: d, analytics: m, microphoneStream: p } = i;
380
- let u = null, M = !1;
381
- const x = ne.Fluent;
382
- let O = !0, I = null, A = null;
378
+ var ue, Ae;
379
+ const n = We(i.debug || !1, "LiveKitStreamingManager"), { Room: c, RoomEvent: o, ConnectionState: s } = await ve(), { callbacks: a, auth: r, baseURL: d, analytics: m, microphoneStream: p } = i;
380
+ let u = null, E = !1;
381
+ const x = te.Fluent;
382
+ let V = !0, I = null, A = null;
383
383
  u = new c({
384
384
  adaptiveStream: !1,
385
385
  // Must be false to use mediaStreamTrack directly
386
386
  dynacast: !0
387
387
  });
388
388
  let L = null;
389
- const T = 2e4, re = kt(r, d || fe, e, a.onError);
390
- let B, K, X;
389
+ const T = 2e4, ne = kt(r, d || ge, e, a.onError);
390
+ let B, N, X;
391
391
  try {
392
- const l = await re.createStream({
393
- transport_provider: he.Livekit,
392
+ const l = await ne.createStream({
393
+ transport_provider: we.Livekit,
394
394
  chat_persist: t.chat_persist ?? !0
395
- }), { id: g, session_token: v, session_url: k } = l;
396
- (_e = a.onStreamCreated) == null || _e.call(a, { session_id: g, stream_id: g, agent_id: e }), B = g, K = v, X = k, await u.prepareConnection(X, K);
395
+ }), { id: h, session_token: v, session_url: k } = l;
396
+ (ue = a.onStreamCreated) == null || ue.call(a, { session_id: h, stream_id: h, agent_id: e }), B = h, N = v, X = k, await u.prepareConnection(X, N);
397
397
  } catch (l) {
398
- ke(l, n, a, () => {
399
- O = !1;
398
+ Re(l, n, a, () => {
399
+ V = !1;
400
400
  });
401
401
  }
402
- if (!X || !K || !B)
402
+ if (!X || !N || !B)
403
403
  return Promise.reject(new Error("Failed to initialize LiveKit stream"));
404
- u.on(o.ConnectionStateChanged, f).on(o.ConnectionQualityChanged, R).on(o.ActiveSpeakersChanged, y).on(o.ParticipantConnected, $).on(o.ParticipantDisconnected, D).on(o.TrackSubscribed, _).on(o.TrackUnsubscribed, W).on(o.DataReceived, H).on(o.MediaDevicesError, q).on(o.EncryptionError, j).on(o.TrackSubscriptionFailed, J), (Ae = a.onConnectionStateChange) == null || Ae.call(a, S.New);
404
+ u.on(o.ConnectionStateChanged, f).on(o.ConnectionQualityChanged, R).on(o.ActiveSpeakersChanged, w).on(o.ParticipantConnected, $).on(o.ParticipantDisconnected, D).on(o.TrackSubscribed, _).on(o.TrackUnsubscribed, U).on(o.DataReceived, H).on(o.MediaDevicesError, q).on(o.EncryptionError, b).on(o.TrackSubscriptionFailed, K), (Ae = a.onConnectionStateChange) == null || Ae.call(a, S.New);
405
405
  try {
406
- await u.connect(X, K), n("LiveKit room joined successfully"), L = setTimeout(() => {
406
+ await u.connect(X, N), n("LiveKit room joined successfully"), L = setTimeout(() => {
407
407
  var l;
408
408
  n("Track subscription timeout - no track subscribed within 30 seconds after connect"), L = null, m.track("connectivity-error", {
409
409
  error: "Track subscription timeout",
410
410
  sessionId: B
411
- }), (l = a.onError) == null || l.call(a, new Error("Track subscription timeout"), { sessionId: B }), pe();
412
- }, T), O = !1;
411
+ }), (l = a.onError) == null || l.call(a, new Error("Track subscription timeout"), { sessionId: B }), se();
412
+ }, T), V = !1;
413
413
  } catch (l) {
414
- ke(l, n, a, () => {
415
- O = !1;
414
+ Re(l, n, a, () => {
415
+ V = !1;
416
416
  });
417
417
  }
418
418
  m.enrich({
419
419
  "stream-type": x
420
420
  });
421
421
  function f(l) {
422
- var g, v, k, b, V;
422
+ var h, v, k, P, O;
423
423
  switch (n("Connection state changed:", l), l) {
424
424
  case s.Connecting:
425
- (g = a.onConnectionStateChange) == null || g.call(a, S.Connecting);
425
+ (h = a.onConnectionStateChange) == null || h.call(a, S.Connecting);
426
426
  break;
427
427
  case s.Connected:
428
- n("LiveKit room connected successfully"), M = !0, O ? queueMicrotask(() => {
429
- var z;
430
- (z = a.onConnectionStateChange) == null || z.call(a, S.Connected);
428
+ n("LiveKit room connected successfully"), E = !0, V ? queueMicrotask(() => {
429
+ var F;
430
+ (F = a.onConnectionStateChange) == null || F.call(a, S.Connected);
431
431
  }) : (v = a.onConnectionStateChange) == null || v.call(a, S.Connected);
432
432
  break;
433
433
  case s.Disconnected:
434
- n("LiveKit room disconnected"), M = !1, (k = a.onConnectionStateChange) == null || k.call(a, S.Disconnected);
434
+ n("LiveKit room disconnected"), E = !1, (k = a.onConnectionStateChange) == null || k.call(a, S.Disconnected);
435
435
  break;
436
436
  case s.Reconnecting:
437
- n("LiveKit room reconnecting..."), (b = a.onConnectionStateChange) == null || b.call(a, S.Connecting);
437
+ n("LiveKit room reconnecting..."), (P = a.onConnectionStateChange) == null || P.call(a, S.Connecting);
438
438
  break;
439
439
  case s.SignalReconnecting:
440
- n("LiveKit room signal reconnecting..."), (V = a.onConnectionStateChange) == null || V.call(a, S.Connecting);
440
+ n("LiveKit room signal reconnecting..."), (O = a.onConnectionStateChange) == null || O.call(a, S.Connecting);
441
441
  break;
442
442
  }
443
443
  }
444
- function R(l, g) {
444
+ function R(l, h) {
445
445
  var v;
446
- n("Connection quality:", l), g != null && g.isLocal && ((v = a.onConnectivityStateChange) == null || v.call(a, Rt[l]));
446
+ n("Connection quality:", l), h != null && h.isLocal && ((v = a.onConnectivityStateChange) == null || v.call(a, Rt[l]));
447
447
  }
448
- function y(l) {
448
+ function w(l) {
449
449
  var v, k;
450
450
  n("Active speakers changed:", l), l[0] ? (v = a.onAgentActivityStateChange) == null || v.call(a, ae.Talking) : (k = a.onAgentActivityStateChange) == null || k.call(a, ae.Idle);
451
451
  }
@@ -453,42 +453,42 @@ async function Dt(e, t, i) {
453
453
  n("Participant connected:", l.identity);
454
454
  }
455
455
  function D(l) {
456
- n("Participant disconnected:", l.identity), pe();
456
+ n("Participant disconnected:", l.identity), se();
457
457
  }
458
- function _(l, g, v) {
459
- var b, V, z;
458
+ function _(l, h, v) {
459
+ var P, O, F;
460
460
  n(`Track subscribed: ${l.kind} from ${v.identity}`), L && (clearTimeout(L), L = null, n("Track subscription timeout cleared"));
461
461
  const k = l.mediaStreamTrack;
462
462
  if (!k) {
463
463
  n(`No mediaStreamTrack available for ${l.kind}`);
464
464
  return;
465
465
  }
466
- I ? (I.addTrack(k), n(`Added ${l.kind} track to shared MediaStream`)) : (I = new MediaStream([k]), n(`Created shared MediaStream with ${l.kind} track`)), l.kind === "video" && ((b = a.onStreamReady) == null || b.call(a), (V = a.onSrcObjectReady) == null || V.call(a, I), (z = a.onVideoStateChange) == null || z.call(a, C.Start));
466
+ I ? (I.addTrack(k), n(`Added ${l.kind} track to shared MediaStream`)) : (I = new MediaStream([k]), n(`Created shared MediaStream with ${l.kind} track`)), l.kind === "video" && ((P = a.onStreamReady) == null || P.call(a), (O = a.onSrcObjectReady) == null || O.call(a, I), (F = a.onVideoStateChange) == null || F.call(a, C.Start));
467
467
  }
468
- function W(l, g, v) {
468
+ function U(l, h, v) {
469
469
  var k;
470
470
  n(`Track unsubscribed: ${l.kind} from ${v.identity}`), l.kind === "video" && ((k = a.onVideoStateChange) == null || k.call(a, C.Stop));
471
471
  }
472
- function H(l, g, v, k) {
473
- var V, z, de;
474
- const b = new TextDecoder().decode(l);
475
- n("Data received:", b);
472
+ function H(l, h, v, k) {
473
+ var O, F, le;
474
+ const P = new TextDecoder().decode(l);
475
+ n("Data received:", P);
476
476
  try {
477
- const ie = JSON.parse(b), me = k || ie.subject;
478
- if (me === N.ChatAnswer) {
477
+ const ie = JSON.parse(P), he = k || ie.subject;
478
+ if (he === z.ChatAnswer) {
479
479
  const oe = Y.Answer;
480
- (V = a.onMessage) == null || V.call(a, oe, {
480
+ (O = a.onMessage) == null || O.call(a, oe, {
481
481
  event: oe,
482
482
  ...ie
483
483
  });
484
- } else if ([N.StreamVideoCreated, N.StreamVideoDone].includes(me)) {
485
- const oe = (ie == null ? void 0 : ie.role) || (g == null ? void 0 : g.identity) || "datachannel";
486
- (z = a.onMessage) == null || z.call(a, me, {
484
+ } else if ([z.StreamVideoCreated, z.StreamVideoDone].includes(he)) {
485
+ const oe = (ie == null ? void 0 : ie.role) || (h == null ? void 0 : h.identity) || "datachannel";
486
+ (F = a.onMessage) == null || F.call(a, he, {
487
487
  [oe]: ie
488
488
  });
489
- } else if (me === N.ChatAudioTranscribed) {
489
+ } else if (he === z.ChatAudioTranscribed) {
490
490
  const oe = Y.Transcribe;
491
- (de = a.onMessage) == null || de.call(a, oe, {
491
+ (le = a.onMessage) == null || le.call(a, oe, {
492
492
  event: oe,
493
493
  ...ie
494
494
  });
@@ -498,62 +498,62 @@ async function Dt(e, t, i) {
498
498
  }
499
499
  }
500
500
  function q(l) {
501
- var g;
502
- n("Media devices error:", l), (g = a.onError) == null || g.call(a, new Error(le), { sessionId: B });
501
+ var h;
502
+ n("Media devices error:", l), (h = a.onError) == null || h.call(a, new Error(me), { sessionId: B });
503
503
  }
504
- function j(l) {
505
- var g;
506
- n("Encryption error:", l), (g = a.onError) == null || g.call(a, new Error(le), { sessionId: B });
504
+ function b(l) {
505
+ var h;
506
+ n("Encryption error:", l), (h = a.onError) == null || h.call(a, new Error(me), { sessionId: B });
507
507
  }
508
- function J(l, g, v) {
509
- n("Track subscription failed:", { trackSid: l, participant: g, reason: v });
508
+ function K(l, h, v) {
509
+ n("Track subscription failed:", { trackSid: l, participant: h, reason: v });
510
510
  }
511
- async function G(l) {
511
+ async function Z(l) {
512
512
  if (!u) return null;
513
- const { Track: g } = await ye(), v = u.localParticipant.audioTrackPublications;
513
+ const { Track: h } = await ve(), v = u.localParticipant.audioTrackPublications;
514
514
  if (v) {
515
- for (const [k, b] of v)
516
- if (b.source === g.Source.Microphone && b.track) {
517
- const z = b.track.mediaStreamTrack;
518
- if (z === l || z && z.id === l.id)
519
- return b;
515
+ for (const [k, P] of v)
516
+ if (P.source === h.Source.Microphone && P.track) {
517
+ const F = P.track.mediaStreamTrack;
518
+ if (F === l || F && F.id === l.id)
519
+ return P;
520
520
  }
521
521
  }
522
522
  return null;
523
523
  }
524
- function E(l) {
524
+ function re(l) {
525
525
  if (!A || !A.track)
526
526
  return !1;
527
- const g = A.track.mediaStreamTrack;
528
- return g !== l && (g == null ? void 0 : g.id) !== l.id;
527
+ const h = A.track.mediaStreamTrack;
528
+ return h !== l && (h == null ? void 0 : h.id) !== l.id;
529
529
  }
530
- async function P(l) {
531
- var V, z;
532
- if (!M || !u)
530
+ async function W(l) {
531
+ var O, F;
532
+ if (!E || !u)
533
533
  throw n("Room is not connected, cannot publish microphone stream"), new Error("Room is not connected");
534
- const g = l.getAudioTracks();
535
- if (g.length === 0) {
534
+ const h = l.getAudioTracks();
535
+ if (h.length === 0) {
536
536
  n("No audio track found in the provided MediaStream");
537
537
  return;
538
538
  }
539
- const v = g[0], { Track: k } = await ye(), b = await G(v);
540
- if (b) {
539
+ const v = h[0], { Track: k } = await ve(), P = await Z(v);
540
+ if (P) {
541
541
  n("Microphone track is already published, skipping", {
542
542
  trackId: v.id,
543
- publishedTrackId: (z = (V = b.track) == null ? void 0 : V.mediaStreamTrack) == null ? void 0 : z.id
544
- }), A = b;
543
+ publishedTrackId: (F = (O = P.track) == null ? void 0 : O.mediaStreamTrack) == null ? void 0 : F.id
544
+ }), A = P;
545
545
  return;
546
546
  }
547
- E(v) && (n("Unpublishing existing microphone track before publishing new one"), await Z()), n("Publishing microphone track from provided MediaStream", { trackId: v.id });
547
+ re(v) && (n("Unpublishing existing microphone track before publishing new one"), await M()), n("Publishing microphone track from provided MediaStream", { trackId: v.id });
548
548
  try {
549
549
  A = await u.localParticipant.publishTrack(v, {
550
550
  source: k.Source.Microphone
551
551
  }), n("Microphone track published successfully", { trackSid: A.trackSid });
552
- } catch (de) {
553
- throw n("Failed to publish microphone track:", de), de;
552
+ } catch (le) {
553
+ throw n("Failed to publish microphone track:", le), le;
554
554
  }
555
555
  }
556
- async function Z() {
556
+ async function M() {
557
557
  if (!(!A || !A.track))
558
558
  try {
559
559
  u && (await u.localParticipant.unpublishTrack(A.track), n("Microphone track unpublished"));
@@ -563,84 +563,84 @@ async function Dt(e, t, i) {
563
563
  A = null;
564
564
  }
565
565
  }
566
- function h() {
566
+ function g() {
567
567
  I && (I.getTracks().forEach((l) => l.stop()), I = null);
568
568
  }
569
- async function w(l, g) {
569
+ async function y(l, h) {
570
570
  var v, k;
571
- if (!M || !u) {
572
- n("Room is not connected for sending messages"), (v = a.onError) == null || v.call(a, new Error(le), {
571
+ if (!E || !u) {
572
+ n("Room is not connected for sending messages"), (v = a.onError) == null || v.call(a, new Error(me), {
573
573
  sessionId: B
574
574
  });
575
575
  return;
576
576
  }
577
577
  try {
578
- await u.localParticipant.sendText(l, { topic: g }), n("Message sent successfully:", l);
579
- } catch (b) {
580
- n("Failed to send message:", b), (k = a.onError) == null || k.call(a, new Error(le), { sessionId: B });
578
+ await u.localParticipant.sendText(l, { topic: h }), n("Message sent successfully:", l);
579
+ } catch (P) {
580
+ n("Failed to send message:", P), (k = a.onError) == null || k.call(a, new Error(me), { sessionId: B });
581
581
  }
582
582
  }
583
- async function F(l) {
584
- var g;
583
+ async function j(l) {
584
+ var h;
585
585
  try {
586
586
  const k = JSON.parse(l).topic;
587
- return w("", k);
587
+ return y("", k);
588
588
  } catch (v) {
589
- n("Failed to send data channel message:", v), (g = a.onError) == null || g.call(a, new Error(le), { sessionId: B });
589
+ n("Failed to send data channel message:", v), (h = a.onError) == null || h.call(a, new Error(me), { sessionId: B });
590
590
  }
591
591
  }
592
592
  function Q(l) {
593
- return w(
593
+ return y(
594
594
  l,
595
595
  "lk.chat"
596
596
  /* Chat */
597
597
  );
598
598
  }
599
- async function pe() {
600
- var l, g;
601
- L && (clearTimeout(L), L = null), u && (await Z(), await u.disconnect()), h(), M = !1, (l = a.onConnectionStateChange) == null || l.call(a, S.Disconnected), (g = a.onAgentActivityStateChange) == null || g.call(a, ae.Idle);
599
+ async function se() {
600
+ var l, h;
601
+ L && (clearTimeout(L), L = null), u && (await M(), await u.disconnect()), g(), E = !1, (l = a.onConnectionStateChange) == null || l.call(a, S.Disconnected), (h = a.onAgentActivityStateChange) == null || h.call(a, ae.Idle);
602
602
  }
603
603
  return {
604
604
  speak(l) {
605
- const g = typeof l == "string" ? l : JSON.stringify(l);
606
- return w(
607
- g,
605
+ const h = typeof l == "string" ? l : JSON.stringify(l);
606
+ return y(
607
+ h,
608
608
  "did.speak"
609
609
  /* Speak */
610
610
  );
611
611
  },
612
- disconnect: pe,
612
+ disconnect: se,
613
613
  async reconnect() {
614
- var l, g, v;
614
+ var l, h, v;
615
615
  if ((u == null ? void 0 : u.state) === s.Connected) {
616
616
  n("Room is already connected");
617
617
  return;
618
618
  }
619
- if (!u || !X || !K)
619
+ if (!u || !X || !N)
620
620
  throw n("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
621
621
  n("Reconnecting to LiveKit room, state:", u.state), (l = a.onConnectionStateChange) == null || l.call(a, S.Connecting);
622
622
  try {
623
- if (await u.connect(X, K), n("Room reconnected"), M = !0, u.remoteParticipants.size === 0) {
624
- if (n("Waiting for agent to join..."), !await new Promise((b) => {
625
- const V = setTimeout(() => {
626
- u == null || u.off(o.ParticipantConnected, z), b(!1);
627
- }, 5e3), z = () => {
628
- clearTimeout(V), u == null || u.off(o.ParticipantConnected, z), b(!0);
623
+ if (await u.connect(X, N), n("Room reconnected"), E = !0, u.remoteParticipants.size === 0) {
624
+ if (n("Waiting for agent to join..."), !await new Promise((P) => {
625
+ const O = setTimeout(() => {
626
+ u == null || u.off(o.ParticipantConnected, F), P(!1);
627
+ }, 5e3), F = () => {
628
+ clearTimeout(O), u == null || u.off(o.ParticipantConnected, F), P(!0);
629
629
  };
630
- u == null || u.on(o.ParticipantConnected, z);
630
+ u == null || u.on(o.ParticipantConnected, F);
631
631
  }))
632
632
  throw n("Agent did not join within timeout"), await u.disconnect(), new Error("Agent did not rejoin the room");
633
633
  n("Agent joined");
634
634
  }
635
- (g = a.onConnectionStateChange) == null || g.call(a, S.Connected);
635
+ (h = a.onConnectionStateChange) == null || h.call(a, S.Connected);
636
636
  } catch (k) {
637
637
  throw n("Failed to reconnect:", k), (v = a.onConnectionStateChange) == null || v.call(a, S.Fail), k;
638
638
  }
639
639
  },
640
- sendDataChannelMessage: F,
640
+ sendDataChannelMessage: j,
641
641
  sendTextMessage: Q,
642
- publishMicrophoneStream: P,
643
- unpublishMicrophoneStream: Z,
642
+ publishMicrophoneStream: W,
643
+ unpublishMicrophoneStream: M,
644
644
  sessionId: B,
645
645
  streamId: B,
646
646
  streamType: x,
@@ -648,25 +648,25 @@ async function Dt(e, t, i) {
648
648
  triggersAvailable: !1
649
649
  };
650
650
  }
651
- const Et = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
651
+ const Mt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
652
652
  __proto__: null,
653
- DataChannelTopic: Te,
653
+ DataChannelTopic: _e,
654
654
  createLiveKitStreamingManager: Dt,
655
- handleInitError: ke
655
+ handleInitError: Re
656
656
  }, Symbol.toStringTag, { value: "Module" }));
657
- function Mt(e, t, i) {
657
+ function Et(e, t, i) {
658
658
  if (!e)
659
659
  throw new Error("Please connect to the agent first");
660
660
  if (!e.interruptAvailable)
661
661
  throw new Error("Interrupt is not enabled for this stream");
662
- if (t !== ne.Fluent)
662
+ if (t !== te.Fluent)
663
663
  throw new Error("Interrupt only available for Fluent streams");
664
664
  if (!i)
665
665
  throw new Error("No active video to interrupt");
666
666
  }
667
667
  async function It(e, t) {
668
668
  const i = {
669
- type: N.StreamInterrupt,
669
+ type: z.StreamInterrupt,
670
670
  videoId: t,
671
671
  timestamp: Date.now()
672
672
  };
@@ -674,7 +674,7 @@ async function It(e, t) {
674
674
  }
675
675
  async function Tt(e) {
676
676
  const t = {
677
- topic: Te.Interrupt
677
+ topic: _e.Interrupt
678
678
  };
679
679
  e.sendDataChannelMessage(JSON.stringify(t));
680
680
  }
@@ -777,18 +777,18 @@ function $t(e, t, i, n, c) {
777
777
  onMessage: (s, a) => {
778
778
  var r, d;
779
779
  if ("content" in a) {
780
- const m = s === N.ChatAnswer ? Y.Answer : s === N.ChatAudioTranscribed ? Y.Transcribe : s;
780
+ const m = s === z.ChatAnswer ? Y.Answer : s === z.ChatAudioTranscribed ? Y.Transcribe : s;
781
781
  Lt(m, a, o, t, i.callbacks.onNewMessage), m === Y.Answer && e.track("agent-message-received", {
782
782
  messages: t.messages.length,
783
783
  mode: t.chatMode
784
784
  });
785
785
  } else {
786
- const m = N, p = [m.StreamVideoDone, m.StreamVideoError, m.StreamVideoRejected], u = [m.StreamFailed, m.StreamVideoError, m.StreamVideoRejected], M = wt(a, n, { mode: t.chatMode });
786
+ const m = z, p = [m.StreamVideoDone, m.StreamVideoError, m.StreamVideoRejected], u = [m.StreamFailed, m.StreamVideoError, m.StreamVideoRejected], E = wt(a, n, { mode: t.chatMode });
787
787
  if (s = s, s === m.StreamVideoCreated)
788
- e.linkTrack("agent-video", M, m.StreamVideoCreated, ["start"]);
788
+ e.linkTrack("agent-video", E, m.StreamVideoCreated, ["start"]);
789
789
  else if (p.includes(s)) {
790
790
  const x = s.split("/")[1];
791
- u.includes(s) ? e.track("agent-video", { ...M, event: x }) : e.linkTrack("agent-video", { ...M, event: x }, s, ["done"]);
791
+ u.includes(s) ? e.track("agent-video", { ...E, event: x }) : e.linkTrack("agent-video", { ...E, event: x }, s, ["done"]);
792
792
  }
793
793
  u.includes(s) && ((d = (r = i.callbacks).onError) == null || d.call(r, new Error(`Stream failed with event ${s}`), { data: a })), a.event === m.StreamDone && c();
794
794
  }
@@ -796,7 +796,7 @@ function $t(e, t, i, n, c) {
796
796
  };
797
797
  }
798
798
  function xt(e, t, i, n) {
799
- const c = Me(e, `${t}/agents/${i}`, n);
799
+ const c = Ie(e, `${t}/agents/${i}`, n);
800
800
  return {
801
801
  createStream(o, s) {
802
802
  return c.post("/streams", o, { signal: s });
@@ -961,7 +961,7 @@ function Nt(e, t, i) {
961
961
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
962
962
  };
963
963
  }
964
- const Re = 100, Kt = Math.max(Math.ceil(400 / Re), 1), Jt = 0.25, Ut = 0.28;
964
+ const De = 100, Kt = Math.max(Math.ceil(400 / De), 1), Jt = 0.25, Ut = 0.28;
965
965
  function Wt() {
966
966
  let e = 0, t, i, n = 0;
967
967
  return (c) => {
@@ -979,20 +979,20 @@ function Wt() {
979
979
  return { isReceiving: !1, avgJitterDelayInInterval: n };
980
980
  };
981
981
  }
982
- function Ot(e, t, i, n, c) {
983
- let o = [], s, a = 0, r = !1, d = ee.Unknown, m = ee.Unknown, p = 0, u = 0;
984
- const M = Wt();
982
+ function Vt(e, t, i, n, c) {
983
+ let o = [], s, a = 0, r = !1, d = G.Unknown, m = G.Unknown, p = 0, u = 0;
984
+ const E = Wt();
985
985
  return setInterval(async () => {
986
- const x = await e.getStats(), { isReceiving: O, avgJitterDelayInInterval: I, freezeCount: A } = M(x), L = zt(x);
987
- if (O)
988
- a = 0, p = A - u, m = I < Jt ? ee.Strong : I > Ut && p > 1 ? ee.Weak : d, m !== d && (c == null || c(m), d = m, u += p, p = 0), r || (n == null || n(C.Start), s = o[o.length - 1], o = [], r = !0), o.push(L);
986
+ const x = await e.getStats(), { isReceiving: V, avgJitterDelayInInterval: I, freezeCount: A } = E(x), L = zt(x);
987
+ if (V)
988
+ a = 0, p = A - u, m = I < Jt ? G.Strong : I > Ut && p > 1 ? G.Weak : d, m !== d && (c == null || c(m), d = m, u += p, p = 0), r || (n == null || n(C.Start), s = o[o.length - 1], o = [], r = !0), o.push(L);
989
989
  else if (r && (a++, a >= Kt)) {
990
- const T = Nt(o, Re, s);
990
+ const T = Nt(o, De, s);
991
991
  n == null || n(C.Stop, T), t() || i(), u = A, r = !1;
992
992
  }
993
- }, Re);
993
+ }, De);
994
994
  }
995
- const Vt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
995
+ const Ot = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
996
996
  function Le(e) {
997
997
  switch (e) {
998
998
  case "connected":
@@ -1047,7 +1047,7 @@ function $e({
1047
1047
  streamType: c,
1048
1048
  report: o
1049
1049
  }) {
1050
- c === ne.Legacy ? qt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: i, report: o }) : c === ne.Fluent && Qt({
1050
+ c === te.Legacy ? qt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: i, report: o }) : c === te.Fluent && Qt({
1051
1051
  statsSignal: e,
1052
1052
  dataChannelSignal: t,
1053
1053
  onVideoStateChange: i,
@@ -1055,165 +1055,165 @@ function $e({
1055
1055
  report: o
1056
1056
  });
1057
1057
  }
1058
- async function Xt(e, t, { debug: i = !1, callbacks: n, auth: c, baseURL: o = fe, analytics: s }, a) {
1059
- var Z;
1058
+ async function Xt(e, t, { debug: i = !1, callbacks: n, auth: c, baseURL: o = ge, analytics: s }, a) {
1059
+ var M;
1060
1060
  const r = We(i, "WebRTCStreamingManager"), d = Ht(r);
1061
- let m = !1, p = !1, u = C.Stop, M = C.Stop;
1062
- const { startConnection: x, sendStreamRequest: O, close: I, createStream: A, addIceCandidate: L } = xt(
1061
+ let m = !1, p = !1, u = C.Stop, E = C.Stop;
1062
+ const { startConnection: x, sendStreamRequest: V, close: I, createStream: A, addIceCandidate: L } = xt(
1063
1063
  c,
1064
1064
  o,
1065
1065
  e,
1066
1066
  n.onError
1067
1067
  ), {
1068
1068
  id: T,
1069
- offer: re,
1069
+ offer: ne,
1070
1070
  ice_servers: B,
1071
- session_id: K,
1071
+ session_id: N,
1072
1072
  fluent: X,
1073
1073
  interrupt_enabled: f,
1074
1074
  triggers_enabled: R
1075
1075
  } = await A(t, a);
1076
- (Z = n.onStreamCreated) == null || Z.call(n, { stream_id: T, session_id: K, agent_id: e });
1077
- const y = new Vt({ iceServers: B }), $ = y.createDataChannel("JanusDataChannel");
1078
- if (!K)
1076
+ (M = n.onStreamCreated) == null || M.call(n, { stream_id: T, session_id: N, agent_id: e });
1077
+ const w = new Ot({ iceServers: B }), $ = w.createDataChannel("JanusDataChannel");
1078
+ if (!N)
1079
1079
  throw new Error("Could not create session_id");
1080
- const D = X ? ne.Fluent : ne.Legacy;
1080
+ const D = X ? te.Fluent : te.Legacy;
1081
1081
  s.enrich({
1082
1082
  "stream-type": D
1083
1083
  });
1084
- const _ = t.stream_warmup && !X, W = () => m, H = () => {
1085
- var h;
1086
- m = !0, p && ((h = n.onConnectionStateChange) == null || h.call(n, S.Connected));
1087
- }, q = Ot(
1088
- y,
1089
- W,
1084
+ const _ = t.stream_warmup && !X, U = () => m, H = () => {
1085
+ var g;
1086
+ m = !0, p && ((g = n.onConnectionStateChange) == null || g.call(n, S.Connected));
1087
+ }, q = Vt(
1088
+ w,
1089
+ U,
1090
1090
  H,
1091
- (h, w) => $e({
1092
- statsSignal: M = h,
1093
- dataChannelSignal: D === ne.Legacy ? u : void 0,
1091
+ (g, y) => $e({
1092
+ statsSignal: E = g,
1093
+ dataChannelSignal: D === te.Legacy ? u : void 0,
1094
1094
  onVideoStateChange: n.onVideoStateChange,
1095
1095
  onAgentActivityStateChange: n.onAgentActivityStateChange,
1096
- report: w,
1096
+ report: y,
1097
1097
  streamType: D
1098
1098
  }),
1099
- (h) => {
1100
- var w;
1101
- return (w = n.onConnectivityStateChange) == null ? void 0 : w.call(n, h);
1099
+ (g) => {
1100
+ var y;
1101
+ return (y = n.onConnectivityStateChange) == null ? void 0 : y.call(n, g);
1102
1102
  }
1103
1103
  );
1104
- y.onicecandidate = (h) => {
1105
- var w;
1106
- r("peerConnection.onicecandidate", h);
1104
+ w.onicecandidate = (g) => {
1105
+ var y;
1106
+ r("peerConnection.onicecandidate", g);
1107
1107
  try {
1108
- h.candidate && h.candidate.sdpMid && h.candidate.sdpMLineIndex !== null ? L(
1108
+ g.candidate && g.candidate.sdpMid && g.candidate.sdpMLineIndex !== null ? L(
1109
1109
  T,
1110
1110
  {
1111
- candidate: h.candidate.candidate,
1112
- sdpMid: h.candidate.sdpMid,
1113
- sdpMLineIndex: h.candidate.sdpMLineIndex
1111
+ candidate: g.candidate.candidate,
1112
+ sdpMid: g.candidate.sdpMid,
1113
+ sdpMLineIndex: g.candidate.sdpMLineIndex
1114
1114
  },
1115
- K,
1115
+ N,
1116
1116
  a
1117
- ) : L(T, { candidate: null }, K, a);
1118
- } catch (F) {
1119
- (w = n.onError) == null || w.call(n, F, { streamId: T });
1117
+ ) : L(T, { candidate: null }, N, a);
1118
+ } catch (j) {
1119
+ (y = n.onError) == null || y.call(n, j, { streamId: T });
1120
1120
  }
1121
1121
  }, $.onopen = () => {
1122
1122
  p = !0, (!_ || m) && H();
1123
1123
  };
1124
- const j = (h) => {
1125
- var w;
1126
- (w = n.onVideoIdChange) == null || w.call(n, h);
1124
+ const b = (g) => {
1125
+ var y;
1126
+ (y = n.onVideoIdChange) == null || y.call(n, g);
1127
1127
  };
1128
- function J(h, w) {
1129
- if (h === N.StreamStarted && typeof w == "object" && "metadata" in w) {
1130
- const F = w.metadata;
1131
- j(F.videoId);
1128
+ function K(g, y) {
1129
+ if (g === z.StreamStarted && typeof y == "object" && "metadata" in y) {
1130
+ const j = y.metadata;
1131
+ b(j.videoId);
1132
1132
  }
1133
- h === N.StreamDone && j(null), u = h === N.StreamStarted ? C.Start : C.Stop, $e({
1134
- statsSignal: D === ne.Legacy ? M : void 0,
1133
+ g === z.StreamDone && b(null), u = g === z.StreamStarted ? C.Start : C.Stop, $e({
1134
+ statsSignal: D === te.Legacy ? E : void 0,
1135
1135
  dataChannelSignal: u,
1136
1136
  onVideoStateChange: n.onVideoStateChange,
1137
1137
  onAgentActivityStateChange: n.onAgentActivityStateChange,
1138
1138
  streamType: D
1139
1139
  });
1140
1140
  }
1141
- function G(h, w) {
1141
+ function Z(g, y) {
1142
1142
  var Q;
1143
- const F = typeof w == "string" ? w : w == null ? void 0 : w.metadata;
1144
- F && s.enrich({ streamMetadata: F }), (Q = n.onStreamReady) == null || Q.call(n);
1143
+ const j = typeof y == "string" ? y : y == null ? void 0 : y.metadata;
1144
+ j && s.enrich({ streamMetadata: j }), (Q = n.onStreamReady) == null || Q.call(n);
1145
1145
  }
1146
- const E = {
1147
- [N.StreamStarted]: J,
1148
- [N.StreamDone]: J,
1149
- [N.StreamReady]: G
1146
+ const re = {
1147
+ [z.StreamStarted]: K,
1148
+ [z.StreamDone]: K,
1149
+ [z.StreamReady]: Z
1150
1150
  };
1151
- $.onmessage = (h) => {
1151
+ $.onmessage = (g) => {
1152
1152
  var Q;
1153
- const { subject: w, data: F } = d(h.data);
1154
- (Q = E[w]) == null || Q.call(E, w, F);
1155
- }, y.oniceconnectionstatechange = () => {
1156
- var w;
1157
- r("peerConnection.oniceconnectionstatechange => " + y.iceConnectionState);
1158
- const h = Le(y.iceConnectionState);
1159
- h !== S.Connected && ((w = n.onConnectionStateChange) == null || w.call(n, h));
1160
- }, y.ontrack = (h) => {
1161
- var w;
1162
- r("peerConnection.ontrack", h), (w = n.onSrcObjectReady) == null || w.call(n, h.streams[0]);
1163
- }, await y.setRemoteDescription(re), r("set remote description OK");
1164
- const P = await y.createAnswer();
1165
- return r("create answer OK"), await y.setLocalDescription(P), r("set local description OK"), await x(T, P, K, a), r("start connection OK"), {
1153
+ const { subject: y, data: j } = d(g.data);
1154
+ (Q = re[y]) == null || Q.call(re, y, j);
1155
+ }, w.oniceconnectionstatechange = () => {
1156
+ var y;
1157
+ r("peerConnection.oniceconnectionstatechange => " + w.iceConnectionState);
1158
+ const g = Le(w.iceConnectionState);
1159
+ g !== S.Connected && ((y = n.onConnectionStateChange) == null || y.call(n, g));
1160
+ }, w.ontrack = (g) => {
1161
+ var y;
1162
+ r("peerConnection.ontrack", g), (y = n.onSrcObjectReady) == null || y.call(n, g.streams[0]);
1163
+ }, await w.setRemoteDescription(ne), r("set remote description OK");
1164
+ const W = await w.createAnswer();
1165
+ return r("create answer OK"), await w.setLocalDescription(W), r("set local description OK"), await x(T, W, N, a), r("start connection OK"), {
1166
1166
  /**
1167
1167
  * Method to send request to server to get clip or talk depend on you payload
1168
1168
  * @param payload
1169
1169
  */
1170
- speak(h) {
1171
- return O(T, K, h);
1170
+ speak(g) {
1171
+ return V(T, N, g);
1172
1172
  },
1173
1173
  /**
1174
1174
  * Method to close RTC connection
1175
1175
  */
1176
1176
  async disconnect() {
1177
- var h;
1177
+ var g;
1178
1178
  if (T) {
1179
- const w = Le(y.iceConnectionState);
1180
- if (y) {
1181
- if (w === S.New) {
1179
+ const y = Le(w.iceConnectionState);
1180
+ if (w) {
1181
+ if (y === S.New) {
1182
1182
  clearInterval(q);
1183
1183
  return;
1184
1184
  }
1185
- y.close(), y.oniceconnectionstatechange = null, y.onnegotiationneeded = null, y.onicecandidate = null, y.ontrack = null;
1185
+ w.close(), w.oniceconnectionstatechange = null, w.onnegotiationneeded = null, w.onicecandidate = null, w.ontrack = null;
1186
1186
  }
1187
1187
  try {
1188
- w === S.Connected && await I(T, K).catch((F) => {
1188
+ y === S.Connected && await I(T, N).catch((j) => {
1189
1189
  });
1190
- } catch (F) {
1191
- r("Error on close stream connection", F);
1190
+ } catch (j) {
1191
+ r("Error on close stream connection", j);
1192
1192
  }
1193
- (h = n.onAgentActivityStateChange) == null || h.call(n, ae.Idle), clearInterval(q);
1193
+ (g = n.onAgentActivityStateChange) == null || g.call(n, ae.Idle), clearInterval(q);
1194
1194
  }
1195
1195
  },
1196
1196
  /**
1197
1197
  * Method to send data channel messages to the server
1198
1198
  */
1199
- sendDataChannelMessage(h) {
1200
- var w, F;
1199
+ sendDataChannelMessage(g) {
1200
+ var y, j;
1201
1201
  if (!m || $.readyState !== "open") {
1202
- r("Data channel is not ready for sending messages"), (w = n.onError) == null || w.call(n, new Error("Data channel is not ready for sending messages"), {
1202
+ r("Data channel is not ready for sending messages"), (y = n.onError) == null || y.call(n, new Error("Data channel is not ready for sending messages"), {
1203
1203
  streamId: T
1204
1204
  });
1205
1205
  return;
1206
1206
  }
1207
1207
  try {
1208
- $.send(h);
1208
+ $.send(g);
1209
1209
  } catch (Q) {
1210
- r("Error sending data channel message", Q), (F = n.onError) == null || F.call(n, Q, { streamId: T });
1210
+ r("Error sending data channel message", Q), (j = n.onError) == null || j.call(n, Q, { streamId: T });
1211
1211
  }
1212
1212
  },
1213
1213
  /**
1214
1214
  * Session identifier information, should be returned in the body of all streaming requests
1215
1215
  */
1216
- sessionId: K,
1216
+ sessionId: N,
1217
1217
  /**
1218
1218
  * Id of current RTC stream
1219
1219
  */
@@ -1223,7 +1223,7 @@ async function Xt(e, t, { debug: i = !1, callbacks: n, auth: c, baseURL: o = fe,
1223
1223
  triggersAvailable: R ?? !1
1224
1224
  };
1225
1225
  }
1226
- var De = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(De || {});
1226
+ var Me = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Me || {});
1227
1227
  async function Yt(e, t, i, n) {
1228
1228
  const c = e.id;
1229
1229
  switch (t.version) {
@@ -1234,8 +1234,8 @@ async function Yt(e, t, i, n) {
1234
1234
  case "v2": {
1235
1235
  const { version: o, ...s } = t;
1236
1236
  switch (s.transport_provider) {
1237
- case he.Livekit:
1238
- const { createLiveKitStreamingManager: a } = await Promise.resolve().then(() => Et);
1237
+ case we.Livekit:
1238
+ const { createLiveKitStreamingManager: a } = await Promise.resolve().then(() => Mt);
1239
1239
  return a(c, s, i);
1240
1240
  default:
1241
1241
  throw new Error(`Unsupported transport provider: ${s.transport_provider}`);
@@ -1248,7 +1248,7 @@ async function Yt(e, t, i, n) {
1248
1248
  const Zt = "cht";
1249
1249
  function Gt() {
1250
1250
  return {
1251
- transport_provider: he.Livekit
1251
+ transport_provider: we.Livekit
1252
1252
  };
1253
1253
  }
1254
1254
  function en(e) {
@@ -1265,10 +1265,10 @@ function en(e) {
1265
1265
  }, ...i && { end_user_data: i } };
1266
1266
  }
1267
1267
  function tn(e, t) {
1268
- return Ee(e.presenter.type) ? { version: De.V2, ...Gt() } : { version: De.V1, ...en(t) };
1268
+ return Ee(e.presenter.type) ? { version: Me.V2, ...Gt() } : { version: Me.V1, ...en(t) };
1269
1269
  }
1270
1270
  function nn(e, t, i, n, c) {
1271
- c === ne.Fluent ? rn(e, t, i, n, c) : on(e, t, i, n, c);
1271
+ c === te.Fluent ? rn(e, t, i, n, c) : on(e, t, i, n, c);
1272
1272
  }
1273
1273
  function rn(e, t, i, n, c) {
1274
1274
  e === C.Start ? n.track("stream-session", { event: "start", "stream-type": c }) : e === C.Stop && n.track("stream-session", {
@@ -1280,11 +1280,11 @@ function rn(e, t, i, n, c) {
1280
1280
  });
1281
1281
  }
1282
1282
  function an(e, t, i, n) {
1283
- te.get() <= 0 || (e === C.Start ? i.linkTrack(
1283
+ ee.get() <= 0 || (e === C.Start ? i.linkTrack(
1284
1284
  "agent-video",
1285
- { event: "start", latency: te.get(!0), "stream-type": n },
1285
+ { event: "start", latency: ee.get(!0), "stream-type": n },
1286
1286
  "start",
1287
- [N.StreamVideoCreated]
1287
+ [z.StreamVideoCreated]
1288
1288
  ) : e === C.Stop && i.linkTrack(
1289
1289
  "agent-video",
1290
1290
  {
@@ -1294,15 +1294,15 @@ function an(e, t, i, n) {
1294
1294
  "stream-type": n
1295
1295
  },
1296
1296
  "done",
1297
- [N.StreamVideoDone]
1297
+ [z.StreamVideoDone]
1298
1298
  ));
1299
1299
  }
1300
1300
  function on(e, t, i, n, c) {
1301
- te.get() <= 0 || (e === C.Start ? n.linkTrack(
1301
+ ee.get() <= 0 || (e === C.Start ? n.linkTrack(
1302
1302
  "agent-video",
1303
- { event: "start", latency: te.get(!0), "stream-type": c },
1303
+ { event: "start", latency: ee.get(!0), "stream-type": c },
1304
1304
  "start",
1305
- [N.StreamVideoCreated]
1305
+ [z.StreamVideoCreated]
1306
1306
  ) : e === C.Stop && n.linkTrack(
1307
1307
  "agent-video",
1308
1308
  {
@@ -1313,11 +1313,11 @@ function on(e, t, i, n, c) {
1313
1313
  ...i
1314
1314
  },
1315
1315
  "done",
1316
- [N.StreamVideoDone]
1316
+ [z.StreamVideoDone]
1317
1317
  ));
1318
1318
  }
1319
1319
  function xe(e, t, i, n) {
1320
- return te.reset(), je.update(), new Promise(async (c, o) => {
1320
+ return ee.reset(), je.update(), new Promise(async (c, o) => {
1321
1321
  try {
1322
1322
  let s, a = !1;
1323
1323
  const r = tn(e, t);
@@ -1347,7 +1347,7 @@ function xe(e, t, i, n) {
1347
1347
  },
1348
1348
  onAgentActivityStateChange: (d) => {
1349
1349
  var m, p;
1350
- (p = (m = t.callbacks).onAgentActivityStateChange) == null || p.call(m, d), d === ae.Talking ? Ce.update() : Ce.reset(), an(
1350
+ (p = (m = t.callbacks).onAgentActivityStateChange) == null || p.call(m, d), d === ae.Talking ? ke.update() : ke.reset(), an(
1351
1351
  d === ae.Talking ? C.Start : C.Stop,
1352
1352
  e,
1353
1353
  i,
@@ -1368,26 +1368,26 @@ function xe(e, t, i, n) {
1368
1368
  });
1369
1369
  }
1370
1370
  async function sn(e, t, i, n, c) {
1371
- var m, p, u, M;
1371
+ var m, p, u, E;
1372
1372
  const o = async () => {
1373
1373
  if (Ee(e.presenter.type)) {
1374
- const x = await xe(e, t, n), O = `${Zt}_${x.sessionId}`, I = (/* @__PURE__ */ new Date()).toISOString();
1374
+ const x = await xe(e, t, n), V = `${Zt}_${x.sessionId}`, I = (/* @__PURE__ */ new Date()).toISOString();
1375
1375
  return { chatResult: {
1376
- chatMode: U.Functional,
1376
+ chatMode: J.Functional,
1377
1377
  chat: {
1378
- id: O,
1378
+ id: V,
1379
1379
  agent_id: e.id,
1380
1380
  owner_id: e.owner_id ?? "",
1381
1381
  created: I,
1382
1382
  modified: I,
1383
1383
  agent_id__created_at: I,
1384
1384
  agent_id__modified_at: I,
1385
- chat_mode: U.Functional,
1385
+ chat_mode: J.Functional,
1386
1386
  messages: []
1387
1387
  }
1388
1388
  }, streamingManager: x };
1389
1389
  } else {
1390
- const x = new AbortController(), O = x.signal;
1390
+ const x = new AbortController(), V = x.signal;
1391
1391
  let I;
1392
1392
  try {
1393
1393
  const A = Ue(
@@ -1397,20 +1397,20 @@ async function sn(e, t, i, n, c) {
1397
1397
  t.mode,
1398
1398
  t.persistentChat,
1399
1399
  c
1400
- ), L = xe(e, t, n, O).then((B) => (I = B, B)), [T, re] = await Promise.all([A, L]);
1401
- return { chatResult: T, streamingManager: re };
1400
+ ), L = xe(e, t, n, V).then((B) => (I = B, B)), [T, ne] = await Promise.all([A, L]);
1401
+ return { chatResult: T, streamingManager: ne };
1402
1402
  } catch (A) {
1403
1403
  throw x.abort(), I && await I.disconnect().catch(() => {
1404
1404
  }), A;
1405
1405
  }
1406
1406
  }
1407
1407
  }, { chatResult: s, streamingManager: a } = await o(), { chat: r, chatMode: d } = s;
1408
- return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (p = (m = t.callbacks).onModeChange) == null || p.call(m, d), d !== U.Functional) ? ((M = (u = t.callbacks).onError) == null || M.call(u, new qe(d)), a == null || a.disconnect(), { chat: r }) : { chat: r, streamingManager: a };
1408
+ return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (p = (m = t.callbacks).onModeChange) == null || p.call(m, d), d !== J.Functional) ? ((E = (u = t.callbacks).onError) == null || E.call(u, new qe(d)), a == null || a.disconnect(), { chat: r }) : { chat: r, streamingManager: a };
1409
1409
  }
1410
1410
  async function un(e, t) {
1411
- var B, K, X;
1411
+ var B, N, X;
1412
1412
  let i = !0, n = null;
1413
- const c = t.mixpanelKey || ct, o = t.wsURL || st, s = t.baseURL || fe, a = t.mode || U.Functional, r = {
1413
+ const c = t.mixpanelKey || ct, o = t.wsURL || st, s = t.baseURL || ge, a = t.mode || J.Functional, r = {
1414
1414
  messages: [],
1415
1415
  chatMode: a
1416
1416
  }, d = vt({
@@ -1423,9 +1423,9 @@ async function un(e, t) {
1423
1423
  be(() => {
1424
1424
  d.track("agent-sdk", { event: "init" }, m);
1425
1425
  });
1426
- const p = mt(t.auth, s, t.callbacks.onError, t.externalId), u = await p.getById(e), M = Ee(u.presenter.type);
1426
+ const p = mt(t.auth, s, t.callbacks.onError, t.externalId), u = await p.getById(e), E = Ee(u.presenter.type);
1427
1427
  d.enrich(ht(u));
1428
- const { onMessage: x, clearQueue: O } = $t(
1428
+ const { onMessage: x, clearQueue: V } = $t(
1429
1429
  d,
1430
1430
  r,
1431
1431
  t,
@@ -1435,7 +1435,7 @@ async function un(e, t) {
1435
1435
  return (f = r.socketManager) == null ? void 0 : f.disconnect();
1436
1436
  }
1437
1437
  );
1438
- r.messages = Ct(t.initialMessages), (K = (B = t.callbacks).onNewMessage) == null || K.call(B, [...r.messages], "answer");
1438
+ r.messages = Ct(t.initialMessages), (N = (B = t.callbacks).onNewMessage) == null || N.call(B, [...r.messages], "answer");
1439
1439
  const I = (f) => {
1440
1440
  n = f;
1441
1441
  }, A = Date.now();
@@ -1443,14 +1443,14 @@ async function un(e, t) {
1443
1443
  d.track("agent-sdk", { event: "loaded", ...gt(u) }, A);
1444
1444
  });
1445
1445
  async function L(f) {
1446
- var W, H, q, j, J, G, E;
1447
- (H = (W = t.callbacks).onConnectionStateChange) == null || H.call(W, S.Connecting), te.reset(), f && !i && (delete r.chat, (j = (q = t.callbacks).onNewMessage) == null || j.call(q, [...r.messages], "answer"));
1448
- const R = a === U.DirectPlayback || M ? Promise.resolve(void 0) : Pt(
1446
+ var U, H, q, b, K, Z, re;
1447
+ (H = (U = t.callbacks).onConnectionStateChange) == null || H.call(U, S.Connecting), ee.reset(), f && !i && (delete r.chat, (b = (q = t.callbacks).onNewMessage) == null || b.call(q, [...r.messages], "answer"));
1448
+ const R = a === J.DirectPlayback || E ? Promise.resolve(void 0) : Pt(
1449
1449
  t.auth,
1450
1450
  o,
1451
1451
  { onMessage: x, onError: t.callbacks.onError },
1452
1452
  t.externalId
1453
- ), y = ve(
1453
+ ), w = Se(
1454
1454
  () => sn(
1455
1455
  u,
1456
1456
  {
@@ -1466,26 +1466,26 @@ async function un(e, t) {
1466
1466
  limit: 3,
1467
1467
  timeout: at,
1468
1468
  timeoutErrorMessage: "Timeout initializing the stream",
1469
- shouldRetryFn: (P) => (P == null ? void 0 : P.message) !== "Could not connect" && P.status !== 429 && (P == null ? void 0 : P.message) !== "InsufficientCreditsError",
1469
+ shouldRetryFn: (W) => (W == null ? void 0 : W.message) !== "Could not connect" && W.status !== 429 && (W == null ? void 0 : W.message) !== "InsufficientCreditsError",
1470
1470
  delayMs: 1e3
1471
1471
  }
1472
- ).catch((P) => {
1473
- var Z, h;
1474
- throw re(U.Maintenance), (h = (Z = t.callbacks).onConnectionStateChange) == null || h.call(Z, S.Fail), P;
1475
- }), [$, { streamingManager: D, chat: _ }] = await Promise.all([R, y]);
1476
- _ && _.id !== ((J = r.chat) == null ? void 0 : J.id) && ((E = (G = t.callbacks).onNewChat) == null || E.call(G, _.id)), r.streamingManager = D, r.socketManager = $, r.chat = _, i = !1, d.enrich({
1472
+ ).catch((W) => {
1473
+ var M, g;
1474
+ throw ne(J.Maintenance), (g = (M = t.callbacks).onConnectionStateChange) == null || g.call(M, S.Fail), W;
1475
+ }), [$, { streamingManager: D, chat: _ }] = await Promise.all([R, w]);
1476
+ _ && _.id !== ((K = r.chat) == null ? void 0 : K.id) && ((re = (Z = t.callbacks).onNewChat) == null || re.call(Z, _.id)), r.streamingManager = D, r.socketManager = $, r.chat = _, i = !1, d.enrich({
1477
1477
  chatId: _ == null ? void 0 : _.id,
1478
1478
  streamId: D == null ? void 0 : D.streamId,
1479
1479
  mode: r.chatMode
1480
- }), re((_ == null ? void 0 : _.chat_mode) ?? a);
1480
+ }), ne((_ == null ? void 0 : _.chat_mode) ?? a);
1481
1481
  }
1482
1482
  async function T() {
1483
- var f, R, y, $;
1484
- (f = r.socketManager) == null || f.disconnect(), await ((R = r.streamingManager) == null ? void 0 : R.disconnect()), delete r.streamingManager, delete r.socketManager, ($ = (y = t.callbacks).onConnectionStateChange) == null || $.call(y, S.Disconnected);
1483
+ var f, R, w, $;
1484
+ (f = r.socketManager) == null || f.disconnect(), await ((R = r.streamingManager) == null ? void 0 : R.disconnect()), delete r.streamingManager, delete r.socketManager, ($ = (w = t.callbacks).onConnectionStateChange) == null || $.call(w, S.Disconnected);
1485
1485
  }
1486
- async function re(f) {
1487
- var R, y;
1488
- f !== r.chatMode && (d.track("agent-mode-change", { mode: f }), r.chatMode = f, r.chatMode !== U.Functional && await T(), (y = (R = t.callbacks).onModeChange) == null || y.call(R, f));
1486
+ async function ne(f) {
1487
+ var R, w;
1488
+ f !== r.chatMode && (d.track("agent-mode-change", { mode: f }), r.chatMode = f, r.chatMode !== J.Functional && await T(), (w = (R = t.callbacks).onModeChange) == null || w.call(R, f));
1489
1489
  }
1490
1490
  return {
1491
1491
  agent: u,
@@ -1503,7 +1503,7 @@ async function un(e, t) {
1503
1503
  },
1504
1504
  starterMessages: ((X = u.knowledge) == null ? void 0 : X.starter_message) || [],
1505
1505
  getSTTToken: () => p.getSTTToken(u.id),
1506
- changeMode: re,
1506
+ changeMode: ne,
1507
1507
  enrichAnalytics: d.enrich,
1508
1508
  async connect() {
1509
1509
  await L(!0), d.track("agent-chat", {
@@ -1513,7 +1513,7 @@ async function un(e, t) {
1513
1513
  },
1514
1514
  async reconnect() {
1515
1515
  const f = r.streamingManager;
1516
- if (M && (f != null && f.reconnect)) {
1516
+ if (E && (f != null && f.reconnect)) {
1517
1517
  try {
1518
1518
  await f.reconnect(), d.track("agent-chat", {
1519
1519
  event: "reconnect",
@@ -1548,111 +1548,114 @@ async function un(e, t) {
1548
1548
  return r.streamingManager.unpublishMicrophoneStream();
1549
1549
  },
1550
1550
  async chat(f) {
1551
- var D, _, W, H, q;
1551
+ var D, _, U, H, q;
1552
1552
  const R = () => {
1553
1553
  if (Ne(a))
1554
- throw new se(`${a} is enabled, chat is disabled`);
1554
+ throw new ce(`${a} is enabled, chat is disabled`);
1555
1555
  if (f.length >= 800)
1556
- throw new se("Message cannot be more than 800 characters");
1556
+ throw new ce("Message cannot be more than 800 characters");
1557
1557
  if (f.length === 0)
1558
- throw new se("Message cannot be empty");
1559
- if (r.chatMode === U.Maintenance)
1560
- throw new se("Chat is in maintenance mode");
1561
- if (![U.TextOnly, U.Playground].includes(r.chatMode)) {
1558
+ throw new ce("Message cannot be empty");
1559
+ if (r.chatMode === J.Maintenance)
1560
+ throw new ce("Chat is in maintenance mode");
1561
+ if (![J.TextOnly, J.Playground].includes(r.chatMode)) {
1562
1562
  if (!r.streamingManager)
1563
- throw new se("Streaming manager is not initialized");
1563
+ throw new ce("Streaming manager is not initialized");
1564
1564
  if (!r.chat)
1565
- throw new se("Chat is not initialized");
1565
+ throw new ce("Chat is not initialized");
1566
1566
  }
1567
- }, y = async () => {
1568
- var j, J;
1567
+ }, w = async () => {
1568
+ var b, K;
1569
1569
  if (!r.chat) {
1570
- const G = await Ue(
1570
+ const Z = await Ue(
1571
1571
  u,
1572
1572
  p,
1573
1573
  d,
1574
1574
  r.chatMode,
1575
1575
  t.persistentChat
1576
1576
  );
1577
- if (!G.chat)
1577
+ if (!Z.chat)
1578
1578
  throw new He(r.chatMode, !!t.persistentChat);
1579
- r.chat = G.chat, (J = (j = t.callbacks).onNewChat) == null || J.call(j, r.chat.id);
1579
+ r.chat = Z.chat, (K = (b = t.callbacks).onNewChat) == null || K.call(b, r.chat.id);
1580
1580
  }
1581
1581
  return r.chat.id;
1582
- }, $ = async (j, J) => ve(M ? async () => {
1583
- var E, P;
1584
- return await ((P = (E = r.streamingManager) == null ? void 0 : E.sendTextMessage) == null ? void 0 : P.call(E, f)), Promise.resolve({});
1585
- } : async () => {
1586
- var E, P;
1587
- return p.chat(
1588
- u.id,
1589
- J,
1590
- {
1591
- chatMode: r.chatMode,
1592
- streamId: (E = r.streamingManager) == null ? void 0 : E.streamId,
1593
- sessionId: (P = r.streamingManager) == null ? void 0 : P.sessionId,
1594
- messages: j.map(({ matches: Z, ...h }) => h)
1582
+ }, $ = async (b, K) => {
1583
+ const Z = r.chatMode === J.Playground;
1584
+ return Se(E && !Z ? async () => {
1585
+ var M, g;
1586
+ return await ((g = (M = r.streamingManager) == null ? void 0 : M.sendTextMessage) == null ? void 0 : g.call(M, f)), Promise.resolve({});
1587
+ } : async () => {
1588
+ var M, g;
1589
+ return p.chat(
1590
+ u.id,
1591
+ K,
1592
+ {
1593
+ chatMode: r.chatMode,
1594
+ streamId: (M = r.streamingManager) == null ? void 0 : M.streamId,
1595
+ sessionId: (g = r.streamingManager) == null ? void 0 : g.sessionId,
1596
+ messages: b.map(({ matches: y, ...j }) => j)
1597
+ },
1598
+ {
1599
+ ...Je(r.chatMode),
1600
+ skipErrorHandler: !0
1601
+ }
1602
+ );
1603
+ }, {
1604
+ limit: 2,
1605
+ shouldRetryFn: (M) => {
1606
+ var j, Q, se, ue;
1607
+ const g = (j = M == null ? void 0 : M.message) == null ? void 0 : j.includes("missing or invalid session_id");
1608
+ return !((Q = M == null ? void 0 : M.message) == null ? void 0 : Q.includes("Stream Error")) && !g ? ((ue = (se = t.callbacks).onError) == null || ue.call(se, M), !1) : !0;
1595
1609
  },
1596
- {
1597
- ...Je(r.chatMode),
1598
- skipErrorHandler: !0
1610
+ onRetry: async () => {
1611
+ await T(), await L(!1);
1599
1612
  }
1600
- );
1601
- }, {
1602
- limit: 2,
1603
- shouldRetryFn: (E) => {
1604
- var h, w, F, Q;
1605
- const P = (h = E == null ? void 0 : E.message) == null ? void 0 : h.includes("missing or invalid session_id");
1606
- return !((w = E == null ? void 0 : E.message) == null ? void 0 : w.includes("Stream Error")) && !P ? ((Q = (F = t.callbacks).onError) == null || Q.call(F, E), !1) : !0;
1607
- },
1608
- onRetry: async () => {
1609
- await T(), await L(!1);
1610
- }
1611
- });
1613
+ });
1614
+ };
1612
1615
  try {
1613
- O(), R(), r.messages.push({
1614
- id: ce(),
1616
+ V(), R(), r.messages.push({
1617
+ id: de(),
1615
1618
  role: "user",
1616
1619
  content: f,
1617
- created_at: new Date(te.update()).toISOString()
1620
+ created_at: new Date(ee.update()).toISOString()
1618
1621
  }), (_ = (D = t.callbacks).onNewMessage) == null || _.call(D, [...r.messages], "user");
1619
- const j = await y(), J = await $([...r.messages], j);
1622
+ const b = await w(), K = await $([...r.messages], b);
1620
1623
  return r.messages.push({
1621
- id: ce(),
1624
+ id: de(),
1622
1625
  role: "assistant",
1623
- content: J.result || "",
1626
+ content: K.result || "",
1624
1627
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1625
- context: J.context,
1626
- matches: J.matches
1628
+ context: K.context,
1629
+ matches: K.matches
1627
1630
  }), d.track("agent-message-send", {
1628
1631
  event: "success",
1629
1632
  messages: r.messages.length + 1
1630
- }), J.result && ((H = (W = t.callbacks).onNewMessage) == null || H.call(W, [...r.messages], "answer"), d.track("agent-message-received", {
1631
- latency: te.get(!0),
1633
+ }), K.result && ((H = (U = t.callbacks).onNewMessage) == null || H.call(U, [...r.messages], "answer"), d.track("agent-message-received", {
1634
+ latency: ee.get(!0),
1632
1635
  messages: r.messages.length
1633
- })), J;
1634
- } catch (j) {
1636
+ })), K;
1637
+ } catch (b) {
1635
1638
  throw ((q = r.messages[r.messages.length - 1]) == null ? void 0 : q.role) === "assistant" && r.messages.pop(), d.track("agent-message-send", {
1636
1639
  event: "error",
1637
1640
  messages: r.messages.length
1638
- }), j;
1641
+ }), b;
1639
1642
  }
1640
1643
  },
1641
- rate(f, R, y) {
1642
- var _, W, H, q;
1643
- const $ = r.messages.find((j) => j.id === f);
1644
+ rate(f, R, w) {
1645
+ var _, U, H, q;
1646
+ const $ = r.messages.find((b) => b.id === f);
1644
1647
  if (r.chat) {
1645
1648
  if (!$)
1646
1649
  throw new Error("Message not found");
1647
1650
  } else throw new Error("Chat is not initialized");
1648
- const D = ((_ = $.matches) == null ? void 0 : _.map((j) => [j.document_id, j.id])) ?? [];
1651
+ const D = ((_ = $.matches) == null ? void 0 : _.map((b) => [b.document_id, b.id])) ?? [];
1649
1652
  return d.track("agent-rate", {
1650
- event: y ? "update" : "create",
1653
+ event: w ? "update" : "create",
1651
1654
  thumb: R === 1 ? "up" : "down",
1652
- knowledge_id: ((W = u.knowledge) == null ? void 0 : W.id) ?? "",
1655
+ knowledge_id: ((U = u.knowledge) == null ? void 0 : U.id) ?? "",
1653
1656
  matches: D,
1654
1657
  score: R
1655
- }), y ? p.updateRating(u.id, r.chat.id, y, {
1658
+ }), w ? p.updateRating(u.id, r.chat.id, w, {
1656
1659
  knowledge_id: ((H = u.knowledge) == null ? void 0 : H.id) ?? "",
1657
1660
  message_id: f,
1658
1661
  matches: D,
@@ -1670,7 +1673,7 @@ async function un(e, t) {
1670
1673
  return d.track("agent-rate-delete", { type: "text" }), p.deleteRating(u.id, r.chat.id, f);
1671
1674
  },
1672
1675
  async speak(f) {
1673
- var D, _, W;
1676
+ var D, _, U;
1674
1677
  function R() {
1675
1678
  if (typeof f == "string") {
1676
1679
  if (!u.presenter.voice)
@@ -1694,11 +1697,11 @@ async function un(e, t) {
1694
1697
  }
1695
1698
  return f;
1696
1699
  }
1697
- const y = R();
1698
- if (d.track("agent-speak", y), te.update(), r.messages && y.type === "text" && (r.messages.push({
1699
- id: ce(),
1700
+ const w = R();
1701
+ if (d.track("agent-speak", w), ee.update(), r.messages && w.type === "text" && (r.messages.push({
1702
+ id: de(),
1700
1703
  role: "assistant",
1701
- content: y.input,
1704
+ content: w.input,
1702
1705
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1703
1706
  }), (_ = (D = t.callbacks).onNewMessage) == null || _.call(D, [...r.messages], "answer")), dt(r.chatMode))
1704
1707
  return {
@@ -1709,18 +1712,18 @@ async function un(e, t) {
1709
1712
  if (!r.streamingManager)
1710
1713
  throw new Error("Please connect to the agent first");
1711
1714
  return r.streamingManager.speak({
1712
- script: y,
1713
- metadata: { chat_id: (W = r.chat) == null ? void 0 : W.id, agent_id: u.id }
1715
+ script: w,
1716
+ metadata: { chat_id: (U = r.chat) == null ? void 0 : U.id, agent_id: u.id }
1714
1717
  });
1715
1718
  },
1716
1719
  async interrupt({ type: f }) {
1717
- var y, $, D;
1720
+ var w, $, D;
1718
1721
  const R = r.messages[r.messages.length - 1];
1719
1722
  d.track("agent-video-interrupt", {
1720
1723
  type: f || "click",
1721
- video_duration_to_interrupt: Ce.get(!0),
1722
- message_duration_to_interrupt: te.get(!0)
1723
- }), R.interrupted = !0, ($ = (y = t.callbacks).onNewMessage) == null || $.call(y, [...r.messages], "answer"), M ? Tt(r.streamingManager) : (Mt(r.streamingManager, (D = r.streamingManager) == null ? void 0 : D.streamType, n), It(r.streamingManager, n));
1724
+ video_duration_to_interrupt: ke.get(!0),
1725
+ message_duration_to_interrupt: ee.get(!0)
1726
+ }), R.interrupted = !0, ($ = (w = t.callbacks).onNewMessage) == null || $.call(w, [...r.messages], "answer"), E ? Tt(r.streamingManager) : (Et(r.streamingManager, (D = r.streamingManager) == null ? void 0 : D.streamType, n), It(r.streamingManager, n));
1724
1727
  }
1725
1728
  };
1726
1729
  }
@@ -1728,23 +1731,23 @@ export {
1728
1731
  ae as AgentActivityState,
1729
1732
  Ze as AgentStatus,
1730
1733
  He as ChatCreationFailed,
1731
- U as ChatMode,
1734
+ J as ChatMode,
1732
1735
  qe as ChatModeDowngraded,
1733
1736
  Y as ChatProgress,
1734
1737
  S as ConnectionState,
1735
- ee as ConnectivityState,
1738
+ G as ConnectivityState,
1736
1739
  nt as DocumentType,
1737
1740
  tt as KnowledgeType,
1738
1741
  Ye as PlanGroup,
1739
1742
  rt as Providers,
1740
1743
  Ge as RateState,
1741
- N as StreamEvents,
1742
- ne as StreamType,
1744
+ z as StreamEvents,
1745
+ te as StreamType,
1743
1746
  C as StreamingState,
1744
1747
  et as Subject,
1745
- he as TransportProvider,
1748
+ we as TransportProvider,
1746
1749
  Xe as UserPlan,
1747
- se as ValidationError,
1750
+ ce as ValidationError,
1748
1751
  Be as VideoType,
1749
1752
  it as VoiceAccess,
1750
1753
  Qe as WsError,