@d-id/client-sdk 1.1.55 → 1.1.56

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 ht = Object.defineProperty;
2
- var pt = (e, n, i) => n in e ? ht(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
3
- var me = (e, n, i) => pt(e, typeof n != "symbol" ? n + "" : n, i);
1
+ var pt = Object.defineProperty;
2
+ var wt = (e, n, i) => n in e ? pt(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
3
+ var ge = (e, n, i) => wt(e, typeof n != "symbol" ? n + "" : n, i);
4
4
  class Re extends Error {
5
5
  constructor({ kind: i, description: r, error: o }) {
6
6
  super(JSON.stringify({ kind: i, description: r }));
7
- me(this, "kind");
8
- me(this, "description");
9
- me(this, "error");
7
+ ge(this, "kind");
8
+ ge(this, "description");
9
+ ge(this, "error");
10
10
  this.kind = i, this.description = r, this.error = o;
11
11
  }
12
12
  }
13
- class wt extends Re {
13
+ class yt extends Re {
14
14
  constructor(n, i) {
15
15
  super({
16
16
  kind: "ChatCreationFailed",
@@ -18,25 +18,25 @@ class wt extends Re {
18
18
  });
19
19
  }
20
20
  }
21
- class yt extends Re {
21
+ class vt extends Re {
22
22
  constructor(n) {
23
23
  super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${n}` });
24
24
  }
25
25
  }
26
- class de extends Re {
26
+ class ue extends Re {
27
27
  constructor(i, r) {
28
28
  super({ kind: "ValidationError", description: i });
29
- me(this, "key");
29
+ ge(this, "key");
30
30
  this.key = r;
31
31
  }
32
32
  }
33
- class vt extends Re {
33
+ class Ct extends Re {
34
34
  constructor(n) {
35
35
  super({ kind: "WSError", description: n });
36
36
  }
37
37
  }
38
- var Ct = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Ct || {}), St = /* @__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))(St || {}), Rt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Rt || {}), Tt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Tt || {}), N = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(N || {}), q = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(q || {}), kt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(kt || {}), Et = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(Et || {}), It = /* @__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))(It || {}), Ge = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Ge || {});
39
- const xn = (e) => {
38
+ var St = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(St || {}), Rt = /* @__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))(Rt || {}), Tt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Tt || {}), kt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(kt || {}), N = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(N || {}), q = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(q || {}), Et = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Et || {}), It = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(It || {}), Dt = /* @__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))(Dt || {}), Ze = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Ze || {});
39
+ const Fn = (e) => {
40
40
  switch (e) {
41
41
  case "clip":
42
42
  return "clip";
@@ -48,12 +48,12 @@ const xn = (e) => {
48
48
  throw new Error(`Unknown video type: ${e}`);
49
49
  }
50
50
  };
51
- var T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}), ne = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ne || {}), J = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(J || {}), E = /* @__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.ToolCalling = "tool/calling", e.ToolResult = "tool/result", e))(E || {}), _ = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(_ || {}), ie = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ie || {}), Pe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Pe || {}), Dt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Dt || {}), Mt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(Mt || {});
52
- const At = 45 * 1e3, _t = "X-Playground-Chat", pe = "https://api.d-id.com", bt = "wss://notifications.d-id.com", Pt = "79f81a83a67430be2bc0fd61042b8faa", Lt = (...e) => {
53
- }, Ze = (e) => new Promise((n) => setTimeout(n, e)), ue = (e = 16) => {
51
+ var T = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(T || {}), te = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(te || {}), J = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(J || {}), E = /* @__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.ToolCalling = "tool/calling", e.ToolResult = "tool/result", e))(E || {}), b = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(b || {}), re = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(re || {}), Pe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Pe || {}), Mt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(Mt || {}), At = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(At || {});
52
+ const _t = 45 * 1e3, bt = "X-Playground-Chat", we = "https://api.d-id.com", Pt = "wss://notifications.d-id.com", Lt = "79f81a83a67430be2bc0fd61042b8faa", jt = (...e) => {
53
+ }, et = (e) => new Promise((n) => setTimeout(n, e)), le = (e = 16) => {
54
54
  const n = new Uint8Array(e);
55
55
  return window.crypto.getRandomValues(n), Array.from(n, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
56
- }, et = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, jt = (e) => {
56
+ }, tt = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, $t = (e) => {
57
57
  switch (e.type) {
58
58
  case "expressive":
59
59
  return "v4";
@@ -62,8 +62,8 @@ const At = 45 * 1e3, _t = "X-Playground-Chat", pe = "https://api.d-id.com", bt =
62
62
  case "talk":
63
63
  return "v2";
64
64
  }
65
- }, $t = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Le = (e) => e === Ge.Expressive, Bt = (e) => [N.TextOnly, N.Playground, N.Maintenance].includes(e), tt = (e) => e && [N.DirectPlayback, N.Off].includes(e);
66
- function xt(e, n) {
65
+ }, xt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Le = (e) => e === Ze.Expressive, Bt = (e) => [N.TextOnly, N.Playground, N.Maintenance].includes(e), nt = (e) => e && [N.DirectPlayback, N.Off].includes(e);
66
+ function Ft(e, n) {
67
67
  let i;
68
68
  return {
69
69
  promise: new Promise((o, a) => {
@@ -87,12 +87,12 @@ async function De(e, n) {
87
87
  try {
88
88
  if (!i.timeout)
89
89
  return await e();
90
- const { promise: a, clear: s } = xt(i.timeout, i.timeoutErrorMessage), c = e().finally(s);
91
- return await Promise.race([c, a]);
90
+ const { promise: a, clear: s } = Ft(i.timeout, i.timeoutErrorMessage), d = e().finally(s);
91
+ return await Promise.race([d, a]);
92
92
  } catch (a) {
93
93
  if (r = a, !i.shouldRetryFn(a) || o >= i.limit)
94
94
  throw a;
95
- await Ze(i.delayMs), i.onRetry(a);
95
+ await et(i.delayMs), i.onRetry(a);
96
96
  }
97
97
  throw r;
98
98
  }
@@ -101,69 +101,69 @@ function Me(e) {
101
101
  return window.localStorage.setItem("did_external_key_id", e), e;
102
102
  let n = window.localStorage.getItem("did_external_key_id");
103
103
  if (!n) {
104
- let i = ue();
104
+ let i = le();
105
105
  window.localStorage.setItem("did_external_key_id", i), n = i;
106
106
  }
107
107
  return n;
108
108
  }
109
- let Ft = ue();
110
- function nt(e, n) {
109
+ let zt = le();
110
+ function rt(e, n) {
111
111
  if (e.type === "bearer")
112
112
  return `Bearer ${e.token}`;
113
113
  if (e.type === "basic")
114
114
  return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}`;
115
115
  if (e.type === "key")
116
- return `Client-Key ${e.clientKey}.${Me(n)}_${Ft}`;
116
+ return `Client-Key ${e.clientKey}.${Me(n)}_${zt}`;
117
117
  throw new Error(`Unknown auth type: ${e}`);
118
118
  }
119
- const zt = (e) => De(e, {
119
+ const Kt = (e) => De(e, {
120
120
  limit: 3,
121
121
  delayMs: 1e3,
122
122
  timeout: 0,
123
123
  shouldRetryFn: (n) => n.status === 429
124
124
  });
125
- function je(e, n = pe, i, r) {
125
+ function je(e, n = we, i, r) {
126
126
  const o = async (a, s) => {
127
- const { skipErrorHandler: c, ...t } = s || {}, d = await zt(
127
+ const { skipErrorHandler: d, ...t } = s || {}, c = await Kt(
128
128
  () => fetch(n + (a != null && a.startsWith("/") ? a : `/${a}`), {
129
129
  ...t,
130
130
  headers: {
131
131
  ...t.headers,
132
- Authorization: nt(e, r),
132
+ Authorization: rt(e, r),
133
133
  "Content-Type": "application/json"
134
134
  }
135
135
  })
136
136
  );
137
- if (!d.ok) {
138
- let p = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
137
+ if (!c.ok) {
138
+ let p = await c.text().catch(() => `Failed to fetch with status ${c.status}`);
139
139
  const g = new Error(p);
140
- throw i && !c && i(g, { url: a, options: t, headers: d.headers }), g;
140
+ throw i && !d && i(g, { url: a, options: t, headers: c.headers }), g;
141
141
  }
142
- return d.json();
142
+ return c.json();
143
143
  };
144
144
  return {
145
145
  get(a, s) {
146
146
  return o(a, { ...s, method: "GET" });
147
147
  },
148
- post(a, s, c) {
149
- return o(a, { ...c, body: JSON.stringify(s), method: "POST" });
148
+ post(a, s, d) {
149
+ return o(a, { ...d, body: JSON.stringify(s), method: "POST" });
150
150
  },
151
- delete(a, s, c) {
152
- return o(a, { ...c, body: JSON.stringify(s), method: "DELETE" });
151
+ delete(a, s, d) {
152
+ return o(a, { ...d, body: JSON.stringify(s), method: "DELETE" });
153
153
  },
154
- patch(a, s, c) {
155
- return o(a, { ...c, body: JSON.stringify(s), method: "PATCH" });
154
+ patch(a, s, d) {
155
+ return o(a, { ...d, body: JSON.stringify(s), method: "PATCH" });
156
156
  }
157
157
  };
158
158
  }
159
- function Kt(e, n = pe, i, r) {
159
+ function Nt(e, n = we, i, r) {
160
160
  const o = je(e, `${n}/agents`, i, r);
161
161
  return {
162
162
  create(a, s) {
163
163
  return o.post("/", a, s);
164
164
  },
165
165
  getAgents(a, s) {
166
- return o.get(`/${a ? `?tag=${a}` : ""}`, s).then((c) => c ?? []);
166
+ return o.get(`/${a ? `?tag=${a}` : ""}`, s).then((d) => d ?? []);
167
167
  },
168
168
  getById(a, s) {
169
169
  return o.get(`/${a}`, s);
@@ -171,31 +171,31 @@ function Kt(e, n = pe, i, r) {
171
171
  delete(a, s) {
172
172
  return o.delete(`/${a}`, void 0, s);
173
173
  },
174
- update(a, s, c) {
175
- return o.patch(`/${a}`, s, c);
174
+ update(a, s, d) {
175
+ return o.patch(`/${a}`, s, d);
176
176
  },
177
- newChat(a, s, c) {
178
- return o.post(`/${a}/chat`, s, c);
177
+ newChat(a, s, d) {
178
+ return o.post(`/${a}/chat`, s, d);
179
179
  },
180
- chat(a, s, c, t) {
181
- return o.post(`/${a}/chat/${s}`, c, t);
180
+ chat(a, s, d, t) {
181
+ return o.post(`/${a}/chat/${s}`, d, t);
182
182
  },
183
- createRating(a, s, c, t) {
184
- return o.post(`/${a}/chat/${s}/ratings`, c, t);
183
+ createRating(a, s, d, t) {
184
+ return o.post(`/${a}/chat/${s}/ratings`, d, t);
185
185
  },
186
- updateRating(a, s, c, t, d) {
187
- return o.patch(`/${a}/chat/${s}/ratings/${c}`, t, d);
186
+ updateRating(a, s, d, t, c) {
187
+ return o.patch(`/${a}/chat/${s}/ratings/${d}`, t, c);
188
188
  },
189
- deleteRating(a, s, c, t) {
190
- return o.delete(`/${a}/chat/${s}/ratings/${c}`, t);
189
+ deleteRating(a, s, d, t) {
190
+ return o.delete(`/${a}/chat/${s}/ratings/${d}`, t);
191
191
  },
192
192
  getSTTToken(a, s) {
193
193
  return o.get(`/${a}/stt-token`, s);
194
194
  }
195
195
  };
196
196
  }
197
- function Nt(e) {
198
- var o, a, s, c;
197
+ function Vt(e) {
198
+ var o, a, s, d;
199
199
  const n = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
200
200
  const t = navigator.platform;
201
201
  return t.toLowerCase().includes("win") ? "Windows" : t.toLowerCase().includes("mac") ? "Mac OS X" : t.toLowerCase().includes("linux") ? "Linux" : "Unknown";
@@ -205,20 +205,20 @@ function Nt(e) {
205
205
  isMobile: `${n() == "Mobile"}`,
206
206
  browser: navigator.userAgent,
207
207
  origin: window.location.origin,
208
- agentType: et(r),
208
+ agentType: tt(r),
209
209
  agentVoice: {
210
210
  voiceId: (a = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : a.voice_id,
211
- provider: (c = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : c.type
211
+ provider: (d = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : d.type
212
212
  }
213
213
  };
214
214
  }
215
- function Vt(e) {
216
- var i, r, o, a, s, c;
215
+ function Ut(e) {
216
+ var i, r, o, a, s, d;
217
217
  const n = (i = e.llm) == null ? void 0 : i.prompt_customization;
218
218
  return {
219
- agentType: et(e.presenter),
220
- presenterType: jt(e.presenter),
221
- presenter: $t(e.presenter),
219
+ agentType: tt(e.presenter),
220
+ presenterType: $t(e.presenter),
221
+ presenter: xt(e.presenter),
222
222
  owner_id: e.owner_id ?? "",
223
223
  promptVersion: (r = e.llm) == null ? void 0 : r.prompt_version,
224
224
  behavior: {
@@ -228,7 +228,7 @@ function Vt(e) {
228
228
  },
229
229
  temperature: (a = e.llm) == null ? void 0 : a.temperature,
230
230
  knowledgeSource: n == null ? void 0 : n.knowledge_source,
231
- starterQuestionsCount: (c = (s = e.knowledge) == null ? void 0 : s.starter_message) == null ? void 0 : c.length,
231
+ starterQuestionsCount: (d = (s = e.knowledge) == null ? void 0 : s.starter_message) == null ? void 0 : d.length,
232
232
  topicsToAvoid: n == null ? void 0 : n.topics_to_avoid,
233
233
  maxResponseLength: n == null ? void 0 : n.max_response_length,
234
234
  agentId: e.id,
@@ -237,23 +237,23 @@ function Vt(e) {
237
237
  ...e.access === "public" ? { from: "agent-template" } : {}
238
238
  };
239
239
  }
240
- const Ut = (e) => e.reduce((n, i) => n + i, 0), Ve = (e) => Ut(e) / e.length;
241
- function Jt(e, n, i) {
242
- var t, d, p;
240
+ const Jt = (e) => e.reduce((n, i) => n + i, 0), Je = (e) => Jt(e) / e.length;
241
+ function Ot(e, n, i) {
242
+ var t, c, p;
243
243
  const { event: r, ...o } = e, { template: a } = (n == null ? void 0 : n.llm) || {}, { language: s } = ((t = n == null ? void 0 : n.presenter) == null ? void 0 : t.voice) || {};
244
244
  return {
245
245
  ...o,
246
246
  llm: { ...o.llm, template: a },
247
- script: { ...o.script, provider: { ...(d = o == null ? void 0 : o.script) == null ? void 0 : d.provider, language: s } },
247
+ script: { ...o.script, provider: { ...(c = o == null ? void 0 : o.script) == null ? void 0 : c.provider, language: s } },
248
248
  stitch: (n == null ? void 0 : n.presenter.type) === "talk" ? (p = n == null ? void 0 : n.presenter) == null ? void 0 : p.stitch : void 0,
249
249
  ...i
250
250
  };
251
251
  }
252
- function Ue(e) {
252
+ function Oe(e) {
253
253
  "requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
254
254
  }
255
- const Ot = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
256
- function Wt(e) {
255
+ const Wt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
256
+ function Ht(e) {
257
257
  const n = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", i = {};
258
258
  return {
259
259
  token: e.token || "testKey",
@@ -264,14 +264,14 @@ function Wt(e) {
264
264
  ...e.mixpanelAdditionalProperties || {}
265
265
  },
266
266
  isEnabled: e.isEnabled ?? !0,
267
- getRandom: ue,
267
+ getRandom: le,
268
268
  enrich(r) {
269
269
  this.additionalProperties = { ...this.additionalProperties, ...r };
270
270
  },
271
271
  async track(r, o, a) {
272
272
  if (!this.isEnabled)
273
273
  return Promise.resolve();
274
- const { audioPath: s, ...c } = o || {}, t = a || Date.now(), d = {
274
+ const { audioPath: s, ...d } = o || {}, t = a || Date.now(), c = {
275
275
  method: "POST",
276
276
  headers: {
277
277
  "Content-Type": "application/x-www-form-urlencoded"
@@ -282,7 +282,7 @@ function Wt(e) {
282
282
  event: r,
283
283
  properties: {
284
284
  ...this.additionalProperties,
285
- ...c,
285
+ ...d,
286
286
  agentId: this.agentId,
287
287
  source: n,
288
288
  token: this.token,
@@ -297,19 +297,19 @@ function Wt(e) {
297
297
  ])
298
298
  })
299
299
  };
300
- return fetch(Ot, d).catch((p) => console.error("Analytics tracking error:", p)), Promise.resolve();
300
+ return fetch(Wt, c).catch((p) => console.error("Analytics tracking error:", p)), Promise.resolve();
301
301
  },
302
302
  linkTrack(r, o, a, s) {
303
303
  i[r] || (i[r] = { events: {}, resolvedDependencies: [] }), s.includes(a) || s.push(a);
304
- const c = i[r];
305
- if (c.events[a] = { props: o }, c.resolvedDependencies.push(a), s.every(
306
- (d) => c.resolvedDependencies.includes(d)
304
+ const d = i[r];
305
+ if (d.events[a] = { props: o }, d.resolvedDependencies.push(a), s.every(
306
+ (c) => d.resolvedDependencies.includes(c)
307
307
  )) {
308
- const d = s.reduce((p, g) => c.events[g] ? { ...p, ...c.events[g].props } : p, {});
309
- this.track(r, d), c.resolvedDependencies = c.resolvedDependencies.filter(
308
+ const c = s.reduce((p, g) => d.events[g] ? { ...p, ...d.events[g].props } : p, {});
309
+ this.track(r, c), d.resolvedDependencies = d.resolvedDependencies.filter(
310
310
  (p) => !s.includes(p)
311
311
  ), s.forEach((p) => {
312
- delete c.events[p];
312
+ delete d.events[p];
313
313
  });
314
314
  }
315
315
  }
@@ -323,33 +323,22 @@ function $e() {
323
323
  get: (n = !1) => n ? Date.now() - e : e
324
324
  };
325
325
  }
326
- const re = $e(), Ae = $e(), Je = $e(), Oe = /* @__PURE__ */ (() => {
327
- let e;
328
- return {
329
- set: (n) => {
330
- e = n;
331
- },
332
- get: () => e,
333
- reset: () => {
334
- e = void 0;
335
- }
336
- };
337
- })();
338
- function rt(e) {
339
- return e === N.Playground ? { headers: { [_t]: "true" } } : {};
326
+ const ne = $e(), Ae = $e(), We = $e();
327
+ function it(e) {
328
+ return e === N.Playground ? { headers: { [bt]: "true" } } : {};
340
329
  }
341
- async function it(e, n, i, r, o = !1, a) {
330
+ async function at(e, n, i, r, o = !1, a) {
342
331
  try {
343
- return !a && !tt(r) && (a = await n.newChat(e.id, { persist: o }, rt(r)), i.track("agent-chat", {
332
+ return !a && !nt(r) && (a = await n.newChat(e.id, { persist: o }, it(r)), i.track("agent-chat", {
344
333
  event: "created",
345
334
  chatId: a.id,
346
335
  mode: r
347
336
  })), { chat: a, chatMode: (a == null ? void 0 : a.chat_mode) ?? r };
348
337
  } catch (s) {
349
- throw Ht(s) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
338
+ throw qt(s) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
350
339
  }
351
340
  }
352
- const Ht = (e) => {
341
+ const qt = (e) => {
353
342
  try {
354
343
  const n = JSON.parse(e.message);
355
344
  return n == null ? void 0 : n.kind;
@@ -357,10 +346,10 @@ const Ht = (e) => {
357
346
  return "UnknownError";
358
347
  }
359
348
  };
360
- function qt(e) {
349
+ function Qt(e) {
361
350
  return e && e.length > 0 ? e : [];
362
351
  }
363
- function Qt(e, n, i, r) {
352
+ function Xt(e, n, i, r) {
364
353
  const o = je(e, `${n}/v2/agents/${i}`, r);
365
354
  return {
366
355
  async createStream(a) {
@@ -368,11 +357,11 @@ function Qt(e, n, i, r) {
368
357
  }
369
358
  };
370
359
  }
371
- const at = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""), Xt = {
360
+ const ot = (e, n) => (i, r) => e && console.log(`[${n}] ${i}`, r ?? ""), Yt = {
372
361
  [E.ChatAnswer]: q.Answer,
373
362
  [E.ChatPartial]: q.Partial
374
363
  };
375
- function Yt(e, n, i) {
364
+ function Gt(e, n, i) {
376
365
  const r = (n.timestamp - e.timestamp) / 1e3;
377
366
  return {
378
367
  duration: r,
@@ -392,7 +381,7 @@ function Yt(e, n, i) {
392
381
  lowFpsCount: i
393
382
  };
394
383
  }
395
- function Gt(e) {
384
+ function Zt(e) {
396
385
  return e.filter(
397
386
  (n) => n.freezeCount > 0 || n.framesPerSecond < 21 || n.framesDropped > 0 || n.packetsLost > 0
398
387
  ).map((n) => {
@@ -403,7 +392,7 @@ function Gt(e) {
403
392
  };
404
393
  });
405
394
  }
406
- function Zt(e) {
395
+ function en(e) {
407
396
  let n = "", i = 0;
408
397
  for (const r of e.values()) {
409
398
  if (r && r.type === "codec" && r.mimeType.startsWith("video") && (n = r.mimeType.split("/")[1]), r && r.type === "candidate-pair") {
@@ -433,8 +422,8 @@ function Zt(e) {
433
422
  }
434
423
  return {};
435
424
  }
436
- function We(e, n, i) {
437
- const r = e.map((t, d) => d === 0 ? i ? {
425
+ function He(e, n, i) {
426
+ const r = e.map((t, c) => c === 0 ? i ? {
438
427
  timestamp: t.timestamp,
439
428
  duration: 0,
440
429
  rtt: t.rtt,
@@ -470,127 +459,127 @@ function We(e, n, i) {
470
459
  freezeDuration: t.freezeDuration
471
460
  } : {
472
461
  timestamp: t.timestamp,
473
- duration: n * d / 1e3,
462
+ duration: n * c / 1e3,
474
463
  rtt: t.rtt,
475
- bytesReceived: t.bytesReceived - e[d - 1].bytesReceived,
476
- bitrate: (t.bytesReceived - e[d - 1].bytesReceived) * 8 / (n / 1e3),
477
- packetsReceived: t.packetsReceived - e[d - 1].packetsReceived,
478
- packetsLost: t.packetsLost - e[d - 1].packetsLost,
479
- framesDropped: t.framesDropped - e[d - 1].framesDropped,
480
- framesDecoded: t.framesDecoded - e[d - 1].framesDecoded,
464
+ bytesReceived: t.bytesReceived - e[c - 1].bytesReceived,
465
+ bitrate: (t.bytesReceived - e[c - 1].bytesReceived) * 8 / (n / 1e3),
466
+ packetsReceived: t.packetsReceived - e[c - 1].packetsReceived,
467
+ packetsLost: t.packetsLost - e[c - 1].packetsLost,
468
+ framesDropped: t.framesDropped - e[c - 1].framesDropped,
469
+ framesDecoded: t.framesDecoded - e[c - 1].framesDecoded,
481
470
  jitter: t.jitter,
482
- jitterBufferDelay: t.jitterBufferDelay - e[d - 1].jitterBufferDelay,
483
- jitterBufferEmittedCount: t.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount,
484
- avgJitterDelayInInterval: (t.jitterBufferDelay - e[d - 1].jitterBufferDelay) / (t.jitterBufferEmittedCount - e[d - 1].jitterBufferEmittedCount),
471
+ jitterBufferDelay: t.jitterBufferDelay - e[c - 1].jitterBufferDelay,
472
+ jitterBufferEmittedCount: t.jitterBufferEmittedCount - e[c - 1].jitterBufferEmittedCount,
473
+ avgJitterDelayInInterval: (t.jitterBufferDelay - e[c - 1].jitterBufferDelay) / (t.jitterBufferEmittedCount - e[c - 1].jitterBufferEmittedCount),
485
474
  framesPerSecond: t.framesPerSecond,
486
- freezeCount: t.freezeCount - e[d - 1].freezeCount,
487
- freezeDuration: t.freezeDuration - e[d - 1].freezeDuration
488
- }), o = Gt(r), a = o.reduce((t, d) => t + (d.causes.includes("low fps") ? 1 : 0), 0), s = r.filter((t) => !!t.avgJitterDelayInInterval).map((t) => t.avgJitterDelayInInterval), c = r.filter((t) => !!t.rtt).map((t) => t.rtt);
475
+ freezeCount: t.freezeCount - e[c - 1].freezeCount,
476
+ freezeDuration: t.freezeDuration - e[c - 1].freezeDuration
477
+ }), o = Zt(r), a = o.reduce((t, c) => t + (c.causes.includes("low fps") ? 1 : 0), 0), s = r.filter((t) => !!t.avgJitterDelayInInterval).map((t) => t.avgJitterDelayInInterval), d = r.filter((t) => !!t.rtt).map((t) => t.rtt);
489
478
  return {
490
479
  webRTCStats: {
491
480
  anomalies: o,
492
- minRtt: Math.min(...c),
493
- avgRtt: Ve(c),
494
- maxRtt: Math.max(...c),
495
- aggregateReport: Yt(e[0], e[e.length - 1], a),
481
+ minRtt: Math.min(...d),
482
+ avgRtt: Je(d),
483
+ maxRtt: Math.max(...d),
484
+ aggregateReport: Gt(e[0], e[e.length - 1], a),
496
485
  minJitterDelayInInterval: Math.min(...s),
497
486
  maxJitterDelayInInterval: Math.max(...s),
498
- avgJitterDelayInInterval: Ve(s)
487
+ avgJitterDelayInInterval: Je(s)
499
488
  },
500
489
  codec: e[0].codec,
501
490
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
502
491
  };
503
492
  }
504
- function ot(e, n) {
493
+ function st(e, n) {
505
494
  for (const i of e.values())
506
495
  if ((i == null ? void 0 : i.type) === "inbound-rtp" && i.kind === n)
507
496
  return i;
508
497
  return null;
509
498
  }
510
- const ge = 10;
511
- function en(e, n) {
512
- let i = !1, r = !1, o = null, a = 0, s = 0;
513
- async function c() {
499
+ const he = 10;
500
+ function tn(e, n) {
501
+ let i = !1, r = !1, o = null, a = 0, s = 0, d = {};
502
+ async function t() {
514
503
  if (i) {
515
504
  try {
516
- const t = await e();
517
- if (!t) {
518
- o = setTimeout(c, ge);
505
+ const c = await e();
506
+ if (!c) {
507
+ o = setTimeout(t, he);
519
508
  return;
520
509
  }
521
- const d = ot(t, "audio");
522
- if (!d) {
523
- o = setTimeout(c, ge);
510
+ const p = st(c, "audio");
511
+ if (!p) {
512
+ o = setTimeout(t, he);
524
513
  return;
525
514
  }
526
- const p = d.totalAudioEnergy ?? 0, g = d.totalSamplesReceived ?? 0;
515
+ const g = p.totalAudioEnergy ?? 0, l = p.totalSamplesReceived ?? 0;
527
516
  if (!r) {
528
- a = p, s = g, r = !0, o = setTimeout(c, ge);
517
+ a = g, s = l, r = !0, o = setTimeout(t, he);
529
518
  return;
530
519
  }
531
- const l = p - a, v = g - s;
532
- if (a = p, s = g, v > 0 && l > 0) {
533
- i = !1, n();
520
+ const v = g - a, D = l - s;
521
+ if (a = g, s = l, D > 0 && v > 0) {
522
+ i = !1, n(d);
534
523
  return;
535
524
  }
536
525
  } catch {
537
526
  }
538
- i && (o = setTimeout(c, ge));
527
+ i && (o = setTimeout(t, he));
539
528
  }
540
529
  }
541
530
  return {
542
- arm() {
543
- i = !0, r = !1, performance.now(), o !== null && clearTimeout(o), o = setTimeout(c, ge);
531
+ arm(c = {}) {
532
+ d = c, i = !0, r = !1, performance.now(), o !== null && clearTimeout(o), o = setTimeout(t, he);
544
533
  },
545
534
  destroy() {
546
535
  i = !1, o !== null && (clearTimeout(o), o = null);
547
536
  }
548
537
  };
549
538
  }
550
- const Se = 100, tn = Math.max(Math.ceil(400 / Se), 1), nn = 0.25, rn = 0.28;
551
- function an() {
539
+ const Se = 100, nn = Math.max(Math.ceil(400 / Se), 1), rn = 0.25, an = 0.28;
540
+ function on() {
552
541
  let e = 0, n, i, r = 0;
553
542
  return (o) => {
554
- const a = ot(o, "video");
543
+ const a = st(o, "video");
555
544
  if (!a)
556
545
  return { isReceiving: !1, avgJitterDelayInInterval: r };
557
- const s = a.jitterBufferDelay, c = a.jitterBufferEmittedCount;
558
- if (i && c > i) {
559
- const p = s - n, g = c - i;
546
+ const s = a.jitterBufferDelay, d = a.jitterBufferEmittedCount;
547
+ if (i && d > i) {
548
+ const p = s - n, g = d - i;
560
549
  r = p / g;
561
550
  }
562
- n = s, i = c;
563
- const t = a.framesDecoded, d = t - e > 0;
564
- return e = t, { isReceiving: d, avgJitterDelayInInterval: r, freezeCount: a.freezeCount };
551
+ n = s, i = d;
552
+ const t = a.framesDecoded, c = t - e > 0;
553
+ return e = t, { isReceiving: c, avgJitterDelayInInterval: r, freezeCount: a.freezeCount };
565
554
  };
566
555
  }
567
- function st(e, n, i, r, o) {
568
- let a = null, s = [], c, t = 0, d = !1, p = ne.Unknown, g = ne.Unknown, l = 0, v = 0;
569
- const b = an();
570
- async function x() {
556
+ function ct(e, n, i, r, o) {
557
+ let a = null, s = [], d, t = 0, c = !1, p = te.Unknown, g = te.Unknown, l = 0, v = 0;
558
+ const D = on();
559
+ async function B() {
571
560
  const L = await e();
572
561
  if (!L)
573
562
  return;
574
- const { isReceiving: j, avgJitterDelayInInterval: D, freezeCount: k } = b(L), O = Zt(L);
563
+ const { isReceiving: j, avgJitterDelayInInterval: M, freezeCount: k } = D(L), O = en(L);
575
564
  if (j)
576
- t = 0, l = k - v, g = D < nn ? ne.Strong : D > rn && l > 1 ? ne.Weak : p, g !== p && (o == null || o(g), p = g, v += l, l = 0), d || (r == null || r(T.Start), c = s[s.length - 1], s = [], d = !0), s.push(O);
577
- else if (d && (t++, t >= tn)) {
578
- const W = We(s, Se, c);
579
- r == null || r(T.Stop, W), n() || i(), v = k, d = !1;
565
+ t = 0, l = k - v, g = M < rn ? te.Strong : M > an && l > 1 ? te.Weak : p, g !== p && (o == null || o(g), p = g, v += l, l = 0), c || (r == null || r(T.Start), d = s[s.length - 1], s = [], c = !0), s.push(O);
566
+ else if (c && (t++, t >= nn)) {
567
+ const W = He(s, Se, d);
568
+ r == null || r(T.Stop, W), n() || i(), v = k, c = !1;
580
569
  }
581
570
  }
582
571
  return {
583
572
  start: () => {
584
- a || (a = setInterval(x, Se));
573
+ a || (a = setInterval(B, Se));
585
574
  },
586
575
  stop: () => {
587
576
  a && (clearInterval(a), a = null);
588
577
  },
589
- getReport: () => We(s, Se, c)
578
+ getReport: () => He(s, Se, d)
590
579
  };
591
580
  }
592
- const He = 2e4;
593
- async function on() {
581
+ const qe = 2e4;
582
+ async function sn() {
594
583
  try {
595
584
  return await import("./livekit-client.esm-RGXA_gNu.js");
596
585
  } catch {
@@ -599,92 +588,92 @@ async function on() {
599
588
  );
600
589
  }
601
590
  }
602
- const sn = {
603
- excellent: ne.Strong,
604
- good: ne.Strong,
605
- poor: ne.Weak,
606
- lost: ne.Unknown,
607
- unknown: ne.Unknown
608
- }, he = JSON.stringify({
591
+ const cn = {
592
+ excellent: te.Strong,
593
+ good: te.Strong,
594
+ poor: te.Weak,
595
+ lost: te.Unknown,
596
+ unknown: te.Unknown
597
+ }, pe = JSON.stringify({
609
598
  kind: "InternalServerError",
610
599
  description: "Stream Error"
611
600
  });
612
- var Be = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Be || {});
601
+ var xe = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(xe || {});
613
602
  function _e(e, n, i) {
614
603
  var r, o;
615
- throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i, _.Fail, "internal:init-error"), (o = i.onError) == null || o.call(i, e, { sessionId: "" }), e;
604
+ throw n("Failed to connect to LiveKit room:", e), (r = i.onConnectionStateChange) == null || r.call(i, b.Fail, "internal:init-error"), (o = i.onError) == null || o.call(i, e, { sessionId: "" }), e;
616
605
  }
617
- async function cn(e, n, i) {
606
+ async function dn(e, n, i) {
618
607
  var ze;
619
- const r = at(i.debug || !1, "LiveKitStreamingManager"), { Room: o, RoomEvent: a, ConnectionState: s, Track: c } = await on(), { callbacks: t, auth: d, baseURL: p, analytics: g } = i;
608
+ const r = ot(i.debug || !1, "LiveKitStreamingManager"), { Room: o, RoomEvent: a, ConnectionState: s, Track: d } = await sn(), { callbacks: t, auth: c, baseURL: p, analytics: g } = i;
620
609
  let l = null, v = !1;
621
- const b = ie.Fluent;
622
- let x = null;
610
+ const D = re.Fluent;
611
+ let B = null;
623
612
  const L = { isPublishing: !1, publication: null }, j = { isPublishing: !1, publication: null };
624
- let D = null, k = null, O = null, W = !1;
613
+ let M = null, k = null, O = null, W = !1;
625
614
  l = new o({
626
615
  adaptiveStream: !1,
627
616
  // Must be false to use mediaStreamTrack directly
628
617
  dynacast: !0
629
618
  });
630
- let F = null, Y = J.Idle, ae = !0;
631
- const se = Qt(d, p || pe, e, t.onError);
632
- let f, S, R;
619
+ let F = null, Y = J.Idle, ie = !0;
620
+ const se = Xt(c, p || we, e, t.onError);
621
+ let m, S, R;
633
622
  try {
634
623
  const u = await se.createStream({
635
624
  transport: n.transport,
636
625
  chat_persist: n.chat_persist ?? !0
637
- }), { id: m, session_token: w, session_url: C } = u;
638
- (ze = t.onStreamCreated) == null || ze.call(t, { session_id: m, stream_id: m, agent_id: e }), f = m, S = w, R = C, await l.prepareConnection(R, S);
626
+ }), { id: f, session_token: w, session_url: C } = u;
627
+ (ze = t.onStreamCreated) == null || ze.call(t, { session_id: f, stream_id: f, agent_id: e }), m = f, S = w, R = C, await l.prepareConnection(R, S);
639
628
  } catch (u) {
640
629
  _e(u, r, t);
641
630
  }
642
- if (!R || !S || !f)
631
+ if (!R || !S || !m)
643
632
  return Promise.reject(new Error("Failed to initialize LiveKit stream"));
644
- l.on(a.ConnectionStateChanged, $).on(a.ConnectionQualityChanged, M).on(a.ParticipantConnected, U).on(a.ParticipantDisconnected, Q).on(a.TrackSubscribed, K).on(a.TrackUnsubscribed, G).on(a.DataReceived, we).on(a.MediaDevicesError, ye).on(a.TranscriptionReceived, V).on(a.EncryptionError, ve).on(a.TrackSubscriptionFailed, ct);
645
- function V(u, m) {
633
+ l.on(a.ConnectionStateChanged, $).on(a.ConnectionQualityChanged, A).on(a.ParticipantConnected, U).on(a.ParticipantDisconnected, Q).on(a.TrackSubscribed, K).on(a.TrackUnsubscribed, G).on(a.DataReceived, ye).on(a.MediaDevicesError, ve).on(a.TranscriptionReceived, V).on(a.EncryptionError, Ce).on(a.TrackSubscriptionFailed, dt);
634
+ function V(u, f) {
646
635
  var w;
647
- m != null && m.isLocal && (re.update(), Y === J.Talking && ((w = t.onInterruptDetected) == null || w.call(t, { type: "audio" }), Y = J.Idle));
636
+ f != null && f.isLocal && (ne.update(), Y === J.Talking && ((w = t.onInterruptDetected) == null || w.call(t, { type: "audio" }), Y = J.Idle));
648
637
  }
649
638
  try {
650
639
  await l.connect(R, S), r("LiveKit room joined successfully"), F = setTimeout(() => {
651
640
  var u;
652
641
  r(
653
- `Track subscription timeout - no track subscribed within ${He / 1e3} seconds after connect`
642
+ `Track subscription timeout - no track subscribed within ${qe / 1e3} seconds after connect`
654
643
  ), F = null, g.track("connectivity-error", {
655
644
  error: "Track subscription timeout",
656
- sessionId: f
657
- }), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId: f }), Ie("internal:track-subscription-timeout");
658
- }, He);
645
+ sessionId: m
646
+ }), (u = t.onError) == null || u.call(t, new Error("Track subscription timeout"), { sessionId: m }), Ie("internal:track-subscription-timeout");
647
+ }, qe);
659
648
  } catch (u) {
660
649
  _e(u, r, t);
661
650
  }
662
651
  g.enrich({
663
- "stream-type": b
652
+ "stream-type": D
664
653
  });
665
654
  function $(u) {
666
- var m, w, C, A;
655
+ var f, w, C, _;
667
656
  switch (r("Connection state changed:", u), u) {
668
657
  case s.Connecting:
669
- r("CALLBACK: onConnectionStateChange(Connecting)"), (m = t.onConnectionStateChange) == null || m.call(t, _.Connecting, "livekit:connecting");
658
+ r("CALLBACK: onConnectionStateChange(Connecting)"), (f = t.onConnectionStateChange) == null || f.call(t, b.Connecting, "livekit:connecting");
670
659
  break;
671
660
  case s.Connected:
672
661
  r("LiveKit room connected successfully"), v = !0;
673
662
  break;
674
663
  case s.Disconnected:
675
- r("LiveKit room disconnected"), v = !1, W = !1, L.publication = null, j.publication = null, (w = t.onConnectionStateChange) == null || w.call(t, _.Disconnected, "livekit:disconnected");
664
+ r("LiveKit room disconnected"), v = !1, W = !1, L.publication = null, j.publication = null, (w = t.onConnectionStateChange) == null || w.call(t, b.Disconnected, "livekit:disconnected");
676
665
  break;
677
666
  case s.Reconnecting:
678
- r("LiveKit room reconnecting..."), (C = t.onConnectionStateChange) == null || C.call(t, _.Connecting, "livekit:reconnecting");
667
+ r("LiveKit room reconnecting..."), (C = t.onConnectionStateChange) == null || C.call(t, b.Connecting, "livekit:reconnecting");
679
668
  break;
680
669
  case s.SignalReconnecting:
681
- r("LiveKit room signal reconnecting..."), (A = t.onConnectionStateChange) == null || A.call(t, _.Connecting, "livekit:signal-reconnecting");
670
+ r("LiveKit room signal reconnecting..."), (_ = t.onConnectionStateChange) == null || _.call(t, b.Connecting, "livekit:signal-reconnecting");
682
671
  break;
683
672
  }
684
673
  }
685
- function M(u, m) {
674
+ function A(u, f) {
686
675
  var w;
687
- r("Connection quality:", u), m != null && m.isLocal && ((w = t.onConnectivityStateChange) == null || w.call(t, sn[u]));
676
+ r("Connection quality:", u), f != null && f.isLocal && ((w = t.onConnectivityStateChange) == null || w.call(t, cn[u]));
688
677
  }
689
678
  function U(u) {
690
679
  r("Participant connected:", u.identity);
@@ -696,82 +685,85 @@ async function cn(e, n, i) {
696
685
  var u;
697
686
  O !== T.Start && (r("CALLBACK: onVideoStateChange(Start)"), O = T.Start, (u = t.onVideoStateChange) == null || u.call(t, T.Start));
698
687
  }
699
- function B(u) {
700
- var m;
701
- O !== T.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), O = T.Stop, (m = t.onVideoStateChange) == null || m.call(t, T.Stop, u));
688
+ function x(u) {
689
+ var f;
690
+ O !== T.Stop && (r("CALLBACK: onVideoStateChange(Stop)"), O = T.Stop, (f = t.onVideoStateChange) == null || f.call(t, T.Stop, u));
702
691
  }
703
- function K(u, m, w) {
704
- var A, P, H;
692
+ function K(u, f, w) {
693
+ var _, P, H;
705
694
  r(`Track subscribed: ${u.kind} from ${w.identity}`);
706
695
  const C = u.mediaStreamTrack;
707
696
  if (!C) {
708
697
  r(`No mediaStreamTrack available for ${u.kind}`);
709
698
  return;
710
699
  }
711
- x ? (x.addTrack(C), r(`Added ${u.kind} track to shared MediaStream`)) : (x = new MediaStream([C]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (k = en(
700
+ B ? (B.addTrack(C), r(`Added ${u.kind} track to shared MediaStream`)) : (B = new MediaStream([C]), r(`Created shared MediaStream with ${u.kind} track`)), u.kind === "audio" && (k = tn(
712
701
  () => u.getRTCStatsReport(),
713
- () => {
714
- var fe, te, Ke;
715
- const z = re.get(!0), ee = Oe.get();
716
- let le = 0;
717
- if (ee) {
718
- const Ne = ((te = (fe = D == null ? void 0 : D.getReport()) == null ? void 0 : fe.webRTCStats) == null ? void 0 : te.avgRtt) ?? 0;
719
- le = Ne > 0 ? Math.round(Ne * 1e3) : 0;
702
+ ({ sttLatency: z, serviceLatency: ee }) => {
703
+ var Ke, Ne, Ve;
704
+ const me = ne.get(!0);
705
+ let fe = 0;
706
+ if (z) {
707
+ const Ue = ((Ne = (Ke = M == null ? void 0 : M.getReport()) == null ? void 0 : Ke.webRTCStats) == null ? void 0 : Ne.avgRtt) ?? 0;
708
+ fe = Ue > 0 ? Math.round(Ue * 1e3) : 0;
720
709
  }
721
- const Ce = z > 0 ? z + (ee ?? 0) + le : void 0;
722
- (Ke = t.onFirstAudioDetected) == null || Ke.call(t, Ce);
710
+ const de = me > 0 ? me + (z ?? 0) + fe : void 0, oe = de !== void 0 && ee !== void 0 ? de - ee : void 0;
711
+ (Ve = t.onFirstAudioDetected) == null || Ve.call(t, { latency: de, networkLatency: oe });
723
712
  }
724
- )), u.kind === "video" && ((A = t.onStreamReady) == null || A.call(t), r("CALLBACK: onSrcObjectReady"), (P = t.onSrcObjectReady) == null || P.call(t, x), W || (W = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (H = t.onConnectionStateChange) == null || H.call(t, _.Connected, "livekit:track-subscribed")), D = st(
713
+ )), u.kind === "video" && ((_ = t.onStreamReady) == null || _.call(t), r("CALLBACK: onSrcObjectReady"), (P = t.onSrcObjectReady) == null || P.call(t, B), W || (W = !0, r("CALLBACK: onConnectionStateChange(Connected)"), (H = t.onConnectionStateChange) == null || H.call(t, b.Connected, "livekit:track-subscribed")), M = ct(
725
714
  () => u.getRTCStatsReport(),
726
715
  () => v,
727
- Lt,
716
+ jt,
728
717
  (z, ee) => {
729
- r(`Video state change: ${z}`), z === T.Start ? (F && (clearTimeout(F), F = null, r("Track subscription timeout cleared")), X()) : z === T.Stop && B(ee);
718
+ r(`Video state change: ${z}`), z === T.Start ? (F && (clearTimeout(F), F = null, r("Track subscription timeout cleared")), X()) : z === T.Stop && x(ee);
730
719
  }
731
- ), D.start());
720
+ ), M.start());
732
721
  }
733
- function G(u, m, w) {
734
- r(`Track unsubscribed: ${u.kind} from ${w.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (B(D == null ? void 0 : D.getReport()), D == null || D.stop(), D = null);
722
+ function G(u, f, w) {
723
+ r(`Track unsubscribed: ${u.kind} from ${w.identity}`), u.kind === "audio" && (k == null || k.destroy(), k = null), u.kind === "video" && (x(M == null ? void 0 : M.getReport()), M == null || M.stop(), M = null);
735
724
  }
736
- function oe(u, m) {
725
+ function ae(u, f) {
737
726
  var C;
738
- const w = Xt[u];
739
- w && ((C = t.onMessage) == null || C.call(t, w, { event: w, ...m }));
727
+ const w = Yt[u];
728
+ w && ((C = t.onMessage) == null || C.call(t, w, { event: w, ...f }));
740
729
  }
741
- function y(u, m) {
742
- var w, C, A;
730
+ function y(u, f) {
731
+ var w, C, _;
743
732
  if (u === E.ToolCalling) {
744
- Y = J.ToolActive, (w = t.onAgentActivityStateChange) == null || w.call(t, J.ToolActive), (C = t.onToolEvent) == null || C.call(t, E.ToolCalling, m);
733
+ Y = J.ToolActive, (w = t.onAgentActivityStateChange) == null || w.call(t, J.ToolActive), (C = t.onToolEvent) == null || C.call(t, E.ToolCalling, f);
745
734
  return;
746
735
  }
747
- u === E.ToolResult && ((A = t.onToolEvent) == null || A.call(t, E.ToolResult, m));
736
+ u === E.ToolResult && ((_ = t.onToolEvent) == null || _.call(t, E.ToolResult, f));
748
737
  }
749
- function h(u, m) {
750
- var w, C, A, P, H;
751
- if (ae = ((w = m.metadata) == null ? void 0 : w.interruptible) !== !1, (C = t.onInterruptibleChange) == null || C.call(t, ae), u === E.StreamVideoCreated) {
752
- Y = J.Talking, (A = t.onAgentActivityStateChange) == null || A.call(t, J.Talking), Oe.set((P = m == null ? void 0 : m.stt) == null ? void 0 : P.latency), k == null || k.arm();
738
+ function h(u, f) {
739
+ var w, C, _, P, H;
740
+ if (ie = ((w = f.metadata) == null ? void 0 : w.interruptible) !== !1, (C = t.onInterruptibleChange) == null || C.call(t, ie), u === E.StreamVideoCreated) {
741
+ Y = J.Talking, (_ = t.onAgentActivityStateChange) == null || _.call(t, J.Talking), k == null || k.arm({
742
+ sttLatency: (P = f == null ? void 0 : f.stt) == null ? void 0 : P.latency,
743
+ serviceLatency: f == null ? void 0 : f.serviceLatency
744
+ });
753
745
  return;
754
746
  }
755
- ae && (Y = J.Idle, (H = t.onAgentActivityStateChange) == null || H.call(t, J.Idle));
747
+ ie && (Y = J.Idle, (H = t.onAgentActivityStateChange) == null || H.call(t, J.Idle));
756
748
  }
757
- function I(u, m) {
749
+ function I(u, f) {
758
750
  var P, H, z, ee;
759
- const w = ((H = (P = D == null ? void 0 : D.getReport()) == null ? void 0 : P.webRTCStats) == null ? void 0 : H.avgRtt) ?? 0, C = w > 0 ? Math.round(w / 2 * 1e3) : 0, A = { ...m, downstreamNetworkLatency: C };
760
- i.debug && ((z = m == null ? void 0 : m.metadata) != null && z.sentiment) && (A.sentiment = {
761
- id: m.metadata.sentiment.id,
762
- name: m.metadata.sentiment.sentiment
763
- }), (ee = t.onMessage) == null || ee.call(t, u, A), h(u, m);
751
+ const w = ((H = (P = M == null ? void 0 : M.getReport()) == null ? void 0 : P.webRTCStats) == null ? void 0 : H.avgRtt) ?? 0, C = w > 0 ? Math.round(w / 2 * 1e3) : 0, _ = { ...f, downstreamNetworkLatency: C };
752
+ i.debug && ((z = f == null ? void 0 : f.metadata) != null && z.sentiment) && (_.sentiment = {
753
+ id: f.metadata.sentiment.id,
754
+ name: f.metadata.sentiment.sentiment
755
+ }), (ee = t.onMessage) == null || ee.call(t, u, _), h(u, f);
764
756
  }
765
- function Z(u, m) {
757
+ function Z(u, f) {
766
758
  var w;
767
- (w = t.onMessage) == null || w.call(t, q.Transcribe, { event: q.Transcribe, ...m }), queueMicrotask(() => {
759
+ (w = t.onMessage) == null || w.call(t, q.Transcribe, { event: q.Transcribe, ...f }), queueMicrotask(() => {
768
760
  var C;
769
761
  (C = t.onAgentActivityStateChange) == null || C.call(t, J.Loading);
770
762
  });
771
763
  }
772
764
  const ce = {
773
- [E.ChatAnswer]: oe,
774
- [E.ChatPartial]: oe,
765
+ [E.ChatAnswer]: ae,
766
+ [E.ChatPartial]: ae,
775
767
  [E.ToolCalling]: y,
776
768
  [E.ToolResult]: y,
777
769
  [E.StreamVideoCreated]: I,
@@ -780,10 +772,10 @@ async function cn(e, n, i) {
780
772
  [E.StreamVideoRejected]: I,
781
773
  [E.ChatAudioTranscribed]: Z
782
774
  };
783
- function we(u, m, w, C) {
784
- const A = new TextDecoder().decode(u);
775
+ function ye(u, f, w, C) {
776
+ const _ = new TextDecoder().decode(u);
785
777
  try {
786
- const P = JSON.parse(A), H = C || P.subject;
778
+ const P = JSON.parse(_), H = C || P.subject;
787
779
  if (r("Data received:", { subject: H, data: P }), !H) return;
788
780
  const z = ce[H];
789
781
  z == null || z(H, P);
@@ -791,74 +783,74 @@ async function cn(e, n, i) {
791
783
  r("Failed to parse data channel message:", P);
792
784
  }
793
785
  }
794
- function ye(u) {
795
- var m;
796
- r("Media devices error:", u), (m = t.onError) == null || m.call(t, new Error(he), { sessionId: f });
797
- }
798
786
  function ve(u) {
799
- var m;
800
- r("Encryption error:", u), (m = t.onError) == null || m.call(t, new Error(he), { sessionId: f });
787
+ var f;
788
+ r("Media devices error:", u), (f = t.onError) == null || f.call(t, new Error(pe), { sessionId: m });
801
789
  }
802
- function ct(u, m, w) {
803
- r("Track subscription failed:", { trackSid: u, participant: m, reason: w });
790
+ function Ce(u) {
791
+ var f;
792
+ r("Encryption error:", u), (f = t.onError) == null || f.call(t, new Error(pe), { sessionId: m });
804
793
  }
805
- function dt(u, m, w) {
806
- for (const [C, A] of w)
807
- if (A.source === m && A.track) {
808
- const P = A.track.mediaStreamTrack;
794
+ function dt(u, f, w) {
795
+ r("Track subscription failed:", { trackSid: u, participant: f, reason: w });
796
+ }
797
+ function ut(u, f, w) {
798
+ for (const [C, _] of w)
799
+ if (_.source === f && _.track) {
800
+ const P = _.track.mediaStreamTrack;
809
801
  if (P === u || (P == null ? void 0 : P.id) === u.id)
810
- return A;
802
+ return _;
811
803
  }
812
804
  return null;
813
805
  }
814
- async function xe(u, m, w, C, A, P) {
815
- var le, Ce, fe;
806
+ async function Be(u, f, w, C, _, P) {
807
+ var me, fe, de;
816
808
  if (!v || !l)
817
809
  throw r(`Room is not connected, cannot publish ${C} stream`), new Error("Room is not connected");
818
810
  if (u.isPublishing) {
819
811
  r(`${C} publish already in progress, skipping`);
820
812
  return;
821
813
  }
822
- const H = w(m);
814
+ const H = w(f);
823
815
  if (H.length === 0)
824
816
  throw new Error(`No ${C} track found in the provided MediaStream`);
825
- const z = H[0], ee = dt(z, C, A());
817
+ const z = H[0], ee = ut(z, C, _());
826
818
  if (ee) {
827
819
  r(`${C} track is already published, skipping`, {
828
820
  trackId: z.id,
829
- publishedTrackId: (Ce = (le = ee.track) == null ? void 0 : le.mediaStreamTrack) == null ? void 0 : Ce.id
821
+ publishedTrackId: (fe = (me = ee.track) == null ? void 0 : me.mediaStreamTrack) == null ? void 0 : fe.id
830
822
  }), u.publication = ee;
831
823
  return;
832
824
  }
833
- if ((fe = u.publication) != null && fe.track) {
834
- const te = u.publication.track.mediaStreamTrack;
835
- te !== z && (te == null ? void 0 : te.id) !== z.id && (r(`Unpublishing existing ${C} track before publishing new one`), await P());
825
+ if ((de = u.publication) != null && de.track) {
826
+ const oe = u.publication.track.mediaStreamTrack;
827
+ oe !== z && (oe == null ? void 0 : oe.id) !== z.id && (r(`Unpublishing existing ${C} track before publishing new one`), await P());
836
828
  }
837
829
  r(`Publishing ${C} track from provided MediaStream`, { trackId: z.id }), u.isPublishing = !0;
838
830
  try {
839
831
  u.publication = await l.localParticipant.publishTrack(z, { source: C }), r(`${C} track published successfully`, { trackSid: u.publication.trackSid });
840
- } catch (te) {
841
- throw r(`Failed to publish ${C} track:`, te), te;
832
+ } catch (oe) {
833
+ throw r(`Failed to publish ${C} track:`, oe), oe;
842
834
  } finally {
843
835
  u.isPublishing = !1;
844
836
  }
845
837
  }
846
- async function Fe(u, m) {
838
+ async function Fe(u, f) {
847
839
  if (!(!u.publication || !u.publication.track))
848
840
  try {
849
- l && (await l.localParticipant.unpublishTrack(u.publication.track, !1), r(`${m} track unpublished`));
841
+ l && (await l.localParticipant.unpublishTrack(u.publication.track, !1), r(`${f} track unpublished`));
850
842
  } catch (w) {
851
- r(`Error unpublishing ${m} track:`, w);
843
+ r(`Error unpublishing ${f} track:`, w);
852
844
  } finally {
853
845
  u.publication = null;
854
846
  }
855
847
  }
856
- async function ut(u) {
857
- return xe(
848
+ async function lt(u) {
849
+ return Be(
858
850
  L,
859
851
  u,
860
- (m) => m.getAudioTracks(),
861
- c.Source.Microphone,
852
+ (f) => f.getAudioTracks(),
853
+ d.Source.Microphone,
862
854
  () => l.localParticipant.audioTrackPublications,
863
855
  Te
864
856
  );
@@ -866,12 +858,12 @@ async function cn(e, n, i) {
866
858
  async function Te() {
867
859
  return Fe(L, "Microphone");
868
860
  }
869
- async function lt(u) {
870
- return xe(
861
+ async function mt(u) {
862
+ return Be(
871
863
  j,
872
864
  u,
873
- (m) => m.getVideoTracks(),
874
- c.Source.Camera,
865
+ (f) => f.getVideoTracks(),
866
+ d.Source.Camera,
875
867
  () => l.localParticipant.videoTrackPublications,
876
868
  ke
877
869
  );
@@ -880,32 +872,32 @@ async function cn(e, n, i) {
880
872
  return Fe(j, "Camera");
881
873
  }
882
874
  function ft() {
883
- x && (x.getTracks().forEach((u) => u.stop()), x = null);
875
+ B && (B.getTracks().forEach((u) => u.stop()), B = null);
884
876
  }
885
- async function Ee(u, m) {
877
+ async function Ee(u, f) {
886
878
  var w, C;
887
879
  if (!v || !l) {
888
- r("Room is not connected for sending messages"), (w = t.onError) == null || w.call(t, new Error(he), {
889
- sessionId: f
880
+ r("Room is not connected for sending messages"), (w = t.onError) == null || w.call(t, new Error(pe), {
881
+ sessionId: m
890
882
  });
891
883
  return;
892
884
  }
893
885
  try {
894
- await l.localParticipant.sendText(u, { topic: m }), r("Message sent successfully:", u);
895
- } catch (A) {
896
- r("Failed to send message:", A), (C = t.onError) == null || C.call(t, new Error(he), { sessionId: f });
886
+ await l.localParticipant.sendText(u, { topic: f }), r("Message sent successfully:", u);
887
+ } catch (_) {
888
+ r("Failed to send message:", _), (C = t.onError) == null || C.call(t, new Error(pe), { sessionId: m });
897
889
  }
898
890
  }
899
- async function mt(u) {
900
- var m;
891
+ async function gt(u) {
892
+ var f;
901
893
  try {
902
894
  const C = JSON.parse(u).topic;
903
895
  return Ee("", C);
904
896
  } catch (w) {
905
- r("Failed to send data channel message:", w), (m = t.onError) == null || m.call(t, new Error(he), { sessionId: f });
897
+ r("Failed to send data channel message:", w), (f = t.onError) == null || f.call(t, new Error(pe), { sessionId: m });
906
898
  }
907
899
  }
908
- function gt(u) {
900
+ function ht(u) {
909
901
  return Ee(
910
902
  u,
911
903
  "lk.chat"
@@ -913,35 +905,35 @@ async function cn(e, n, i) {
913
905
  );
914
906
  }
915
907
  async function Ie(u) {
916
- var m, w;
917
- F && (clearTimeout(F), F = null), k == null || k.destroy(), k = null, l && ((m = t.onConnectionStateChange) == null || m.call(t, _.Disconnecting, u), await Promise.all([Te(), ke()]), await l.disconnect()), ft(), v = !1, W = !1, (w = t.onAgentActivityStateChange) == null || w.call(t, J.Idle), Y = J.Idle;
908
+ var f, w;
909
+ F && (clearTimeout(F), F = null), k == null || k.destroy(), k = null, l && ((f = t.onConnectionStateChange) == null || f.call(t, b.Disconnecting, u), await Promise.all([Te(), ke()]), await l.disconnect()), ft(), v = !1, W = !1, (w = t.onAgentActivityStateChange) == null || w.call(t, J.Idle), Y = J.Idle;
918
910
  }
919
911
  return {
920
912
  speak(u) {
921
- const m = typeof u == "string" ? u : JSON.stringify(u);
913
+ const f = typeof u == "string" ? u : JSON.stringify(u);
922
914
  return Ee(
923
- m,
915
+ f,
924
916
  "did.speak"
925
917
  /* Speak */
926
918
  );
927
919
  },
928
920
  disconnect: () => Ie("user:disconnect"),
929
921
  async reconnect() {
930
- var u, m;
922
+ var u, f;
931
923
  if ((l == null ? void 0 : l.state) === s.Connected) {
932
924
  r("Room is already connected");
933
925
  return;
934
926
  }
935
927
  if (!l || !R || !S)
936
928
  throw r("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
937
- r("Reconnecting to LiveKit room, state:", l.state), W = !1, (u = t.onConnectionStateChange) == null || u.call(t, _.Connecting, "user:reconnect");
929
+ r("Reconnecting to LiveKit room, state:", l.state), W = !1, (u = t.onConnectionStateChange) == null || u.call(t, b.Connecting, "user:reconnect");
938
930
  try {
939
931
  if (await l.connect(R, S), r("Room reconnected"), v = !0, l.remoteParticipants.size === 0) {
940
932
  if (r("Waiting for agent to join..."), !await new Promise((C) => {
941
- const A = setTimeout(() => {
933
+ const _ = setTimeout(() => {
942
934
  l == null || l.off(a.ParticipantConnected, P), C(!1);
943
935
  }, 5e3), P = () => {
944
- clearTimeout(A), l == null || l.off(a.ParticipantConnected, P), C(!0);
936
+ clearTimeout(_), l == null || l.off(a.ParticipantConnected, P), C(!0);
945
937
  };
946
938
  l == null || l.on(a.ParticipantConnected, P);
947
939
  }))
@@ -949,40 +941,40 @@ async function cn(e, n, i) {
949
941
  r("Agent joined, reconnection successful");
950
942
  }
951
943
  } catch (w) {
952
- throw r("Failed to reconnect:", w), (m = t.onConnectionStateChange) == null || m.call(t, _.Fail, "user:reconnect-failed"), w;
944
+ throw r("Failed to reconnect:", w), (f = t.onConnectionStateChange) == null || f.call(t, b.Fail, "user:reconnect-failed"), w;
953
945
  }
954
946
  },
955
- sendDataChannelMessage: mt,
956
- sendTextMessage: gt,
957
- publishMicrophoneStream: ut,
947
+ sendDataChannelMessage: gt,
948
+ sendTextMessage: ht,
949
+ publishMicrophoneStream: lt,
958
950
  unpublishMicrophoneStream: Te,
959
- publishCameraStream: lt,
951
+ publishCameraStream: mt,
960
952
  unpublishCameraStream: ke,
961
- sessionId: f,
962
- streamId: f,
963
- streamType: b,
953
+ sessionId: m,
954
+ streamId: m,
955
+ streamType: D,
964
956
  interruptAvailable: !0,
965
- isInterruptible: ae,
957
+ isInterruptible: ie,
966
958
  triggersAvailable: !1
967
959
  };
968
960
  }
969
- const dn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
961
+ const un = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
970
962
  __proto__: null,
971
- DataChannelTopic: Be,
972
- createLiveKitStreamingManager: cn,
963
+ DataChannelTopic: xe,
964
+ createLiveKitStreamingManager: dn,
973
965
  handleInitError: _e
974
966
  }, Symbol.toStringTag, { value: "Module" }));
975
- function un(e, n, i) {
967
+ function ln(e, n, i) {
976
968
  if (!e)
977
969
  throw new Error("Please connect to the agent first");
978
970
  if (!e.interruptAvailable)
979
971
  throw new Error("Interrupt is not enabled for this stream");
980
- if (n !== ie.Fluent)
972
+ if (n !== re.Fluent)
981
973
  throw new Error("Interrupt only available for Fluent streams");
982
974
  if (!i)
983
975
  throw new Error("No active video to interrupt");
984
976
  }
985
- async function ln(e, n) {
977
+ async function mn(e, n) {
986
978
  const i = {
987
979
  type: E.StreamInterrupt,
988
980
  videoId: n,
@@ -992,46 +984,46 @@ async function ln(e, n) {
992
984
  }
993
985
  async function fn(e) {
994
986
  const n = {
995
- topic: Be.Interrupt
987
+ topic: xe.Interrupt
996
988
  };
997
989
  e.sendDataChannelMessage(JSON.stringify(n));
998
990
  }
999
- function mn(e) {
991
+ function gn(e) {
1000
992
  return new Promise((n, i) => {
1001
- const { callbacks: r, host: o, auth: a, externalId: s } = e, { onMessage: c = null, onOpen: t = null, onClose: d = null, onError: p = null } = r || {}, g = new WebSocket(`${o}?authorization=${encodeURIComponent(nt(a, s))}`);
1002
- g.onmessage = c, g.onclose = d, g.onerror = (l) => {
993
+ const { callbacks: r, host: o, auth: a, externalId: s } = e, { onMessage: d = null, onOpen: t = null, onClose: c = null, onError: p = null } = r || {}, g = new WebSocket(`${o}?authorization=${encodeURIComponent(rt(a, s))}`);
994
+ g.onmessage = d, g.onclose = c, g.onerror = (l) => {
1003
995
  console.error(l), p == null || p("Websocket failed to connect", l), i(l);
1004
996
  }, g.onopen = (l) => {
1005
997
  t == null || t(l), n(g);
1006
998
  };
1007
999
  });
1008
1000
  }
1009
- async function gn(e) {
1001
+ async function hn(e) {
1010
1002
  const { retries: n = 1 } = e;
1011
1003
  let i = null;
1012
1004
  for (let r = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; r++)
1013
1005
  try {
1014
- i = await mn(e);
1006
+ i = await gn(e);
1015
1007
  } catch (o) {
1016
1008
  if (r === n)
1017
1009
  throw o;
1018
- await Ze(r * 500);
1010
+ await et(r * 500);
1019
1011
  }
1020
1012
  return i;
1021
1013
  }
1022
- async function hn(e, n, i, r) {
1023
- const o = i != null && i.onMessage ? [i.onMessage] : [], a = await gn({
1014
+ async function pn(e, n, i, r) {
1015
+ const o = i != null && i.onMessage ? [i.onMessage] : [], a = await hn({
1024
1016
  auth: e,
1025
1017
  host: n,
1026
1018
  externalId: r,
1027
1019
  callbacks: {
1028
1020
  onError: (s) => {
1029
- var c;
1030
- return (c = i.onError) == null ? void 0 : c.call(i, new vt(s));
1021
+ var d;
1022
+ return (d = i.onError) == null ? void 0 : d.call(i, new Ct(s));
1031
1023
  },
1032
1024
  onMessage(s) {
1033
- const c = JSON.parse(s.data);
1034
- o.forEach((t) => t(c.event, c));
1025
+ const d = JSON.parse(s.data);
1026
+ o.forEach((t) => t(d.event, d));
1035
1027
  }
1036
1028
  }
1037
1029
  });
@@ -1041,7 +1033,7 @@ async function hn(e, n, i, r) {
1041
1033
  subscribeToEvents: (s) => o.push(s)
1042
1034
  };
1043
1035
  }
1044
- function pn(e) {
1036
+ function wn(e) {
1045
1037
  if (e.answer !== void 0)
1046
1038
  return e.answer;
1047
1039
  let n = 0, i = "";
@@ -1049,7 +1041,7 @@ function pn(e) {
1049
1041
  i += e[n++];
1050
1042
  return i;
1051
1043
  }
1052
- function wn(e, n, i) {
1044
+ function yn(e, n, i) {
1053
1045
  if (!e.content)
1054
1046
  return;
1055
1047
  const r = n.messages[n.messages.length - 1];
@@ -1063,9 +1055,9 @@ function wn(e, n, i) {
1063
1055
  };
1064
1056
  n.messages.push(o), i == null || i([...n.messages], "user");
1065
1057
  }
1066
- function yn(e, n, i, r, o) {
1058
+ function vn(e, n, i, r, o) {
1067
1059
  if (e === q.Transcribe && n.content) {
1068
- wn(n, r, o);
1060
+ yn(n, r, o);
1069
1061
  return;
1070
1062
  }
1071
1063
  if (!(e === q.Partial || e === q.Answer))
@@ -1083,78 +1075,78 @@ function yn(e, n, i, r, o) {
1083
1075
  s = a;
1084
1076
  else
1085
1077
  return;
1086
- const { content: c, sequence: t } = n;
1087
- e === q.Partial ? i[t] = c : i.answer = c;
1088
- const d = pn(i);
1089
- (s.content !== d || e === q.Answer) && (s.content = d, o == null || o([...r.messages], e));
1078
+ const { content: d, sequence: t } = n;
1079
+ e === q.Partial ? i[t] = d : i.answer = d;
1080
+ const c = wn(i);
1081
+ (s.content !== c || e === q.Answer) && (s.content = c, o == null || o([...r.messages], e));
1090
1082
  }
1091
- function vn(e, n, i, r, o) {
1083
+ function Cn(e, n, i, r, o) {
1092
1084
  let a = {};
1093
1085
  const s = () => a = {};
1094
- let c = "answer";
1095
- const t = (d, p) => {
1086
+ let d = "answer";
1087
+ const t = (c, p) => {
1096
1088
  var g, l;
1097
- p === "user" && s(), c = p, (l = (g = i.callbacks).onNewMessage) == null || l.call(g, d, p);
1089
+ p === "user" && s(), d = p, (l = (g = i.callbacks).onNewMessage) == null || l.call(g, c, p);
1098
1090
  };
1099
1091
  return {
1100
1092
  clearQueue: s,
1101
- onMessage: (d, p) => {
1093
+ onMessage: (c, p) => {
1102
1094
  var g, l;
1103
1095
  if ("content" in p) {
1104
- const v = d === E.ChatAnswer ? q.Answer : d === E.ChatAudioTranscribed ? q.Transcribe : d;
1105
- yn(v, p, a, n, t), v === q.Answer && e.track("agent-message-received", {
1096
+ const v = c === E.ChatAnswer ? q.Answer : c === E.ChatAudioTranscribed ? q.Transcribe : c;
1097
+ vn(v, p, a, n, t), v === q.Answer && e.track("agent-message-received", {
1106
1098
  content: p.content,
1107
1099
  messages: n.messages.length,
1108
1100
  mode: n.chatMode
1109
1101
  });
1110
1102
  } else {
1111
- const v = E, b = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], x = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], L = Jt(p, r, { mode: n.chatMode });
1112
- if (d = d, d === v.StreamVideoCreated && (e.linkTrack("agent-video", L, v.StreamVideoCreated, ["start"]), p.sentiment)) {
1103
+ const v = E, D = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], B = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], L = Ot(p, r, { mode: n.chatMode });
1104
+ if (c = c, c === v.StreamVideoCreated && (e.linkTrack("agent-video", L, v.StreamVideoCreated, ["start"]), p.sentiment)) {
1113
1105
  const j = n.messages[n.messages.length - 1];
1114
1106
  if ((j == null ? void 0 : j.role) === "assistant") {
1115
- const D = { ...j, sentiment: p.sentiment };
1116
- n.messages[n.messages.length - 1] = D, t == null || t([...n.messages], c);
1107
+ const M = { ...j, sentiment: p.sentiment };
1108
+ n.messages[n.messages.length - 1] = M, t == null || t([...n.messages], d);
1117
1109
  }
1118
1110
  }
1119
- if (b.includes(d)) {
1120
- const j = d.split("/")[1];
1121
- x.includes(d) ? e.track("agent-video", { ...L, event: j }) : e.linkTrack("agent-video", { ...L, event: j }, d, ["done"]);
1111
+ if (D.includes(c)) {
1112
+ const j = c.split("/")[1];
1113
+ B.includes(c) ? e.track("agent-video", { ...L, event: j }) : e.linkTrack("agent-video", { ...L, event: j }, c, ["done"]);
1122
1114
  }
1123
- x.includes(d) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${d}`), { data: p })), p.event === v.StreamDone && o();
1115
+ B.includes(c) && ((l = (g = i.callbacks).onError) == null || l.call(g, new Error(`Stream failed with event ${c}`), { data: p })), p.event === v.StreamDone && o();
1124
1116
  }
1125
1117
  }
1126
1118
  };
1127
1119
  }
1128
- function Cn(e, n, i, r) {
1120
+ function Sn(e, n, i, r) {
1129
1121
  const o = je(e, `${n}/agents/${i}`, r);
1130
1122
  return {
1131
1123
  createStream(a, s) {
1132
1124
  return o.post("/streams", a, { signal: s });
1133
1125
  },
1134
- startConnection(a, s, c, t) {
1126
+ startConnection(a, s, d, t) {
1135
1127
  return o.post(
1136
1128
  `/streams/${a}/sdp`,
1137
1129
  {
1138
- session_id: c,
1130
+ session_id: d,
1139
1131
  answer: s
1140
1132
  },
1141
1133
  { signal: t }
1142
1134
  );
1143
1135
  },
1144
- addIceCandidate(a, s, c, t) {
1136
+ addIceCandidate(a, s, d, t) {
1145
1137
  return o.post(
1146
1138
  `/streams/${a}/ice`,
1147
1139
  {
1148
- session_id: c,
1140
+ session_id: d,
1149
1141
  ...s
1150
1142
  },
1151
1143
  { signal: t }
1152
1144
  );
1153
1145
  },
1154
- sendStreamRequest(a, s, c) {
1146
+ sendStreamRequest(a, s, d) {
1155
1147
  return o.post(`/streams/${a}`, {
1156
1148
  session_id: s,
1157
- ...c
1149
+ ...d
1158
1150
  });
1159
1151
  },
1160
1152
  close(a, s) {
@@ -1162,28 +1154,28 @@ function Cn(e, n, i, r) {
1162
1154
  }
1163
1155
  };
1164
1156
  }
1165
- const Sn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
1166
- function qe(e) {
1157
+ const Rn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
1158
+ function Qe(e) {
1167
1159
  switch (e) {
1168
1160
  case "connected":
1169
- return _.Connected;
1161
+ return b.Connected;
1170
1162
  case "checking":
1171
- return _.Connecting;
1163
+ return b.Connecting;
1172
1164
  case "failed":
1173
- return _.Fail;
1165
+ return b.Fail;
1174
1166
  case "new":
1175
- return _.New;
1167
+ return b.New;
1176
1168
  case "closed":
1177
- return _.Closed;
1169
+ return b.Closed;
1178
1170
  case "disconnected":
1179
- return _.Disconnected;
1171
+ return b.Disconnected;
1180
1172
  case "completed":
1181
- return _.Completed;
1173
+ return b.Completed;
1182
1174
  default:
1183
- return _.New;
1175
+ return b.New;
1184
1176
  }
1185
1177
  }
1186
- const Rn = (e) => (n) => {
1178
+ const Tn = (e) => (n) => {
1187
1179
  const [i, r = ""] = n.split(/:(.+)/);
1188
1180
  try {
1189
1181
  const o = JSON.parse(r);
@@ -1192,7 +1184,7 @@ const Rn = (e) => (n) => {
1192
1184
  return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: r, error: o }), { subject: i, data: r };
1193
1185
  }
1194
1186
  };
1195
- function Tn({
1187
+ function kn({
1196
1188
  statsSignal: e,
1197
1189
  dataChannelSignal: n,
1198
1190
  onVideoStateChange: i,
@@ -1201,7 +1193,7 @@ function Tn({
1201
1193
  }) {
1202
1194
  e === T.Start && n === T.Start ? (o("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && n === T.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, r));
1203
1195
  }
1204
- function kn({
1196
+ function En({
1205
1197
  statsSignal: e,
1206
1198
  dataChannelSignal: n,
1207
1199
  onVideoStateChange: i,
@@ -1211,7 +1203,7 @@ function kn({
1211
1203
  }) {
1212
1204
  e === T.Start ? (a("CALLBACK: onVideoStateChange(Start)"), i == null || i(T.Start)) : e === T.Stop && (a("CALLBACK: onVideoStateChange(Stop)"), i == null || i(T.Stop, o)), n === T.Start ? r == null || r(J.Talking) : n === T.Stop && (r == null || r(J.Idle));
1213
1205
  }
1214
- function Qe({
1206
+ function Xe({
1215
1207
  statsSignal: e,
1216
1208
  dataChannelSignal: n,
1217
1209
  onVideoStateChange: i,
@@ -1220,7 +1212,7 @@ function Qe({
1220
1212
  report: a,
1221
1213
  log: s
1222
1214
  }) {
1223
- o === ie.Legacy ? Tn({ statsSignal: e, dataChannelSignal: n, onVideoStateChange: i, report: a, log: s }) : o === ie.Fluent && kn({
1215
+ o === re.Legacy ? kn({ statsSignal: e, dataChannelSignal: n, onVideoStateChange: i, report: a, log: s }) : o === re.Fluent && En({
1224
1216
  statsSignal: e,
1225
1217
  dataChannelSignal: n,
1226
1218
  onVideoStateChange: i,
@@ -1229,11 +1221,11 @@ function Qe({
1229
1221
  log: s
1230
1222
  });
1231
1223
  }
1232
- async function En(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe, analytics: s }, c) {
1233
- var oe;
1234
- const t = at(i, "WebRTCStreamingManager"), d = Rn(t);
1224
+ async function In(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = we, analytics: s }, d) {
1225
+ var ae;
1226
+ const t = ot(i, "WebRTCStreamingManager"), c = Tn(t);
1235
1227
  let p = !1, g = !1, l = T.Stop, v = T.Stop;
1236
- const { startConnection: b, sendStreamRequest: x, close: L, createStream: j, addIceCandidate: D } = Cn(
1228
+ const { startConnection: D, sendStreamRequest: B, close: L, createStream: j, addIceCandidate: M } = Sn(
1237
1229
  o,
1238
1230
  a,
1239
1231
  e,
@@ -1244,27 +1236,27 @@ async function En(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe,
1244
1236
  ice_servers: W,
1245
1237
  session_id: F,
1246
1238
  fluent: Y,
1247
- interrupt_enabled: ae,
1239
+ interrupt_enabled: ie,
1248
1240
  triggers_enabled: se
1249
- } = await j(n, c);
1250
- (oe = r.onStreamCreated) == null || oe.call(r, { stream_id: k, session_id: F, agent_id: e });
1251
- const f = new Sn({ iceServers: W }), S = f.createDataChannel("JanusDataChannel");
1241
+ } = await j(n, d);
1242
+ (ae = r.onStreamCreated) == null || ae.call(r, { stream_id: k, session_id: F, agent_id: e });
1243
+ const m = new Rn({ iceServers: W }), S = m.createDataChannel("JanusDataChannel");
1252
1244
  if (!F)
1253
1245
  throw new Error("Could not create session_id");
1254
- const R = Y ? ie.Fluent : ie.Legacy;
1246
+ const R = Y ? re.Fluent : re.Legacy;
1255
1247
  s.enrich({
1256
1248
  "stream-type": R
1257
1249
  });
1258
- const V = n.stream_warmup && !Y, $ = () => p, M = () => {
1250
+ const V = n.stream_warmup && !Y, $ = () => p, A = () => {
1259
1251
  var y;
1260
- p = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (y = r.onConnectionStateChange) == null || y.call(r, _.Connected));
1261
- }, U = st(
1262
- () => f.getStats(),
1252
+ p = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (y = r.onConnectionStateChange) == null || y.call(r, b.Connected));
1253
+ }, U = ct(
1254
+ () => m.getStats(),
1263
1255
  $,
1264
- M,
1265
- (y, h) => Qe({
1256
+ A,
1257
+ (y, h) => Xe({
1266
1258
  statsSignal: v = y,
1267
- dataChannelSignal: R === ie.Legacy ? l : void 0,
1259
+ dataChannelSignal: R === re.Legacy ? l : void 0,
1268
1260
  onVideoStateChange: r.onVideoStateChange,
1269
1261
  onAgentActivityStateChange: r.onAgentActivityStateChange,
1270
1262
  report: h,
@@ -1276,11 +1268,11 @@ async function En(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe,
1276
1268
  return (h = r.onConnectivityStateChange) == null ? void 0 : h.call(r, y);
1277
1269
  }
1278
1270
  );
1279
- U.start(), f.onicecandidate = (y) => {
1271
+ U.start(), m.onicecandidate = (y) => {
1280
1272
  var h;
1281
1273
  t("peerConnection.onicecandidate", y);
1282
1274
  try {
1283
- y.candidate && y.candidate.sdpMid && y.candidate.sdpMLineIndex !== null ? D(
1275
+ y.candidate && y.candidate.sdpMid && y.candidate.sdpMLineIndex !== null ? M(
1284
1276
  k,
1285
1277
  {
1286
1278
  candidate: y.candidate.candidate,
@@ -1288,13 +1280,13 @@ async function En(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe,
1288
1280
  sdpMLineIndex: y.candidate.sdpMLineIndex
1289
1281
  },
1290
1282
  F,
1291
- c
1292
- ) : D(k, { candidate: null }, F, c);
1283
+ d
1284
+ ) : M(k, { candidate: null }, F, d);
1293
1285
  } catch (I) {
1294
1286
  (h = r.onError) == null || h.call(r, I, { streamId: k });
1295
1287
  }
1296
1288
  }, S.onopen = () => {
1297
- g = !0, (!V || p) && M();
1289
+ g = !0, (!V || p) && A();
1298
1290
  };
1299
1291
  const Q = (y) => {
1300
1292
  var h;
@@ -1305,8 +1297,8 @@ async function En(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe,
1305
1297
  const I = h.metadata;
1306
1298
  Q(I.videoId);
1307
1299
  }
1308
- y === E.StreamDone && Q(null), l = y === E.StreamStarted ? T.Start : T.Stop, Qe({
1309
- statsSignal: R === ie.Legacy ? v : void 0,
1300
+ y === E.StreamDone && Q(null), l = y === E.StreamStarted ? T.Start : T.Stop, Xe({
1301
+ statsSignal: R === re.Legacy ? v : void 0,
1310
1302
  dataChannelSignal: l,
1311
1303
  onVideoStateChange: r.onVideoStateChange,
1312
1304
  onAgentActivityStateChange: r.onAgentActivityStateChange,
@@ -1314,7 +1306,7 @@ async function En(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe,
1314
1306
  log: t
1315
1307
  });
1316
1308
  }
1317
- function B(y, h) {
1309
+ function x(y, h) {
1318
1310
  var Z;
1319
1311
  const I = typeof h == "string" ? h : h == null ? void 0 : h.metadata;
1320
1312
  I && s.enrich({ streamMetadata: I }), (Z = r.onStreamReady) == null || Z.call(r);
@@ -1322,29 +1314,29 @@ async function En(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe,
1322
1314
  const K = {
1323
1315
  [E.StreamStarted]: X,
1324
1316
  [E.StreamDone]: X,
1325
- [E.StreamReady]: B
1317
+ [E.StreamReady]: x
1326
1318
  };
1327
1319
  S.onmessage = (y) => {
1328
1320
  var Z;
1329
- const { subject: h, data: I } = d(y.data);
1321
+ const { subject: h, data: I } = c(y.data);
1330
1322
  (Z = K[h]) == null || Z.call(K, h, I);
1331
- }, f.oniceconnectionstatechange = () => {
1323
+ }, m.oniceconnectionstatechange = () => {
1332
1324
  var h;
1333
- t("peerConnection.oniceconnectionstatechange => " + f.iceConnectionState);
1334
- const y = qe(f.iceConnectionState);
1335
- y !== _.Connected && ((h = r.onConnectionStateChange) == null || h.call(r, y));
1336
- }, f.ontrack = (y) => {
1325
+ t("peerConnection.oniceconnectionstatechange => " + m.iceConnectionState);
1326
+ const y = Qe(m.iceConnectionState);
1327
+ y !== b.Connected && ((h = r.onConnectionStateChange) == null || h.call(r, y));
1328
+ }, m.ontrack = (y) => {
1337
1329
  var h;
1338
1330
  t("peerConnection.ontrack", y), t("CALLBACK: onSrcObjectReady"), (h = r.onSrcObjectReady) == null || h.call(r, y.streams[0]);
1339
- }, await f.setRemoteDescription(O), t("set remote description OK");
1340
- const G = await f.createAnswer();
1341
- return t("create answer OK"), await f.setLocalDescription(G), t("set local description OK"), await b(k, G, F, c), t("start connection OK"), {
1331
+ }, await m.setRemoteDescription(O), t("set remote description OK");
1332
+ const G = await m.createAnswer();
1333
+ return t("create answer OK"), await m.setLocalDescription(G), t("set local description OK"), await D(k, G, F, d), t("start connection OK"), {
1342
1334
  /**
1343
1335
  * Method to send request to server to get clip or talk depend on you payload
1344
1336
  * @param payload
1345
1337
  */
1346
1338
  speak(y) {
1347
- return x(k, F, y);
1339
+ return B(k, F, y);
1348
1340
  },
1349
1341
  /**
1350
1342
  * Method to close RTC connection
@@ -1352,16 +1344,16 @@ async function En(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe,
1352
1344
  async disconnect() {
1353
1345
  var y;
1354
1346
  if (k) {
1355
- const h = qe(f.iceConnectionState);
1356
- if (f) {
1357
- if (h === _.New) {
1347
+ const h = Qe(m.iceConnectionState);
1348
+ if (m) {
1349
+ if (h === b.New) {
1358
1350
  U.stop();
1359
1351
  return;
1360
1352
  }
1361
- f.close(), f.oniceconnectionstatechange = null, f.onnegotiationneeded = null, f.onicecandidate = null, f.ontrack = null;
1353
+ m.close(), m.oniceconnectionstatechange = null, m.onnegotiationneeded = null, m.onicecandidate = null, m.ontrack = null;
1362
1354
  }
1363
1355
  try {
1364
- h === _.Connected && await L(k, F).catch((I) => {
1356
+ h === b.Connected && await L(k, F).catch((I) => {
1365
1357
  });
1366
1358
  } catch (I) {
1367
1359
  t("Error on close stream connection", I);
@@ -1395,25 +1387,25 @@ async function En(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = pe,
1395
1387
  */
1396
1388
  streamId: k,
1397
1389
  streamType: R,
1398
- interruptAvailable: ae ?? !1,
1390
+ interruptAvailable: ie ?? !1,
1399
1391
  isInterruptible: !0,
1400
1392
  triggersAvailable: se ?? !1
1401
1393
  };
1402
1394
  }
1403
1395
  var be = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(be || {});
1404
- async function In(e, n, i, r) {
1396
+ async function Dn(e, n, i, r) {
1405
1397
  const o = e.id;
1406
1398
  switch (n.version) {
1407
1399
  case "v1": {
1408
1400
  const { version: a, ...s } = n;
1409
- return En(o, s, i, r);
1401
+ return In(o, s, i, r);
1410
1402
  }
1411
1403
  case "v2": {
1412
1404
  const { version: a, ...s } = n;
1413
1405
  switch (s.transport.provider) {
1414
1406
  case Pe.Livekit:
1415
- const { createLiveKitStreamingManager: c } = await Promise.resolve().then(() => dn);
1416
- return c(o, s, i);
1407
+ const { createLiveKitStreamingManager: d } = await Promise.resolve().then(() => un);
1408
+ return d(o, s, i);
1417
1409
  default:
1418
1410
  throw new Error(`Unsupported transport provider: ${s.transport.provider}`);
1419
1411
  }
@@ -1422,15 +1414,15 @@ async function In(e, n, i, r) {
1422
1414
  throw new Error(`Invalid stream version: ${n.version}`);
1423
1415
  }
1424
1416
  }
1425
- const Dn = "cht";
1426
- function Mn() {
1417
+ const Mn = "cht";
1418
+ function An() {
1427
1419
  return {
1428
1420
  transport: {
1429
1421
  provider: Pe.Livekit
1430
1422
  }
1431
1423
  };
1432
1424
  }
1433
- function An(e) {
1425
+ function _n(e) {
1434
1426
  var o, a;
1435
1427
  const { streamOptions: n } = e ?? {}, i = ((o = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : o.plan) !== void 0 ? {
1436
1428
  plan: (a = e.mixpanelAdditionalProperties) == null ? void 0 : a.plan
@@ -1443,16 +1435,16 @@ function An(e) {
1443
1435
  fluent: n == null ? void 0 : n.fluent
1444
1436
  }, ...i && { end_user_data: i } };
1445
1437
  }
1446
- function _n(e, n) {
1447
- return Le(e.presenter.type) ? { version: be.V2, ...Mn() } : { version: be.V1, ...An(n) };
1438
+ function bn(e, n) {
1439
+ return Le(e.presenter.type) ? { version: be.V2, ...An() } : { version: be.V1, ..._n(n) };
1448
1440
  }
1449
- function bn(e, n, i) {
1441
+ function Pn(e, n, i) {
1450
1442
  i.track("agent-connection-state-change", { state: e, ...n && { reason: n } });
1451
1443
  }
1452
- function Pn(e, n, i, r, o) {
1453
- o === ie.Fluent ? Ln(e, n, i, r, o) : jn(e, n, i, r, o);
1454
- }
1455
1444
  function Ln(e, n, i, r, o) {
1445
+ o === re.Fluent ? jn(e, n, i, r, o) : $n(e, n, i, r, o);
1446
+ }
1447
+ function jn(e, n, i, r, o) {
1456
1448
  e === T.Start ? r.track("stream-session", { event: "start", "stream-type": o }) : e === T.Stop && r.track("stream-session", {
1457
1449
  event: "stop",
1458
1450
  is_greenscreen: n.presenter.type === "clip" && n.presenter.is_greenscreen,
@@ -1461,8 +1453,8 @@ function Ln(e, n, i, r, o) {
1461
1453
  ...i
1462
1454
  });
1463
1455
  }
1464
- function Xe(e, n, i, r, o) {
1465
- e === T.Start ? i.linkTrack("agent-video", { event: "start", latency: o, "stream-type": r }, "start", [
1456
+ function Ye(e, n, i, r, o) {
1457
+ e === T.Start ? i.linkTrack("agent-video", { event: "start", ...o, "stream-type": r }, "start", [
1466
1458
  E.StreamVideoCreated
1467
1459
  ]) : e === T.Stop && i.linkTrack(
1468
1460
  "agent-video",
@@ -1476,10 +1468,10 @@ function Xe(e, n, i, r, o) {
1476
1468
  [E.StreamVideoDone]
1477
1469
  );
1478
1470
  }
1479
- function jn(e, n, i, r, o) {
1471
+ function $n(e, n, i, r, o) {
1480
1472
  e === T.Start ? r.linkTrack(
1481
1473
  "agent-video",
1482
- { event: "start", latency: re.get(!0), "stream-type": o },
1474
+ { event: "start", latency: ne.get(!0), "stream-type": o },
1483
1475
  "start",
1484
1476
  [E.StreamVideoCreated]
1485
1477
  ) : e === T.Stop && r.linkTrack(
@@ -1495,17 +1487,17 @@ function jn(e, n, i, r, o) {
1495
1487
  [E.StreamVideoDone]
1496
1488
  );
1497
1489
  }
1498
- function Ye(e, n, i, r) {
1499
- return re.reset(), Je.update(), new Promise(async (o, a) => {
1490
+ function Ge(e, n, i, r) {
1491
+ return ne.reset(), We.update(), new Promise(async (o, a) => {
1500
1492
  try {
1501
- let s, c = !1;
1502
- const t = _n(e, n);
1493
+ let s, d = !1;
1494
+ const t = bn(e, n);
1503
1495
  i.enrich({
1504
1496
  "stream-version": t.version.toString()
1505
1497
  });
1506
- let d = null;
1498
+ let c = null;
1507
1499
  const p = e.presenter.type === "expressive";
1508
- s = await In(
1500
+ s = await Dn(
1509
1501
  e,
1510
1502
  t,
1511
1503
  {
@@ -1514,12 +1506,12 @@ function Ye(e, n, i, r) {
1514
1506
  callbacks: {
1515
1507
  ...n.callbacks,
1516
1508
  onConnectionStateChange: (g, l) => {
1517
- var v, b;
1518
- (b = (v = n.callbacks).onConnectionStateChange) == null || b.call(v, g), bn(g, l, i), g === _.Connected && (s ? o(s) : c = !0);
1509
+ var v, D;
1510
+ (D = (v = n.callbacks).onConnectionStateChange) == null || D.call(v, g), Pn(g, l, i), g === b.Connected && (s ? o(s) : d = !0);
1519
1511
  },
1520
1512
  onVideoStateChange: (g, l) => {
1521
- var v, b;
1522
- (b = (v = n.callbacks).onVideoStateChange) == null || b.call(v, g), Pn(
1513
+ var v, D;
1514
+ (D = (v = n.callbacks).onVideoStateChange) == null || D.call(v, g), Ln(
1523
1515
  g,
1524
1516
  e,
1525
1517
  l,
@@ -1529,15 +1521,15 @@ function Ye(e, n, i, r) {
1529
1521
  },
1530
1522
  onAgentActivityStateChange: (g) => {
1531
1523
  var l, v;
1532
- (v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === J.Talking ? (Ae.update(), d = (b) => {
1533
- Xe(
1524
+ (v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === J.Talking ? (Ae.update(), c = (D) => {
1525
+ Ye(
1534
1526
  T.Start,
1535
1527
  e,
1536
1528
  i,
1537
1529
  s.streamType,
1538
- b
1539
- ), d = null;
1540
- }, p || d(re.get(!0))) : (Ae.reset(), d = null, Xe(
1530
+ D
1531
+ ), c = null;
1532
+ }, p || c({ latency: ne.get(!0) })) : (Ae.reset(), c = null, Ye(
1541
1533
  T.Stop,
1542
1534
  e,
1543
1535
  i,
@@ -1545,30 +1537,30 @@ function Ye(e, n, i, r) {
1545
1537
  ));
1546
1538
  },
1547
1539
  onFirstAudioDetected: (g) => {
1548
- d == null || d(g);
1540
+ c == null || c(g);
1549
1541
  },
1550
1542
  onStreamReady: () => {
1551
- const g = Je.get(!0);
1543
+ const g = We.get(!0);
1552
1544
  i.track("agent-chat", { event: "ready", latency: g });
1553
1545
  }
1554
1546
  }
1555
1547
  },
1556
1548
  r
1557
- ), c && o(s);
1549
+ ), d && o(s);
1558
1550
  } catch (s) {
1559
1551
  a(s);
1560
1552
  }
1561
1553
  });
1562
1554
  }
1563
- async function $n(e, n, i, r, o) {
1555
+ async function xn(e, n, i, r, o) {
1564
1556
  var p, g, l, v;
1565
1557
  const a = async () => {
1566
1558
  if (Le(e.presenter.type)) {
1567
- const b = await Ye(e, n, r), x = `${Dn}_${b.sessionId}`, L = (/* @__PURE__ */ new Date()).toISOString();
1559
+ const D = await Ge(e, n, r), B = `${Mn}_${D.sessionId}`, L = (/* @__PURE__ */ new Date()).toISOString();
1568
1560
  return { chatResult: {
1569
1561
  chatMode: N.Functional,
1570
1562
  chat: {
1571
- id: x,
1563
+ id: B,
1572
1564
  agent_id: e.id,
1573
1565
  owner_id: e.owner_id ?? "",
1574
1566
  created: L,
@@ -1578,153 +1570,153 @@ async function $n(e, n, i, r, o) {
1578
1570
  chat_mode: N.Functional,
1579
1571
  messages: []
1580
1572
  }
1581
- }, streamingManager: b };
1573
+ }, streamingManager: D };
1582
1574
  } else {
1583
- const b = new AbortController(), x = b.signal;
1575
+ const D = new AbortController(), B = D.signal;
1584
1576
  let L;
1585
1577
  try {
1586
- const j = it(
1578
+ const j = at(
1587
1579
  e,
1588
1580
  i,
1589
1581
  r,
1590
1582
  n.mode,
1591
1583
  n.persistentChat,
1592
1584
  o
1593
- ), D = Ye(e, n, r, x).then((W) => (L = W, W)), [k, O] = await Promise.all([j, D]);
1585
+ ), M = Ge(e, n, r, B).then((W) => (L = W, W)), [k, O] = await Promise.all([j, M]);
1594
1586
  return { chatResult: k, streamingManager: O };
1595
1587
  } catch (j) {
1596
- throw b.abort(), L && await L.disconnect().catch(() => {
1588
+ throw D.abort(), L && await L.disconnect().catch(() => {
1597
1589
  }), j;
1598
1590
  }
1599
1591
  }
1600
- }, { chatResult: s, streamingManager: c } = await a(), { chat: t, chatMode: d } = s;
1601
- return d && n.mode !== void 0 && d !== n.mode && (n.mode = d, (g = (p = n.callbacks).onModeChange) == null || g.call(p, d), d !== N.Functional) ? ((v = (l = n.callbacks).onError) == null || v.call(l, new yt(d)), c == null || c.disconnect(), { chat: t }) : { chat: t, streamingManager: c };
1592
+ }, { chatResult: s, streamingManager: d } = await a(), { chat: t, chatMode: c } = s;
1593
+ return c && n.mode !== void 0 && c !== n.mode && (n.mode = c, (g = (p = n.callbacks).onModeChange) == null || g.call(p, c), c !== N.Functional) ? ((v = (l = n.callbacks).onError) == null || v.call(l, new vt(c)), d == null || d.disconnect(), { chat: t }) : { chat: t, streamingManager: d };
1602
1594
  }
1603
- async function Fn(e, n) {
1604
- var F, Y, ae, se;
1595
+ async function zn(e, n) {
1596
+ var F, Y, ie, se;
1605
1597
  let i = !0, r = null;
1606
- const o = n.mixpanelKey || Pt, a = n.wsURL || bt, s = n.baseURL || pe, c = n.mode || N.Functional, t = {
1598
+ const o = n.mixpanelKey || Lt, a = n.wsURL || Pt, s = n.baseURL || we, d = n.mode || N.Functional, t = {
1607
1599
  messages: [],
1608
- chatMode: c
1609
- }, d = Wt({
1600
+ chatMode: d
1601
+ }, c = Ht({
1610
1602
  token: o,
1611
1603
  agentId: e,
1612
1604
  isEnabled: n.enableAnalitics,
1613
1605
  externalId: n.externalId,
1614
1606
  mixpanelAdditionalProperties: n.mixpanelAdditionalProperties
1615
1607
  }), p = Date.now();
1616
- Ue(() => {
1617
- d.track("agent-sdk", { event: "init" }, p);
1608
+ Oe(() => {
1609
+ c.track("agent-sdk", { event: "init" }, p);
1618
1610
  });
1619
- const g = Kt(n.auth, s, n.callbacks.onError, n.externalId), l = await g.getById(e);
1611
+ const g = Nt(n.auth, s, n.callbacks.onError, n.externalId), l = await g.getById(e);
1620
1612
  n.debug = n.debug || ((F = l == null ? void 0 : l.advanced_settings) == null ? void 0 : F.ui_debug_mode);
1621
1613
  const v = Le(l.presenter.type);
1622
- d.enrich(Vt(l));
1623
- const { onMessage: b, clearQueue: x } = vn(
1624
- d,
1614
+ c.enrich(Ut(l));
1615
+ const { onMessage: D, clearQueue: B } = Cn(
1616
+ c,
1625
1617
  t,
1626
1618
  n,
1627
1619
  l,
1628
1620
  () => {
1629
- var f;
1630
- return (f = t.socketManager) == null ? void 0 : f.disconnect();
1621
+ var m;
1622
+ return (m = t.socketManager) == null ? void 0 : m.disconnect();
1631
1623
  }
1632
1624
  );
1633
- t.messages = qt(n.initialMessages), (ae = (Y = n.callbacks).onNewMessage) == null || ae.call(Y, [...t.messages], "answer");
1634
- const L = (f) => {
1635
- r = f;
1636
- }, j = ({ type: f }) => {
1637
- var R, V, $, M;
1625
+ t.messages = Qt(n.initialMessages), (ie = (Y = n.callbacks).onNewMessage) == null || ie.call(Y, [...t.messages], "answer");
1626
+ const L = (m) => {
1627
+ r = m;
1628
+ }, j = ({ type: m }) => {
1629
+ var R, V, $, A;
1638
1630
  if (!((R = t.streamingManager) != null && R.isInterruptible)) return;
1639
1631
  const S = t.messages[t.messages.length - 1];
1640
- d.track("agent-video-interrupt", {
1641
- type: f || "click",
1632
+ c.track("agent-video-interrupt", {
1633
+ type: m || "click",
1642
1634
  video_duration_to_interrupt: Ae.get(!0),
1643
- message_duration_to_interrupt: re.get(!0)
1644
- }), S.interrupted = !0, ($ = (V = n.callbacks).onNewMessage) == null || $.call(V, [...t.messages], "answer"), v ? fn(t.streamingManager) : (un(t.streamingManager, (M = t.streamingManager) == null ? void 0 : M.streamType, r), ln(t.streamingManager, r));
1645
- }, D = Date.now();
1646
- Ue(() => {
1647
- d.track("agent-sdk", { event: "loaded", ...Nt(l) }, D);
1635
+ message_duration_to_interrupt: ne.get(!0)
1636
+ }), S.interrupted = !0, ($ = (V = n.callbacks).onNewMessage) == null || $.call(V, [...t.messages], "answer"), v ? fn(t.streamingManager) : (ln(t.streamingManager, (A = t.streamingManager) == null ? void 0 : A.streamType, r), mn(t.streamingManager, r));
1637
+ }, M = Date.now();
1638
+ Oe(() => {
1639
+ c.track("agent-sdk", { event: "loaded", ...Vt(l) }, M);
1648
1640
  });
1649
- async function k(f) {
1650
- var U, Q, X, B, K, G, oe;
1651
- (Q = (U = n.callbacks).onConnectionStateChange) == null || Q.call(U, _.Connecting), re.reset(), f && !i && (delete t.chat, (B = (X = n.callbacks).onNewMessage) == null || B.call(X, [...t.messages], "answer"));
1652
- const S = c === N.DirectPlayback || v ? Promise.resolve(void 0) : hn(
1641
+ async function k(m) {
1642
+ var U, Q, X, x, K, G, ae;
1643
+ (Q = (U = n.callbacks).onConnectionStateChange) == null || Q.call(U, b.Connecting), ne.reset(), m && !i && (delete t.chat, (x = (X = n.callbacks).onNewMessage) == null || x.call(X, [...t.messages], "answer"));
1644
+ const S = d === N.DirectPlayback || v ? Promise.resolve(void 0) : pn(
1653
1645
  n.auth,
1654
1646
  a,
1655
- { onMessage: b, onError: n.callbacks.onError },
1647
+ { onMessage: D, onError: n.callbacks.onError },
1656
1648
  n.externalId
1657
1649
  ), R = De(
1658
- () => $n(
1650
+ () => xn(
1659
1651
  l,
1660
1652
  {
1661
1653
  ...n,
1662
- mode: c,
1654
+ mode: d,
1663
1655
  callbacks: {
1664
1656
  ...n.callbacks,
1665
1657
  onVideoIdChange: L,
1666
- onMessage: b,
1658
+ onMessage: D,
1667
1659
  onInterruptDetected: j
1668
1660
  }
1669
1661
  },
1670
1662
  g,
1671
- d,
1663
+ c,
1672
1664
  t.chat
1673
1665
  ),
1674
1666
  {
1675
1667
  limit: 3,
1676
- timeout: At,
1668
+ timeout: _t,
1677
1669
  timeoutErrorMessage: "Timeout initializing the stream",
1678
1670
  shouldRetryFn: (y) => (y == null ? void 0 : y.message) !== "Could not connect" && y.status !== 429 && (y == null ? void 0 : y.message) !== "InsufficientCreditsError",
1679
1671
  delayMs: 1e3
1680
1672
  }
1681
1673
  ).catch((y) => {
1682
1674
  var h, I;
1683
- throw W(N.Maintenance), (I = (h = n.callbacks).onConnectionStateChange) == null || I.call(h, _.Fail), y;
1684
- }), [V, { streamingManager: $, chat: M }] = await Promise.all([S, R]);
1685
- M && M.id !== ((K = t.chat) == null ? void 0 : K.id) && ((oe = (G = n.callbacks).onNewChat) == null || oe.call(G, M.id)), t.streamingManager = $, t.socketManager = V, t.chat = M, i = !1, d.enrich({
1686
- chatId: M == null ? void 0 : M.id,
1675
+ throw W(N.Maintenance), (I = (h = n.callbacks).onConnectionStateChange) == null || I.call(h, b.Fail), y;
1676
+ }), [V, { streamingManager: $, chat: A }] = await Promise.all([S, R]);
1677
+ A && A.id !== ((K = t.chat) == null ? void 0 : K.id) && ((ae = (G = n.callbacks).onNewChat) == null || ae.call(G, A.id)), t.streamingManager = $, t.socketManager = V, t.chat = A, i = !1, c.enrich({
1678
+ chatId: A == null ? void 0 : A.id,
1687
1679
  streamId: $ == null ? void 0 : $.streamId,
1688
1680
  mode: t.chatMode
1689
- }), W((M == null ? void 0 : M.chat_mode) ?? c);
1681
+ }), W((A == null ? void 0 : A.chat_mode) ?? d);
1690
1682
  }
1691
1683
  async function O() {
1692
- var f, S, R, V;
1693
- (f = t.socketManager) == null || f.disconnect(), await ((S = t.streamingManager) == null ? void 0 : S.disconnect()), delete t.streamingManager, delete t.socketManager, (V = (R = n.callbacks).onConnectionStateChange) == null || V.call(R, _.Disconnected);
1684
+ var m, S, R, V;
1685
+ (m = t.socketManager) == null || m.disconnect(), await ((S = t.streamingManager) == null ? void 0 : S.disconnect()), delete t.streamingManager, delete t.socketManager, (V = (R = n.callbacks).onConnectionStateChange) == null || V.call(R, b.Disconnected);
1694
1686
  }
1695
- async function W(f) {
1687
+ async function W(m) {
1696
1688
  var S, R;
1697
- f !== t.chatMode && (d.track("agent-mode-change", { mode: f }), t.chatMode = f, t.chatMode !== N.Functional && await O(), (R = (S = n.callbacks).onModeChange) == null || R.call(S, f));
1689
+ m !== t.chatMode && (c.track("agent-mode-change", { mode: m }), t.chatMode = m, t.chatMode !== N.Functional && await O(), (R = (S = n.callbacks).onModeChange) == null || R.call(S, m));
1698
1690
  }
1699
1691
  return {
1700
1692
  agent: l,
1701
1693
  getStreamType: () => {
1702
- var f;
1703
- return (f = t.streamingManager) == null ? void 0 : f.streamType;
1694
+ var m;
1695
+ return (m = t.streamingManager) == null ? void 0 : m.streamType;
1704
1696
  },
1705
1697
  getIsInterruptAvailable: () => {
1706
- var f;
1707
- return ((f = t.streamingManager) == null ? void 0 : f.interruptAvailable) ?? !1;
1698
+ var m;
1699
+ return ((m = t.streamingManager) == null ? void 0 : m.interruptAvailable) ?? !1;
1708
1700
  },
1709
1701
  getIsTriggersAvailable: () => {
1710
- var f;
1711
- return ((f = t.streamingManager) == null ? void 0 : f.triggersAvailable) ?? !1;
1702
+ var m;
1703
+ return ((m = t.streamingManager) == null ? void 0 : m.triggersAvailable) ?? !1;
1712
1704
  },
1713
1705
  starterMessages: ((se = l.knowledge) == null ? void 0 : se.starter_message) || [],
1714
1706
  getSTTToken: () => g.getSTTToken(l.id),
1715
1707
  changeMode: W,
1716
- enrichAnalytics: d.enrich,
1708
+ enrichAnalytics: c.enrich,
1717
1709
  async connect() {
1718
- await k(!0), d.track("agent-chat", {
1710
+ await k(!0), c.track("agent-chat", {
1719
1711
  event: "connect",
1720
1712
  mode: t.chatMode
1721
1713
  });
1722
1714
  },
1723
1715
  async reconnect() {
1724
- const f = t.streamingManager;
1725
- if (v && (f != null && f.reconnect)) {
1716
+ const m = t.streamingManager;
1717
+ if (v && (m != null && m.reconnect)) {
1726
1718
  try {
1727
- await f.reconnect(), d.track("agent-chat", {
1719
+ await m.reconnect(), c.track("agent-chat", {
1728
1720
  event: "reconnect",
1729
1721
  mode: t.chatMode
1730
1722
  });
@@ -1733,78 +1725,78 @@ async function Fn(e, n) {
1733
1725
  }
1734
1726
  return;
1735
1727
  }
1736
- await O(), await k(!1), d.track("agent-chat", {
1728
+ await O(), await k(!1), c.track("agent-chat", {
1737
1729
  event: "reconnect",
1738
1730
  mode: t.chatMode
1739
1731
  });
1740
1732
  },
1741
1733
  async disconnect() {
1742
- await O(), d.track("agent-chat", {
1734
+ await O(), c.track("agent-chat", {
1743
1735
  event: "disconnect",
1744
1736
  mode: t.chatMode
1745
1737
  });
1746
1738
  },
1747
- async publishMicrophoneStream(f) {
1739
+ async publishMicrophoneStream(m) {
1748
1740
  var S;
1749
1741
  if (!((S = t.streamingManager) != null && S.publishMicrophoneStream))
1750
1742
  throw new Error("publishMicrophoneStream is not available for this streaming manager");
1751
- return t.streamingManager.publishMicrophoneStream(f);
1743
+ return t.streamingManager.publishMicrophoneStream(m);
1752
1744
  },
1753
1745
  async unpublishMicrophoneStream() {
1754
- var f;
1755
- if (!((f = t.streamingManager) != null && f.unpublishMicrophoneStream))
1746
+ var m;
1747
+ if (!((m = t.streamingManager) != null && m.unpublishMicrophoneStream))
1756
1748
  throw new Error("unpublishMicrophoneStream is not available for this streaming manager");
1757
1749
  return t.streamingManager.unpublishMicrophoneStream();
1758
1750
  },
1759
- async publishCameraStream(f) {
1751
+ async publishCameraStream(m) {
1760
1752
  var S;
1761
1753
  if (!((S = t.streamingManager) != null && S.publishCameraStream))
1762
1754
  throw new Error("publishCameraStream is not available for this streaming manager");
1763
- return t.streamingManager.publishCameraStream(f);
1755
+ return t.streamingManager.publishCameraStream(m);
1764
1756
  },
1765
1757
  async unpublishCameraStream() {
1766
- var f;
1767
- if (!((f = t.streamingManager) != null && f.unpublishCameraStream))
1758
+ var m;
1759
+ if (!((m = t.streamingManager) != null && m.unpublishCameraStream))
1768
1760
  throw new Error("unpublishCameraStream is not available for this streaming manager");
1769
1761
  return t.streamingManager.unpublishCameraStream();
1770
1762
  },
1771
- async chat(f) {
1772
- var $, M, U, Q, X;
1763
+ async chat(m) {
1764
+ var $, A, U, Q, X;
1773
1765
  const S = () => {
1774
- if (tt(c))
1775
- throw new de(`${c} is enabled, chat is disabled`);
1776
- if (f.length >= 800)
1777
- throw new de("Message cannot be more than 800 characters");
1778
- if (f.length === 0)
1779
- throw new de("Message cannot be empty");
1766
+ if (nt(d))
1767
+ throw new ue(`${d} is enabled, chat is disabled`);
1768
+ if (m.length >= 800)
1769
+ throw new ue("Message cannot be more than 800 characters");
1770
+ if (m.length === 0)
1771
+ throw new ue("Message cannot be empty");
1780
1772
  if (t.chatMode === N.Maintenance)
1781
- throw new de("Chat is in maintenance mode");
1773
+ throw new ue("Chat is in maintenance mode");
1782
1774
  if (![N.TextOnly, N.Playground].includes(t.chatMode)) {
1783
1775
  if (!t.streamingManager)
1784
- throw new de("Streaming manager is not initialized");
1776
+ throw new ue("Streaming manager is not initialized");
1785
1777
  if (!t.chat)
1786
- throw new de("Chat is not initialized");
1778
+ throw new ue("Chat is not initialized");
1787
1779
  }
1788
1780
  }, R = async () => {
1789
- var B, K;
1781
+ var x, K;
1790
1782
  if (!t.chat) {
1791
- const G = await it(
1783
+ const G = await at(
1792
1784
  l,
1793
1785
  g,
1794
- d,
1786
+ c,
1795
1787
  t.chatMode,
1796
1788
  n.persistentChat
1797
1789
  );
1798
1790
  if (!G.chat)
1799
- throw new wt(t.chatMode, !!n.persistentChat);
1800
- t.chat = G.chat, (K = (B = n.callbacks).onNewChat) == null || K.call(B, t.chat.id);
1791
+ throw new yt(t.chatMode, !!n.persistentChat);
1792
+ t.chat = G.chat, (K = (x = n.callbacks).onNewChat) == null || K.call(x, t.chat.id);
1801
1793
  }
1802
1794
  return t.chat.id;
1803
- }, V = async (B, K) => {
1795
+ }, V = async (x, K) => {
1804
1796
  const G = t.chatMode === N.Playground;
1805
1797
  return De(v && !G ? async () => {
1806
1798
  var h, I;
1807
- return await ((I = (h = t.streamingManager) == null ? void 0 : h.sendTextMessage) == null ? void 0 : I.call(h, f)), Promise.resolve({});
1799
+ return await ((I = (h = t.streamingManager) == null ? void 0 : h.sendTextMessage) == null ? void 0 : I.call(h, m)), Promise.resolve({});
1808
1800
  } : async () => {
1809
1801
  var h, I;
1810
1802
  return g.chat(
@@ -1814,19 +1806,19 @@ async function Fn(e, n) {
1814
1806
  chatMode: t.chatMode,
1815
1807
  streamId: (h = t.streamingManager) == null ? void 0 : h.streamId,
1816
1808
  sessionId: (I = t.streamingManager) == null ? void 0 : I.sessionId,
1817
- messages: B.map(({ matches: Z, ...ce }) => ce)
1809
+ messages: x.map(({ matches: Z, ...ce }) => ce)
1818
1810
  },
1819
1811
  {
1820
- ...rt(t.chatMode),
1812
+ ...it(t.chatMode),
1821
1813
  skipErrorHandler: !0
1822
1814
  }
1823
1815
  );
1824
1816
  }, {
1825
1817
  limit: 2,
1826
1818
  shouldRetryFn: (h) => {
1827
- var ce, we, ye, ve;
1819
+ var ce, ye, ve, Ce;
1828
1820
  const I = (ce = h == null ? void 0 : h.message) == null ? void 0 : ce.includes("missing or invalid session_id");
1829
- return !((we = h == null ? void 0 : h.message) == null ? void 0 : we.includes("Stream Error")) && !I ? ((ve = (ye = n.callbacks).onError) == null || ve.call(ye, h), !1) : !0;
1821
+ return !((ye = h == null ? void 0 : h.message) == null ? void 0 : ye.includes("Stream Error")) && !I ? ((Ce = (ve = n.callbacks).onError) == null || Ce.call(ve, h), !1) : !0;
1830
1822
  },
1831
1823
  onRetry: async () => {
1832
1824
  await O(), await k(!1);
@@ -1834,43 +1826,43 @@ async function Fn(e, n) {
1834
1826
  });
1835
1827
  };
1836
1828
  try {
1837
- x(), S(), t.messages.push({
1838
- id: ue(),
1829
+ B(), S(), t.messages.push({
1830
+ id: le(),
1839
1831
  role: "user",
1840
- content: f,
1841
- created_at: new Date(re.update()).toISOString()
1842
- }), (M = ($ = n.callbacks).onNewMessage) == null || M.call($, [...t.messages], "user");
1843
- const B = await R(), K = await V([...t.messages], B);
1832
+ content: m,
1833
+ created_at: new Date(ne.update()).toISOString()
1834
+ }), (A = ($ = n.callbacks).onNewMessage) == null || A.call($, [...t.messages], "user");
1835
+ const x = await R(), K = await V([...t.messages], x);
1844
1836
  return t.messages.push({
1845
- id: ue(),
1837
+ id: le(),
1846
1838
  role: "assistant",
1847
1839
  content: K.result || "",
1848
1840
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1849
1841
  context: K.context,
1850
1842
  matches: K.matches
1851
- }), d.track("agent-message-send", {
1843
+ }), c.track("agent-message-send", {
1852
1844
  event: "success",
1853
1845
  messages: t.messages.length + 1
1854
- }), K.result && ((Q = (U = n.callbacks).onNewMessage) == null || Q.call(U, [...t.messages], "answer"), d.track("agent-message-received", {
1855
- latency: re.get(!0),
1846
+ }), K.result && ((Q = (U = n.callbacks).onNewMessage) == null || Q.call(U, [...t.messages], "answer"), c.track("agent-message-received", {
1847
+ latency: ne.get(!0),
1856
1848
  messages: t.messages.length
1857
1849
  })), K;
1858
- } catch (B) {
1859
- throw ((X = t.messages[t.messages.length - 1]) == null ? void 0 : X.role) === "assistant" && t.messages.pop(), d.track("agent-message-send", {
1850
+ } catch (x) {
1851
+ throw ((X = t.messages[t.messages.length - 1]) == null ? void 0 : X.role) === "assistant" && t.messages.pop(), c.track("agent-message-send", {
1860
1852
  event: "error",
1861
1853
  messages: t.messages.length
1862
- }), B;
1854
+ }), x;
1863
1855
  }
1864
1856
  },
1865
- rate(f, S, R) {
1866
- var M, U, Q, X;
1867
- const V = t.messages.find((B) => B.id === f);
1857
+ rate(m, S, R) {
1858
+ var A, U, Q, X;
1859
+ const V = t.messages.find((x) => x.id === m);
1868
1860
  if (t.chat) {
1869
1861
  if (!V)
1870
1862
  throw new Error("Message not found");
1871
1863
  } else throw new Error("Chat is not initialized");
1872
- const $ = ((M = V.matches) == null ? void 0 : M.map((B) => [B.document_id, B.id])) ?? [];
1873
- return d.track("agent-rate", {
1864
+ const $ = ((A = V.matches) == null ? void 0 : A.map((x) => [x.document_id, x.id])) ?? [];
1865
+ return c.track("agent-rate", {
1874
1866
  event: R ? "update" : "create",
1875
1867
  thumb: S === 1 ? "up" : "down",
1876
1868
  knowledge_id: ((U = l.knowledge) == null ? void 0 : U.id) ?? "",
@@ -1878,53 +1870,53 @@ async function Fn(e, n) {
1878
1870
  score: S
1879
1871
  }), R ? g.updateRating(l.id, t.chat.id, R, {
1880
1872
  knowledge_id: ((Q = l.knowledge) == null ? void 0 : Q.id) ?? "",
1881
- message_id: f,
1873
+ message_id: m,
1882
1874
  matches: $,
1883
1875
  score: S
1884
1876
  }) : g.createRating(l.id, t.chat.id, {
1885
1877
  knowledge_id: ((X = l.knowledge) == null ? void 0 : X.id) ?? "",
1886
- message_id: f,
1878
+ message_id: m,
1887
1879
  matches: $,
1888
1880
  score: S
1889
1881
  });
1890
1882
  },
1891
- deleteRate(f) {
1883
+ deleteRate(m) {
1892
1884
  if (!t.chat)
1893
1885
  throw new Error("Chat is not initialized");
1894
- return d.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
1886
+ return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, m);
1895
1887
  },
1896
- async speak(f) {
1897
- var $, M, U;
1888
+ async speak(m) {
1889
+ var $, A, U;
1898
1890
  function S() {
1899
- if (typeof f == "string") {
1891
+ if (typeof m == "string") {
1900
1892
  if (!l.presenter.voice)
1901
1893
  throw new Error("Presenter voice is not initialized");
1902
1894
  return {
1903
1895
  type: "text",
1904
1896
  provider: l.presenter.voice,
1905
- input: f,
1897
+ input: m,
1906
1898
  ssml: !1
1907
1899
  };
1908
1900
  }
1909
- if (f.type === "text" && !f.provider) {
1901
+ if (m.type === "text" && !m.provider) {
1910
1902
  if (!l.presenter.voice)
1911
1903
  throw new Error("Presenter voice is not initialized");
1912
1904
  return {
1913
1905
  type: "text",
1914
1906
  provider: l.presenter.voice,
1915
- input: f.input,
1916
- ssml: f.ssml
1907
+ input: m.input,
1908
+ ssml: m.ssml
1917
1909
  };
1918
1910
  }
1919
- return f;
1911
+ return m;
1920
1912
  }
1921
1913
  const R = S();
1922
- if (d.track("agent-speak", R), re.update(), t.messages && R.type === "text" && (t.messages.push({
1923
- id: ue(),
1914
+ if (c.track("agent-speak", R), ne.update(), t.messages && R.type === "text" && (t.messages.push({
1915
+ id: le(),
1924
1916
  role: "assistant",
1925
1917
  content: R.input,
1926
1918
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1927
- }), (M = ($ = n.callbacks).onNewMessage) == null || M.call($, [...t.messages], "answer")), Bt(t.chatMode))
1919
+ }), (A = ($ = n.callbacks).onNewMessage) == null || A.call($, [...t.messages], "answer")), Bt(t.chatMode))
1928
1920
  return {
1929
1921
  duration: 0,
1930
1922
  video_id: "",
@@ -1942,28 +1934,28 @@ async function Fn(e, n) {
1942
1934
  }
1943
1935
  export {
1944
1936
  J as AgentActivityState,
1945
- Rt as AgentStatus,
1946
- wt as ChatCreationFailed,
1937
+ Tt as AgentStatus,
1938
+ yt as ChatCreationFailed,
1947
1939
  N as ChatMode,
1948
- yt as ChatModeDowngraded,
1940
+ vt as ChatModeDowngraded,
1949
1941
  q as ChatProgress,
1950
- _ as ConnectionState,
1951
- ne as ConnectivityState,
1952
- It as DocumentType,
1953
- Et as KnowledgeType,
1954
- St as PlanGroup,
1955
- Dt as Providers,
1956
- Tt as RateState,
1942
+ b as ConnectionState,
1943
+ te as ConnectivityState,
1944
+ Dt as DocumentType,
1945
+ It as KnowledgeType,
1946
+ Rt as PlanGroup,
1947
+ Mt as Providers,
1948
+ kt as RateState,
1957
1949
  E as StreamEvents,
1958
- ie as StreamType,
1950
+ re as StreamType,
1959
1951
  T as StreamingState,
1960
- kt as Subject,
1952
+ Et as Subject,
1961
1953
  Pe as TransportProvider,
1962
- Ct as UserPlan,
1963
- de as ValidationError,
1964
- Ge as VideoType,
1965
- Mt as VoiceAccess,
1966
- vt as WsError,
1967
- Fn as createAgentManager,
1968
- xn as mapVideoType
1954
+ St as UserPlan,
1955
+ ue as ValidationError,
1956
+ Ze as VideoType,
1957
+ At as VoiceAccess,
1958
+ Ct as WsError,
1959
+ zn as createAgentManager,
1960
+ Fn as mapVideoType
1969
1961
  };