@d-id/client-sdk 1.1.67 → 1.1.68-staging.316

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- var We = Object.defineProperty;
2
- var Je = (e, t, r) => t in e ? We(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var Z = (e, t, r) => Je(e, typeof t != "symbol" ? t + "" : t, r);
1
+ var Je = Object.defineProperty;
2
+ var Oe = (e, t, r) => t in e ? Je(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var Z = (e, t, r) => Oe(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  class ce extends Error {
5
5
  constructor({ kind: r, description: a, error: c }) {
6
6
  super(JSON.stringify({ kind: r, description: a }));
@@ -10,7 +10,7 @@ class ce extends Error {
10
10
  this.kind = r, this.description = a, this.error = c;
11
11
  }
12
12
  }
13
- class Oe extends ce {
13
+ class He extends ce {
14
14
  constructor(t, r) {
15
15
  super({
16
16
  kind: "ChatCreationFailed",
@@ -18,7 +18,7 @@ class Oe extends ce {
18
18
  });
19
19
  }
20
20
  }
21
- class He extends ce {
21
+ class qe extends ce {
22
22
  constructor(t) {
23
23
  super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
24
24
  }
@@ -30,12 +30,12 @@ class G extends ce {
30
30
  this.key = a;
31
31
  }
32
32
  }
33
- class qe extends ce {
33
+ class Xe extends ce {
34
34
  constructor(t) {
35
35
  super({ kind: "WSError", description: t });
36
36
  }
37
37
  }
38
- var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(Ye || {}), Ge = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ge || {}), Qe = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Qe || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), U = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(U || {}), Ze = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Ze || {}), et = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(et || {}), tt = /* @__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))(tt || {}), Pe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Pe || {});
38
+ var Ye = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Ye || {}), Ge = /* @__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))(Ge || {}), Qe = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Qe || {}), Ze = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Ze || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), N = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(N || {}), et = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(et || {}), tt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(tt || {}), rt = /* @__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))(rt || {}), je = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(je || {});
39
39
  const sr = (e) => {
40
40
  switch (e) {
41
41
  case "clip":
@@ -48,12 +48,12 @@ const sr = (e) => {
48
48
  throw new Error(`Unknown video type: ${e}`);
49
49
  }
50
50
  };
51
- var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), te = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(te || {}), ne = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ne || {}), P = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(P || {}), L = /* @__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))(L || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), he = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(he || {}), rt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(rt || {}), nt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(nt || {});
52
- const at = 45 * 1e3, it = "X-Playground-Chat", de = "https://api.d-id.com", st = "wss://notifications.d-id.com", ot = "79f81a83a67430be2bc0fd61042b8faa", or = (...e) => {
53
- }, je = (e) => new Promise((t) => setTimeout(t, e)), Q = (e = 16) => {
51
+ var k = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(k || {}), te = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(te || {}), ne = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ne || {}), P = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(P || {}), L = /* @__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))(L || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), pe = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(pe || {}), nt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(nt || {}), at = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(at || {});
52
+ const it = 45 * 1e3, st = "X-Playground-Chat", de = "https://api.d-id.com", ot = "wss://notifications.d-id.com", ct = "79f81a83a67430be2bc0fd61042b8faa", or = (...e) => {
53
+ }, Be = (e) => new Promise((t) => setTimeout(t, e)), Q = (e = 16) => {
54
54
  const t = new Uint8Array(e);
55
55
  return window.crypto.getRandomValues(t), Array.from(t, (r) => r.toString(16).padStart(2, "0")).join("").slice(0, 13);
56
- }, Be = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, ct = (e) => {
56
+ }, $e = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, dt = (e) => {
57
57
  switch (e.type) {
58
58
  case "expressive":
59
59
  return "v4";
@@ -62,13 +62,13 @@ const at = 45 * 1e3, it = "X-Playground-Chat", de = "https://api.d-id.com", st =
62
62
  case "talk":
63
63
  return "v2";
64
64
  }
65
- }, dt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, pe = (e) => e === Pe.Expressive, lt = (e) => [x.TextOnly, x.Playground, x.Maintenance].includes(e), $e = (e) => e && [x.DirectPlayback, x.Off].includes(e), Se = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, ke = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, ut = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
66
- function mt(e) {
65
+ }, lt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, he = (e) => e === je.Expressive, ut = (e) => [x.TextOnly, x.Playground, x.Maintenance].includes(e), ze = (e) => e && [x.DirectPlayback, x.Off].includes(e), Se = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, ke = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, mt = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
66
+ function ft(e) {
67
67
  const t = e.split("?")[0].split("#")[0].toLowerCase();
68
- return ut.some((r) => t.endsWith(r));
68
+ return mt.some((r) => t.endsWith(r));
69
69
  }
70
70
  const Re = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), De = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
71
- function ft(e) {
71
+ function gt(e) {
72
72
  if (e.length === 0)
73
73
  return [];
74
74
  const t = [];
@@ -83,7 +83,7 @@ function ft(e) {
83
83
  if (!t.some((o) => r.index >= o.index && r.index < o.index + o.length)) {
84
84
  const o = r[2], n = r[1];
85
85
  let i;
86
- mt(o) ? i = { type: "video", src: o, alt: n } : (i = { type: "image", src: o, alt: n }, o.toLowerCase().endsWith(".gif") && (i.mimeType = "image/gif")), t.push({ index: r.index, length: r[0].length, part: i });
86
+ ft(o) ? i = { type: "video", src: o, alt: n } : (i = { type: "image", src: o, alt: n }, o.toLowerCase().endsWith(".gif") && (i.mimeType = "image/gif")), t.push({ index: r.index, length: r[0].length, part: i });
87
87
  }
88
88
  for (Re.lastIndex = 0; (r = Re.exec(e)) !== null; )
89
89
  t.some((o) => r.index >= o.index && r.index < o.index + o.length) || t.push({
@@ -108,9 +108,9 @@ function ft(e) {
108
108
  }
109
109
  let Ie = "", le = [];
110
110
  function re(e) {
111
- return e === Ie || (Ie = e, le = ft(e)), le;
111
+ return e === Ie || (Ie = e, le = gt(e)), le;
112
112
  }
113
- function gt(e, t) {
113
+ function pt(e, t) {
114
114
  let r;
115
115
  return {
116
116
  promise: new Promise((c, s) => {
@@ -134,12 +134,12 @@ async function ue(e, t) {
134
134
  try {
135
135
  if (!r.timeout)
136
136
  return await e();
137
- const { promise: s, clear: o } = gt(r.timeout, r.timeoutErrorMessage), n = e().finally(o);
137
+ const { promise: s, clear: o } = pt(r.timeout, r.timeoutErrorMessage), n = e().finally(o);
138
138
  return await Promise.race([n, s]);
139
139
  } catch (s) {
140
140
  if (a = s, !r.shouldRetryFn(s) || c >= r.limit)
141
141
  throw s;
142
- await je(r.delayMs), r.onRetry(s);
142
+ await Be(r.delayMs), r.onRetry(s);
143
143
  }
144
144
  throw a;
145
145
  }
@@ -154,7 +154,7 @@ function me(e) {
154
154
  return t;
155
155
  }
156
156
  let ht = Q();
157
- function ze(e, t) {
157
+ function Fe(e, t) {
158
158
  if (e.type === "bearer")
159
159
  return `Bearer ${e.token}`;
160
160
  if (e.type === "basic")
@@ -163,24 +163,30 @@ function ze(e, t) {
163
163
  return `Client-Key ${e.clientKey}.${me(t)}_${ht}`;
164
164
  throw new Error(`Unknown auth type: ${e}`);
165
165
  }
166
- const pt = (e) => ue(e, {
166
+ const wt = (e) => ue(e, {
167
167
  limit: 3,
168
168
  delayMs: 1e3,
169
169
  timeout: 0,
170
170
  shouldRetryFn: (t) => t.status === 429
171
171
  });
172
- function Fe(e, t = de, r, a) {
172
+ function Ne(e, t = de, r, a) {
173
173
  const c = async (s, o) => {
174
- const { skipErrorHandler: n, ...i } = o || {}, d = await pt(
175
- () => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
176
- ...i,
177
- headers: {
178
- ...i.headers,
179
- Authorization: ze(e, a),
180
- "Content-Type": "application/json"
181
- }
182
- })
183
- );
174
+ const { skipErrorHandler: n, ...i } = o || {};
175
+ let d;
176
+ try {
177
+ d = await wt(
178
+ () => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
179
+ ...i,
180
+ headers: {
181
+ ...i.headers,
182
+ Authorization: Fe(e, a),
183
+ "Content-Type": "application/json"
184
+ }
185
+ })
186
+ );
187
+ } catch (m) {
188
+ throw !((m == null ? void 0 : m.name) === "AbortError") && r && !n && r(m, { url: s, options: i }), m;
189
+ }
184
190
  if (!d.ok) {
185
191
  let m = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
186
192
  const l = new Error(m);
@@ -203,8 +209,8 @@ function Fe(e, t = de, r, a) {
203
209
  }
204
210
  };
205
211
  }
206
- function wt(e, t = de, r, a) {
207
- const c = Fe(e, `${t}/agents`, r, a);
212
+ function vt(e, t = de, r, a) {
213
+ const c = Ne(e, `${t}/agents`, r, a);
208
214
  return {
209
215
  create(s, o) {
210
216
  return c.post("/", s, o);
@@ -241,7 +247,7 @@ function wt(e, t = de, r, a) {
241
247
  }
242
248
  };
243
249
  }
244
- function vt(e) {
250
+ function yt(e) {
245
251
  var c, s, o, n;
246
252
  const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", r = () => {
247
253
  const i = navigator.platform;
@@ -252,20 +258,20 @@ function vt(e) {
252
258
  isMobile: `${t() == "Mobile"}`,
253
259
  browser: navigator.userAgent,
254
260
  origin: window.location.origin,
255
- agentType: Be(a),
261
+ agentType: $e(a),
256
262
  agentVoice: {
257
263
  voiceId: (s = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : s.voice_id,
258
264
  provider: (n = (o = e.presenter) == null ? void 0 : o.voice) == null ? void 0 : n.type
259
265
  }
260
266
  };
261
267
  }
262
- function yt(e) {
268
+ function Ct(e) {
263
269
  var r, a, c, s, o, n;
264
270
  const t = (r = e.llm) == null ? void 0 : r.prompt_customization;
265
271
  return {
266
- agentType: Be(e.presenter),
267
- presenterType: ct(e.presenter),
268
- presenter: dt(e.presenter),
272
+ agentType: $e(e.presenter),
273
+ presenterType: dt(e.presenter),
274
+ presenter: lt(e.presenter),
269
275
  owner_id: e.owner_id ?? "",
270
276
  promptVersion: (a = e.llm) == null ? void 0 : a.prompt_version,
271
277
  behavior: {
@@ -284,8 +290,8 @@ function yt(e) {
284
290
  ...e.access === "public" ? { from: "agent-template" } : {}
285
291
  };
286
292
  }
287
- const Ct = (e) => e.reduce((t, r) => t + r, 0), Me = (e) => Ct(e) / e.length;
288
- function St(e, t, r) {
293
+ const St = (e) => e.reduce((t, r) => t + r, 0), Me = (e) => St(e) / e.length;
294
+ function kt(e, t, r) {
289
295
  var i, d, m;
290
296
  const { event: a, ...c } = e, { template: s } = (t == null ? void 0 : t.llm) || {}, { language: o } = ((i = t == null ? void 0 : t.presenter) == null ? void 0 : i.voice) || {};
291
297
  return {
@@ -299,8 +305,8 @@ function St(e, t, r) {
299
305
  function Ee(e) {
300
306
  "requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
301
307
  }
302
- const kt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
303
- function Rt(e) {
308
+ const Rt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
309
+ function Dt(e) {
304
310
  const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", r = {};
305
311
  return {
306
312
  token: e.token || "testKey",
@@ -344,7 +350,7 @@ function Rt(e) {
344
350
  ])
345
351
  })
346
352
  };
347
- return fetch(kt, d).catch((m) => console.error("Analytics tracking error:", m)), Promise.resolve();
353
+ return fetch(Rt, d).catch((m) => console.error("Analytics tracking error:", m)), Promise.resolve();
348
354
  },
349
355
  linkTrack(a, c, s, o) {
350
356
  r[a] || (r[a] = { events: {}, resolvedDependencies: [] }), o.includes(s) || o.push(s);
@@ -371,21 +377,21 @@ function we() {
371
377
  };
372
378
  }
373
379
  const H = we(), fe = we(), Te = we();
374
- function Ne(e) {
375
- return e === x.Playground ? { headers: { [it]: "true" } } : {};
380
+ function Ve(e) {
381
+ return e === x.Playground ? { headers: { [st]: "true" } } : {};
376
382
  }
377
- async function Ve(e, t, r, a, c = !1, s) {
383
+ async function Ke(e, t, r, a, c = !1, s) {
378
384
  try {
379
- return !s && !$e(a) && (s = await t.newChat(e.id, { persist: c }, Ne(a)), r.track("agent-chat", {
385
+ return !s && !ze(a) && (s = await t.newChat(e.id, { persist: c }, Ve(a)), r.track("agent-chat", {
380
386
  event: "created",
381
387
  chatId: s.id,
382
388
  mode: a
383
389
  })), { chat: s, chatMode: (s == null ? void 0 : s.chat_mode) ?? a };
384
390
  } catch (o) {
385
- throw Dt(o) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
391
+ throw It(o) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
386
392
  }
387
393
  }
388
- const Dt = (e) => {
394
+ const It = (e) => {
389
395
  try {
390
396
  const t = JSON.parse(e.message);
391
397
  return t == null ? void 0 : t.kind;
@@ -393,41 +399,41 @@ const Dt = (e) => {
393
399
  return "UnknownError";
394
400
  }
395
401
  };
396
- function It(e) {
402
+ function Mt(e) {
397
403
  return e && e.length > 0 ? e : [];
398
404
  }
399
- function Mt(e) {
405
+ function Et(e) {
400
406
  return new Promise((t, r) => {
401
- const { callbacks: a, host: c, auth: s, externalId: o } = e, { onMessage: n = null, onOpen: i = null, onClose: d = null, onError: m = null } = a || {}, l = new WebSocket(`${c}?authorization=${encodeURIComponent(ze(s, o))}`);
402
- l.onmessage = n, l.onclose = d, l.onerror = (w) => {
403
- console.error(w), m == null || m("Websocket failed to connect", w), r(w);
404
- }, l.onopen = (w) => {
405
- i == null || i(w), t(l);
407
+ const { callbacks: a, host: c, auth: s, externalId: o } = e, { onMessage: n = null, onOpen: i = null, onClose: d = null, onError: m = null } = a || {}, l = new WebSocket(`${c}?authorization=${encodeURIComponent(Fe(s, o))}`);
408
+ l.onmessage = n, l.onclose = d, l.onerror = (p) => {
409
+ console.error(p), m == null || m("Websocket failed to connect", p), r(p);
410
+ }, l.onopen = (p) => {
411
+ i == null || i(p), t(l);
406
412
  };
407
413
  });
408
414
  }
409
- async function Et(e) {
415
+ async function Tt(e) {
410
416
  const { retries: t = 1 } = e;
411
417
  let r = null;
412
418
  for (let a = 0; (r == null ? void 0 : r.readyState) !== WebSocket.OPEN; a++)
413
419
  try {
414
- r = await Mt(e);
420
+ r = await Et(e);
415
421
  } catch (c) {
416
422
  if (a === t)
417
423
  throw c;
418
- await je(a * 500);
424
+ await Be(a * 500);
419
425
  }
420
426
  return r;
421
427
  }
422
- async function Tt(e, t, r, a) {
423
- const c = r != null && r.onMessage ? [r.onMessage] : [], s = await Et({
428
+ async function _t(e, t, r, a) {
429
+ const c = r != null && r.onMessage ? [r.onMessage] : [], s = await Tt({
424
430
  auth: e,
425
431
  host: t,
426
432
  externalId: a,
427
433
  callbacks: {
428
434
  onError: (o) => {
429
435
  var n;
430
- return (n = r.onError) == null ? void 0 : n.call(r, new qe(o));
436
+ return (n = r.onError) == null ? void 0 : n.call(r, new Xe(o));
431
437
  },
432
438
  onMessage(o) {
433
439
  const n = JSON.parse(o.data);
@@ -441,7 +447,7 @@ async function Tt(e, t, r, a) {
441
447
  subscribeToEvents: (o) => c.push(o)
442
448
  };
443
449
  }
444
- function _t(e) {
450
+ function _e(e) {
445
451
  if (e.answer !== void 0)
446
452
  return e.answer;
447
453
  let t = 0, r = "";
@@ -452,9 +458,7 @@ function _t(e) {
452
458
  function bt(e, t, r) {
453
459
  if (!e.content)
454
460
  return;
455
- const a = t.messages[t.messages.length - 1];
456
- (a == null ? void 0 : a.role) === "assistant" && !a.interrupted && (a.interrupted = !0);
457
- const c = {
461
+ const a = {
458
462
  id: e.id || `user-${Date.now()}`,
459
463
  role: e.role,
460
464
  content: e.content,
@@ -462,73 +466,88 @@ function bt(e, t, r) {
462
466
  created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
463
467
  transcribed: !0
464
468
  };
465
- t.messages.push(c), r == null || r([...t.messages], "user");
469
+ t.messages.push(a), r == null || r([...t.messages], "user");
466
470
  }
467
- function At(e, t, r, a, c, s) {
468
- if (e === U.Transcribe && t.content) {
471
+ function At(e, t, r, a, c, s, o) {
472
+ if (e === N.Transcribe && t.content) {
469
473
  bt(t, a, c);
470
474
  return;
471
475
  }
472
- if (!(e === U.Partial || e === U.Answer))
476
+ if (!(e === N.Partial || e === N.Answer))
473
477
  return;
474
- const o = a.messages[a.messages.length - 1], n = t.id && (o == null ? void 0 : o.role) === "assistant" && o.id !== t.id;
475
- let i;
476
- if ((o == null ? void 0 : o.role) === "assistant" && !n)
477
- i = o;
478
- else if (!o || o.transcribed && o.role === "user" || n)
479
- n && s(), i = {
478
+ const n = a.messages[a.messages.length - 1], i = o === "answer";
479
+ let d;
480
+ if ((n == null ? void 0 : n.role) === "assistant" && !i)
481
+ d = n;
482
+ else if (!n || n.role === "user" || i)
483
+ i && s(), d = {
480
484
  id: t.id || `assistant-${Date.now()}`,
481
485
  role: t.role || "assistant",
482
486
  content: t.content || "",
483
487
  parts: [],
484
488
  created_at: t.created_at || (/* @__PURE__ */ new Date()).toISOString()
485
- }, a.messages.push(i);
489
+ }, a.messages.push(d);
486
490
  else
487
491
  return;
488
- const { content: d, sequence: m } = t;
489
- e === U.Partial ? r[m] = d : r.answer = d;
490
- const l = _t(r);
491
- (i.content !== l || e === U.Answer) && (i.content = l, i.parts = re(l), c == null || c([...a.messages], e));
492
+ const { content: m, sequence: l } = t;
493
+ if (e === N.Partial)
494
+ r[l] = m;
495
+ else {
496
+ const w = _e(r);
497
+ !!(m && m.length < w.length) && (d.interrupted = !0), r.answer = m;
498
+ }
499
+ const p = _e(r);
500
+ (d.content !== p || e === N.Answer) && (d.content = p, d.parts = re(p), c == null || c([...a.messages], e));
492
501
  }
493
502
  function xt(e, t, r, a, c) {
494
- let s = {};
495
- const o = () => s = {};
496
- let n = "answer";
503
+ const s = {}, o = () => {
504
+ for (const d of Object.keys(s))
505
+ delete s[d];
506
+ };
507
+ let n = null;
497
508
  const i = (d, m) => {
498
- var l, w;
499
- m === "user" && o(), n = m, (w = (l = r.callbacks).onNewMessage) == null || w.call(l, d, m);
509
+ var l, p;
510
+ m === "user" && o(), (p = (l = r.callbacks).onNewMessage) == null || p.call(l, d, m);
500
511
  };
501
512
  return {
502
513
  clearQueue: o,
503
514
  onMessage: (d, m) => {
504
- var l, w;
515
+ var l, p;
505
516
  if ("content" in m) {
506
- const v = d === P.ChatAnswer ? U.Answer : d === P.ChatAudioTranscribed ? U.Transcribe : d;
507
- At(v, m, s, t, i, o), v === U.Answer && e.track("agent-message-received", {
517
+ const w = d === P.ChatAnswer ? N.Answer : d === P.ChatAudioTranscribed ? N.Transcribe : d;
518
+ At(
519
+ w,
520
+ m,
521
+ s,
522
+ t,
523
+ i,
524
+ o,
525
+ n
526
+ ), w === N.Partial ? n = "partial" : w === N.Answer && (n = "answer", o()), w === N.Answer && e.track("agent-message-received", {
508
527
  content: m.content,
509
528
  messages: t.messages.length,
510
529
  mode: t.chatMode
511
530
  });
512
531
  } else {
513
- const v = P, k = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], B = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], M = St(m, a, { mode: t.chatMode });
514
- if (d = d, d === v.StreamVideoCreated && (e.linkTrack("agent-video", M, v.StreamVideoCreated, ["start"]), m.sentiment)) {
532
+ const w = P, C = [w.StreamVideoDone, w.StreamVideoError, w.StreamVideoRejected], B = [w.StreamFailed, w.StreamVideoError, w.StreamVideoRejected], M = kt(m, a, { mode: t.chatMode });
533
+ if (d = d, d === w.StreamVideoCreated && (e.linkTrack("agent-video", M, w.StreamVideoCreated, ["start"]), m.sentiment)) {
515
534
  const D = t.messages[t.messages.length - 1];
516
535
  if ((D == null ? void 0 : D.role) === "assistant") {
517
536
  const $ = { ...D, sentiment: m.sentiment };
518
- t.messages[t.messages.length - 1] = $, i == null || i([...t.messages], n);
537
+ t.messages[t.messages.length - 1] = $, i == null || i([...t.messages], n ?? "answer");
519
538
  }
520
539
  }
521
- if (k.includes(d)) {
540
+ if (C.includes(d)) {
522
541
  const D = d.split("/")[1];
523
542
  B.includes(d) ? e.track("agent-video", { ...M, event: D }) : e.linkTrack("agent-video", { ...M, event: D }, d, ["done"]);
524
543
  }
525
- B.includes(d) && ((w = (l = r.callbacks).onError) == null || w.call(l, new Error(`Stream failed with event ${d}`), { data: m })), m.event === v.StreamDone && c();
544
+ B.includes(d) && ((p = (l = r.callbacks).onError) == null || p.call(l, new Error(`Stream failed with event ${d}`), { data: m })), m.event === w.StreamDone && c();
526
545
  }
527
546
  }
528
547
  };
529
548
  }
530
549
  function Lt(e, t, r, a) {
531
- const c = Fe(e, `${t}/agents/${r}`, a);
550
+ const c = Ne(e, `${t}/agents/${r}`, a);
532
551
  return {
533
552
  createStream(s, o) {
534
553
  return c.post("/streams", s, { signal: o });
@@ -631,7 +650,7 @@ function $t(e) {
631
650
  freezeDuration: s.totalFreezesDuration
632
651
  };
633
652
  }
634
- function _e(e, t, r) {
653
+ function be(e, t, r) {
635
654
  const a = e.map((i, d) => d === 0 ? r ? {
636
655
  timestamp: i.timestamp,
637
656
  duration: 0,
@@ -699,7 +718,7 @@ function _e(e, t, r) {
699
718
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
700
719
  };
701
720
  }
702
- function Ke(e, t) {
721
+ function Ue(e, t) {
703
722
  for (const r of e.values())
704
723
  if ((r == null ? void 0 : r.type) === "inbound-rtp" && r.kind === t)
705
724
  return r;
@@ -716,18 +735,18 @@ function cr(e, t) {
716
735
  c = setTimeout(i, ee);
717
736
  return;
718
737
  }
719
- const m = Ke(d, "audio");
738
+ const m = Ue(d, "audio");
720
739
  if (!m) {
721
740
  c = setTimeout(i, ee);
722
741
  return;
723
742
  }
724
- const l = m.totalAudioEnergy ?? 0, w = m.totalSamplesReceived ?? 0;
743
+ const l = m.totalAudioEnergy ?? 0, p = m.totalSamplesReceived ?? 0;
725
744
  if (!a) {
726
- s = l, o = w, a = !0, c = setTimeout(i, ee);
745
+ s = l, o = p, a = !0, c = setTimeout(i, ee);
727
746
  return;
728
747
  }
729
- const v = l - s, k = w - o;
730
- if (s = l, o = w, k > 0 && v > 0) {
748
+ const w = l - s, C = p - o;
749
+ if (s = l, o = p, C > 0 && w > 0) {
731
750
  r = !1, t(n);
732
751
  return;
733
752
  }
@@ -749,7 +768,7 @@ const oe = 100, zt = Math.max(Math.ceil(400 / oe), 1), Ft = 0.25, Nt = 0.28;
749
768
  function Vt() {
750
769
  let e = 0, t, r, a = 0;
751
770
  return (c) => {
752
- const s = Ke(c, "video");
771
+ const s = Ue(c, "video");
753
772
  if (!s)
754
773
  return { isReceiving: !1, avgJitterDelayInInterval: a };
755
774
  const o = s.jitterBufferDelay, n = s.jitterBufferEmittedCount;
@@ -763,18 +782,18 @@ function Vt() {
763
782
  };
764
783
  }
765
784
  function Kt(e, t, r, a, c) {
766
- let s = null, o = [], n, i = 0, d = !1, m = te.Unknown, l = te.Unknown, w = 0, v = 0;
767
- const k = Vt();
785
+ let s = null, o = [], n, i = 0, d = !1, m = te.Unknown, l = te.Unknown, p = 0, w = 0;
786
+ const C = Vt();
768
787
  async function B() {
769
788
  const M = await e();
770
789
  if (!M)
771
790
  return;
772
- const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: _ } = k(M), q = $t(M);
791
+ const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: _ } = C(M), q = $t(M);
773
792
  if (D)
774
- i = 0, w = _ - v, l = $ < Ft ? te.Strong : $ > Nt && w > 1 ? te.Weak : m, l !== m && (c == null || c(l), m = l, v += w, w = 0), d || (a == null || a(S.Start), n = o[o.length - 1], o = [], d = !0), o.push(q);
793
+ i = 0, p = _ - w, l = $ < Ft ? te.Strong : $ > Nt && p > 1 ? te.Weak : m, l !== m && (c == null || c(l), m = l, w += p, p = 0), d || (a == null || a(k.Start), n = o[o.length - 1], o = [], d = !0), o.push(q);
775
794
  else if (d && (i++, i >= zt)) {
776
- const J = _e(o, oe, n);
777
- a == null || a(S.Stop, J), t() || r(), v = _, d = !1;
795
+ const J = be(o, oe, n);
796
+ a == null || a(k.Stop, J), t() || r(), w = _, d = !1;
778
797
  }
779
798
  }
780
799
  return {
@@ -784,11 +803,11 @@ function Kt(e, t, r, a, c) {
784
803
  stop: () => {
785
804
  s && (clearInterval(s), s = null);
786
805
  },
787
- getReport: () => _e(o, oe, n)
806
+ getReport: () => be(o, oe, n)
788
807
  };
789
808
  }
790
809
  const Ut = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
791
- function be(e) {
810
+ function Ae(e) {
792
811
  switch (e) {
793
812
  case "connected":
794
813
  return L.Connected;
@@ -824,7 +843,7 @@ function Jt({
824
843
  report: a,
825
844
  log: c
826
845
  }) {
827
- e === S.Start && t === S.Start ? (c("CALLBACK: onVideoStateChange(Start)"), r == null || r(S.Start)) : e === S.Stop && t === S.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), r == null || r(S.Stop, a));
846
+ e === k.Start && t === k.Start ? (c("CALLBACK: onVideoStateChange(Start)"), r == null || r(k.Start)) : e === k.Stop && t === k.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), r == null || r(k.Stop, a));
828
847
  }
829
848
  function Ot({
830
849
  statsSignal: e,
@@ -834,9 +853,9 @@ function Ot({
834
853
  report: c,
835
854
  log: s
836
855
  }) {
837
- e === S.Start ? (s("CALLBACK: onVideoStateChange(Start)"), r == null || r(S.Start)) : e === S.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), r == null || r(S.Stop, c)), t === S.Start ? a == null || a(ne.Talking) : t === S.Stop && (a == null || a(ne.Idle));
856
+ e === k.Start ? (s("CALLBACK: onVideoStateChange(Start)"), r == null || r(k.Start)) : e === k.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), r == null || r(k.Stop, c)), t === k.Start ? a == null || a(ne.Talking) : t === k.Stop && (a == null || a(ne.Idle));
838
857
  }
839
- function Ae({
858
+ function xe({
840
859
  statsSignal: e,
841
860
  dataChannelSignal: t,
842
861
  onVideoStateChange: r,
@@ -857,8 +876,8 @@ function Ae({
857
876
  async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de, analytics: o }, n) {
858
877
  var E;
859
878
  const i = Pt(r, "WebRTCStreamingManager"), d = Wt(i);
860
- let m = !1, l = !1, w = S.Stop, v = S.Stop;
861
- const { startConnection: k, sendStreamRequest: B, close: M, createStream: D, addIceCandidate: $ } = Lt(
879
+ let m = !1, l = !1, p = k.Stop, w = k.Stop;
880
+ const { startConnection: C, sendStreamRequest: B, close: M, createStream: D, addIceCandidate: $ } = Lt(
862
881
  c,
863
882
  s,
864
883
  e,
@@ -867,17 +886,17 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
867
886
  id: _,
868
887
  offer: q,
869
888
  ice_servers: J,
870
- session_id: N,
889
+ session_id: V,
871
890
  fluent: X,
872
891
  interrupt_enabled: O
873
892
  } = await D(t, n);
874
- (E = a.onStreamCreated) == null || E.call(a, { stream_id: _, session_id: N, agent_id: e });
893
+ (E = a.onStreamCreated) == null || E.call(a, { stream_id: _, session_id: V, agent_id: e });
875
894
  const I = new Ut({ iceServers: J }), Y = I.createDataChannel("JanusDataChannel");
876
- if (!N)
895
+ if (!V)
877
896
  throw new Error("Could not create session_id");
878
- const V = X ? W.Fluent : W.Legacy;
897
+ const K = X ? W.Fluent : W.Legacy;
879
898
  o.enrich({
880
- "stream-type": V
899
+ "stream-type": K
881
900
  });
882
901
  const ae = t.stream_warmup && !X, ie = () => m, u = () => {
883
902
  var f;
@@ -886,13 +905,13 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
886
905
  () => I.getStats(),
887
906
  ie,
888
907
  u,
889
- (f, h) => Ae({
890
- statsSignal: v = f,
891
- dataChannelSignal: V === W.Legacy ? w : void 0,
908
+ (f, h) => xe({
909
+ statsSignal: w = f,
910
+ dataChannelSignal: K === W.Legacy ? p : void 0,
892
911
  onVideoStateChange: a.onVideoStateChange,
893
912
  onAgentActivityStateChange: a.onAgentActivityStateChange,
894
913
  report: h,
895
- streamType: V,
914
+ streamType: K,
896
915
  log: i
897
916
  }),
898
917
  (f) => {
@@ -911,31 +930,31 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
911
930
  sdpMid: f.candidate.sdpMid,
912
931
  sdpMLineIndex: f.candidate.sdpMLineIndex
913
932
  },
914
- N,
933
+ V,
915
934
  n
916
- ) : $(_, { candidate: null }, N, n);
935
+ ) : $(_, { candidate: null }, V, n);
917
936
  } catch (b) {
918
937
  (h = a.onError) == null || h.call(a, b, { streamId: _ });
919
938
  }
920
939
  }, Y.onopen = () => {
921
940
  l = !0, (!ae || m) && u();
922
941
  };
923
- let p = null;
942
+ let v = null;
924
943
  const y = (f) => {
925
944
  var h;
926
- p = f, (h = a.onVideoIdChange) == null || h.call(a, f);
945
+ v = f, (h = a.onVideoIdChange) == null || h.call(a, f);
927
946
  };
928
- function C(f, h) {
947
+ function S(f, h) {
929
948
  if (f === P.StreamStarted && typeof h == "object" && "metadata" in h) {
930
949
  const b = h.metadata;
931
950
  y(b.videoId);
932
951
  }
933
- f === P.StreamDone && y(null), w = f === P.StreamStarted ? S.Start : S.Stop, Ae({
934
- statsSignal: V === W.Legacy ? v : void 0,
935
- dataChannelSignal: w,
952
+ f === P.StreamDone && y(null), p = f === P.StreamStarted ? k.Start : k.Stop, xe({
953
+ statsSignal: K === W.Legacy ? w : void 0,
954
+ dataChannelSignal: p,
936
955
  onVideoStateChange: a.onVideoStateChange,
937
956
  onAgentActivityStateChange: a.onAgentActivityStateChange,
938
- streamType: V,
957
+ streamType: K,
939
958
  log: i
940
959
  });
941
960
  }
@@ -945,8 +964,8 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
945
964
  b && o.enrich({ streamMetadata: b }), (T = a.onStreamReady) == null || T.call(a);
946
965
  }
947
966
  const j = {
948
- [P.StreamStarted]: C,
949
- [P.StreamDone]: C,
967
+ [P.StreamStarted]: S,
968
+ [P.StreamDone]: S,
950
969
  [P.StreamReady]: R
951
970
  };
952
971
  Y.onmessage = (f) => {
@@ -956,14 +975,14 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
956
975
  }, I.oniceconnectionstatechange = () => {
957
976
  var h;
958
977
  i("peerConnection.oniceconnectionstatechange => " + I.iceConnectionState);
959
- const f = be(I.iceConnectionState);
978
+ const f = Ae(I.iceConnectionState);
960
979
  f !== L.Connected && ((h = a.onConnectionStateChange) == null || h.call(a, f));
961
980
  }, I.ontrack = (f) => {
962
981
  var h;
963
982
  i("peerConnection.ontrack", f), i("CALLBACK: onSrcObjectReady"), (h = a.onSrcObjectReady) == null || h.call(a, f.streams[0]);
964
983
  }, await I.setRemoteDescription(q), i("set remote description OK");
965
984
  const z = await I.createAnswer();
966
- i("create answer OK"), await I.setLocalDescription(z), i("set local description OK"), await k(_, z, N, n), i("start connection OK");
985
+ i("create answer OK"), await I.setLocalDescription(z), i("set local description OK"), await C(_, z, V, n), i("start connection OK");
967
986
  function F(f) {
968
987
  var h, b;
969
988
  if (!m || Y.readyState !== "open") {
@@ -984,7 +1003,7 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
984
1003
  * @param payload
985
1004
  */
986
1005
  speak(f) {
987
- return B(_, N, f);
1006
+ return B(_, V, f);
988
1007
  },
989
1008
  /**
990
1009
  * Method to close RTC connection
@@ -992,7 +1011,7 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
992
1011
  async disconnect() {
993
1012
  var f;
994
1013
  if (_) {
995
- const h = be(I.iceConnectionState);
1014
+ const h = Ae(I.iceConnectionState);
996
1015
  if (I) {
997
1016
  if (h === L.New) {
998
1017
  g.stop();
@@ -1001,7 +1020,7 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
1001
1020
  I.close(), I.oniceconnectionstatechange = null, I.onnegotiationneeded = null, I.onicecandidate = null, I.ontrack = null;
1002
1021
  }
1003
1022
  try {
1004
- h === L.Connected && await M(_, N).catch((b) => {
1023
+ h === L.Connected && await M(_, V).catch((b) => {
1005
1024
  });
1006
1025
  } catch (b) {
1007
1026
  i("Error on close stream connection", b);
@@ -1013,24 +1032,24 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
1013
1032
  /**
1014
1033
  * Session identifier information, should be returned in the body of all streaming requests
1015
1034
  */
1016
- sessionId: N,
1035
+ sessionId: V,
1017
1036
  /**
1018
1037
  * Id of current RTC stream
1019
1038
  */
1020
1039
  streamId: _,
1021
- streamType: V,
1040
+ streamType: K,
1022
1041
  interruptAvailable: O ?? !1,
1023
1042
  isInterruptible: !0,
1024
1043
  interrupt(f) {
1025
1044
  if (!O)
1026
1045
  throw new Error("Interrupt is not enabled for this stream");
1027
- if (V !== W.Fluent)
1046
+ if (K !== W.Fluent)
1028
1047
  throw new Error("Interrupt only available for Fluent streams");
1029
- if (!p)
1048
+ if (!v)
1030
1049
  throw new Error("No active video to interrupt");
1031
1050
  const h = {
1032
1051
  type: P.StreamInterrupt,
1033
- videoId: p,
1052
+ videoId: v,
1034
1053
  timestamp: Date.now()
1035
1054
  };
1036
1055
  F(JSON.stringify(h));
@@ -1048,8 +1067,8 @@ async function qt(e, t, r, a) {
1048
1067
  case "v2": {
1049
1068
  const { version: s, ...o } = t;
1050
1069
  switch (o.transport.provider) {
1051
- case he.Livekit:
1052
- const { createLiveKitStreamingManager: n } = await import("./livekit-manager-zAbqmsie.js");
1070
+ case pe.Livekit:
1071
+ const { createLiveKitStreamingManager: n } = await import("./livekit-manager-Zdv-HZDQ.js");
1053
1072
  return n(c, o, r);
1054
1073
  default:
1055
1074
  throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
@@ -1063,7 +1082,7 @@ const Xt = "cht";
1063
1082
  function Yt() {
1064
1083
  return {
1065
1084
  transport: {
1066
- provider: he.Livekit
1085
+ provider: pe.Livekit
1067
1086
  }
1068
1087
  };
1069
1088
  }
@@ -1081,7 +1100,7 @@ function Gt(e) {
1081
1100
  }, ...r && { end_user_data: r } };
1082
1101
  }
1083
1102
  function Qt(e, t) {
1084
- return pe(e.presenter.type) ? { version: ge.V2, ...Yt() } : { version: ge.V1, ...Gt(t) };
1103
+ return he(e.presenter.type) ? { version: ge.V2, ...Yt() } : { version: ge.V1, ...Gt(t) };
1085
1104
  }
1086
1105
  function Zt(e, t, r) {
1087
1106
  r.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
@@ -1090,7 +1109,7 @@ function er(e, t, r, a, c) {
1090
1109
  c === W.Fluent ? tr(e, t, r, a, c) : rr(e, t, r, a, c);
1091
1110
  }
1092
1111
  function tr(e, t, r, a, c) {
1093
- e === S.Start ? a.track("stream-session", { event: "start", "stream-type": c }) : e === S.Stop && a.track("stream-session", {
1112
+ e === k.Start ? a.track("stream-session", { event: "start", "stream-type": c }) : e === k.Stop && a.track("stream-session", {
1094
1113
  event: "stop",
1095
1114
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1096
1115
  background: t.presenter.type === "clip" && t.presenter.background,
@@ -1098,10 +1117,10 @@ function tr(e, t, r, a, c) {
1098
1117
  ...r
1099
1118
  });
1100
1119
  }
1101
- function xe(e, t, r, a, c) {
1102
- e === S.Start ? r.linkTrack("agent-video", { event: "start", ...c, "stream-type": a }, "start", [
1120
+ function Le(e, t, r, a, c) {
1121
+ e === k.Start ? r.linkTrack("agent-video", { event: "start", ...c, "stream-type": a }, "start", [
1103
1122
  P.StreamVideoCreated
1104
- ]) : e === S.Stop && r.linkTrack(
1123
+ ]) : e === k.Stop && r.linkTrack(
1105
1124
  "agent-video",
1106
1125
  {
1107
1126
  event: "stop",
@@ -1114,12 +1133,12 @@ function xe(e, t, r, a, c) {
1114
1133
  );
1115
1134
  }
1116
1135
  function rr(e, t, r, a, c) {
1117
- e === S.Start ? a.linkTrack(
1136
+ e === k.Start ? a.linkTrack(
1118
1137
  "agent-video",
1119
1138
  { event: "start", latency: H.get(!0), "stream-type": c },
1120
1139
  "start",
1121
1140
  [P.StreamVideoCreated]
1122
- ) : e === S.Stop && a.linkTrack(
1141
+ ) : e === k.Stop && a.linkTrack(
1123
1142
  "agent-video",
1124
1143
  {
1125
1144
  event: "stop",
@@ -1149,7 +1168,7 @@ function nr(e, t, r) {
1149
1168
  extra_keys: c.extra ? Object.keys(c.extra).length : 0
1150
1169
  });
1151
1170
  }
1152
- function Le(e, t, r, a) {
1171
+ function Pe(e, t, r, a) {
1153
1172
  return H.reset(), Te.update(), new Promise(async (c, s) => {
1154
1173
  try {
1155
1174
  let o, n = !1;
@@ -1167,32 +1186,32 @@ function Le(e, t, r, a) {
1167
1186
  analytics: r,
1168
1187
  callbacks: {
1169
1188
  ...t.callbacks,
1170
- onConnectionStateChange: (l, w) => {
1171
- var v, k;
1172
- (k = (v = t.callbacks).onConnectionStateChange) == null || k.call(v, l), Zt(l, w, r), l === L.Connected && (o ? c(o) : n = !0);
1189
+ onConnectionStateChange: (l, p) => {
1190
+ var w, C;
1191
+ (C = (w = t.callbacks).onConnectionStateChange) == null || C.call(w, l), Zt(l, p, r), l === L.Connected && (o ? c(o) : n = !0);
1173
1192
  },
1174
- onVideoStateChange: (l, w) => {
1175
- var v, k;
1176
- (k = (v = t.callbacks).onVideoStateChange) == null || k.call(v, l), er(
1193
+ onVideoStateChange: (l, p) => {
1194
+ var w, C;
1195
+ (C = (w = t.callbacks).onVideoStateChange) == null || C.call(w, l), er(
1177
1196
  l,
1178
1197
  e,
1179
- w,
1198
+ p,
1180
1199
  r,
1181
1200
  o.streamType
1182
1201
  );
1183
1202
  },
1184
1203
  onAgentActivityStateChange: (l) => {
1185
- var w, v;
1186
- (v = (w = t.callbacks).onAgentActivityStateChange) == null || v.call(w, l), l === ne.Talking ? (fe.update(), d = (k) => {
1187
- xe(
1188
- S.Start,
1204
+ var p, w;
1205
+ (w = (p = t.callbacks).onAgentActivityStateChange) == null || w.call(p, l), l === ne.Talking ? (fe.update(), d = (C) => {
1206
+ Le(
1207
+ k.Start,
1189
1208
  e,
1190
1209
  r,
1191
1210
  o.streamType,
1192
- k
1211
+ C
1193
1212
  ), d = null;
1194
- }, m || d({ latency: H.get(!0) })) : (fe.reset(), d = null, xe(
1195
- S.Stop,
1213
+ }, m || d({ latency: H.get(!0) })) : (fe.reset(), d = null, Le(
1214
+ k.Stop,
1196
1215
  e,
1197
1216
  r,
1198
1217
  o.streamType
@@ -1205,9 +1224,9 @@ function Le(e, t, r, a) {
1205
1224
  const l = Te.get(!0);
1206
1225
  r.track("agent-chat", { event: "ready", latency: l });
1207
1226
  },
1208
- onToolEvent: (l, w) => {
1209
- var v, k;
1210
- (k = (v = t.callbacks).onToolEvent) == null || k.call(v, l, w), nr(l, w, r);
1227
+ onToolEvent: (l, p) => {
1228
+ var w, C;
1229
+ (C = (w = t.callbacks).onToolEvent) == null || C.call(w, l, p), nr(l, p, r);
1211
1230
  }
1212
1231
  }
1213
1232
  },
@@ -1219,10 +1238,10 @@ function Le(e, t, r, a) {
1219
1238
  });
1220
1239
  }
1221
1240
  async function ar(e, t, r, a, c) {
1222
- var m, l, w, v;
1241
+ var m, l, p, w;
1223
1242
  const s = async () => {
1224
- if (pe(e.presenter.type)) {
1225
- const k = await Le(e, t, a), B = `${Xt}_${k.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
1243
+ if (he(e.presenter.type)) {
1244
+ const C = await Pe(e, t, a), B = `${Xt}_${C.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
1226
1245
  return { chatResult: {
1227
1246
  chatMode: x.Functional,
1228
1247
  chat: {
@@ -1236,35 +1255,35 @@ async function ar(e, t, r, a, c) {
1236
1255
  chat_mode: x.Functional,
1237
1256
  messages: []
1238
1257
  }
1239
- }, streamingManager: k };
1258
+ }, streamingManager: C };
1240
1259
  } else {
1241
- const k = new AbortController(), B = k.signal;
1260
+ const C = new AbortController(), B = C.signal;
1242
1261
  let M;
1243
1262
  try {
1244
- const D = Ve(
1263
+ const D = Ke(
1245
1264
  e,
1246
1265
  r,
1247
1266
  a,
1248
1267
  t.mode,
1249
1268
  t.persistentChat,
1250
1269
  c
1251
- ), $ = Le(e, t, a, B).then((J) => (M = J, J)), [_, q] = await Promise.all([D, $]);
1270
+ ), $ = Pe(e, t, a, B).then((J) => (M = J, J)), [_, q] = await Promise.all([D, $]);
1252
1271
  return { chatResult: _, streamingManager: q };
1253
1272
  } catch (D) {
1254
- throw k.abort(), M && await M.disconnect().catch(() => {
1273
+ throw C.abort(), M && await M.disconnect().catch(() => {
1255
1274
  }), D;
1256
1275
  }
1257
1276
  }
1258
1277
  }, { chatResult: o, streamingManager: n } = await s(), { chat: i, chatMode: d } = o;
1259
- return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (l = (m = t.callbacks).onModeChange) == null || l.call(m, d), d !== x.Functional) ? ((v = (w = t.callbacks).onError) == null || v.call(w, new He(d)), n == null || n.disconnect(), { chat: i }) : { chat: i, streamingManager: n };
1278
+ return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (l = (m = t.callbacks).onModeChange) == null || l.call(m, d), d !== x.Functional) ? ((w = (p = t.callbacks).onError) == null || w.call(p, new qe(d)), n == null || n.disconnect(), { chat: i }) : { chat: i, streamingManager: n };
1260
1279
  }
1261
1280
  async function dr(e, t) {
1262
- var Y, V, ae, ie;
1281
+ var Y, K, ae, ie;
1263
1282
  let r = !0;
1264
- const a = t.mixpanelKey || ot, c = t.wsURL || st, s = t.baseURL || de, o = t.mode || x.Functional, n = {
1283
+ const a = t.mixpanelKey || ct, c = t.wsURL || ot, s = t.baseURL || de, o = t.mode || x.Functional, n = {
1265
1284
  messages: [],
1266
1285
  chatMode: o
1267
- }, i = Rt({
1286
+ }, i = Dt({
1268
1287
  token: a,
1269
1288
  agentId: e,
1270
1289
  isEnabled: t.enableAnalitics,
@@ -1274,66 +1293,66 @@ async function dr(e, t) {
1274
1293
  Ee(() => {
1275
1294
  i.track("agent-sdk", { event: "init" }, d);
1276
1295
  });
1277
- const m = wt(t.auth, s, t.callbacks.onError, t.externalId), l = await m.getById(e);
1296
+ const m = vt(t.auth, s, t.callbacks.onError, t.externalId), l = await m.getById(e);
1278
1297
  t.debug = t.debug || ((Y = l == null ? void 0 : l.advanced_settings) == null ? void 0 : Y.ui_debug_mode);
1279
- const w = pe(l.presenter.type);
1280
- i.enrich(yt(l));
1281
- const { onMessage: v, clearQueue: k } = xt(i, n, t, l, () => {
1282
- var u, g, p;
1283
- (u = n.socketManager) == null || u.disconnect(), (p = (g = t.callbacks).onConnectionStateChange) == null || p.call(g, L.Disconnected);
1298
+ const p = he(l.presenter.type);
1299
+ i.enrich(Ct(l));
1300
+ const { onMessage: w, clearQueue: C } = xt(i, n, t, l, () => {
1301
+ var u, g, v;
1302
+ (u = n.socketManager) == null || u.disconnect(), (v = (g = t.callbacks).onConnectionStateChange) == null || v.call(g, L.Disconnected);
1284
1303
  });
1285
- n.messages = It(t.initialMessages), (ae = (V = t.callbacks).onNewMessage) == null || ae.call(V, [...n.messages], "answer");
1304
+ n.messages = Mt(t.initialMessages), (ae = (K = t.callbacks).onNewMessage) == null || ae.call(K, [...n.messages], "answer");
1286
1305
  const B = (u) => {
1287
1306
  }, M = ({ type: u }) => {
1288
- var p, y, C, R;
1289
- if (!((p = n.streamingManager) != null && p.interruptAvailable) || !((y = n.streamingManager) != null && y.isInterruptible)) return;
1307
+ var v, y, S, R;
1308
+ if (!((v = n.streamingManager) != null && v.interruptAvailable) || !((y = n.streamingManager) != null && y.isInterruptible)) return;
1290
1309
  const g = n.messages[n.messages.length - 1];
1291
1310
  i.track("agent-video-interrupt", {
1292
1311
  type: u || "click",
1293
1312
  video_duration_to_interrupt: fe.get(!0),
1294
1313
  message_duration_to_interrupt: H.get(!0)
1295
- }), g.interrupted = !0, (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "answer"), n.streamingManager.interrupt(u);
1314
+ }), g.interrupted = !0, (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...n.messages], "answer"), n.streamingManager.interrupt(u);
1296
1315
  }, D = /* @__PURE__ */ new Map();
1297
1316
  function $(u) {
1298
1317
  return async (g) => {
1299
- const p = D.get(u);
1300
- if (!p)
1318
+ const v = D.get(u);
1319
+ if (!v)
1301
1320
  throw new Error(`No handler registered for client tool: ${u}`);
1302
1321
  try {
1303
1322
  const y = JSON.parse(g.payload);
1304
- return await p(y);
1323
+ return await v(y);
1305
1324
  } catch (y) {
1306
1325
  throw new Error(`Client tool "${u}" failed: ${y.message}`);
1307
1326
  }
1308
1327
  };
1309
1328
  }
1310
1329
  function _() {
1311
- var u, g, p, y;
1312
- for (const [C] of D)
1313
- (g = (u = n.streamingManager) == null ? void 0 : u.unregisterRpcMethod) == null || g.call(u, C), (y = (p = n.streamingManager) == null ? void 0 : p.registerRpcMethod) == null || y.call(p, C, $(C));
1330
+ var u, g, v, y;
1331
+ for (const [S] of D)
1332
+ (g = (u = n.streamingManager) == null ? void 0 : u.unregisterRpcMethod) == null || g.call(u, S), (y = (v = n.streamingManager) == null ? void 0 : v.registerRpcMethod) == null || y.call(v, S, $(S));
1314
1333
  }
1315
1334
  function q(u, g) {
1316
- var y, C;
1317
- const p = !D.has(u);
1318
- D.set(u, g), p && ((C = (y = n.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || C.call(y, u, $(u)));
1335
+ var y, S;
1336
+ const v = !D.has(u);
1337
+ D.set(u, g), v && ((S = (y = n.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || S.call(y, u, $(u)));
1319
1338
  }
1320
1339
  function J(u) {
1321
- var g, p;
1322
- D.delete(u), (p = (g = n.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || p.call(g, u);
1340
+ var g, v;
1341
+ D.delete(u), (v = (g = n.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || v.call(g, u);
1323
1342
  }
1324
- const N = Date.now();
1343
+ const V = Date.now();
1325
1344
  Ee(() => {
1326
- i.track("agent-sdk", { event: "loaded", ...vt(l) }, N);
1345
+ i.track("agent-sdk", { event: "loaded", ...yt(l) }, V);
1327
1346
  });
1328
1347
  async function X(u) {
1329
1348
  var j, z, F, E, f, h, b;
1330
1349
  (z = (j = t.callbacks).onConnectionStateChange) == null || z.call(j, L.Connecting), H.reset(), u && !r && (delete n.chat, (E = (F = t.callbacks).onNewMessage) == null || E.call(F, [...n.messages], "answer"));
1331
- const g = o === x.DirectPlayback || w ? Promise.resolve(void 0) : Tt(
1350
+ const g = o === x.DirectPlayback || p ? Promise.resolve(void 0) : _t(
1332
1351
  t.auth,
1333
1352
  c,
1334
- { onMessage: v, onError: t.callbacks.onError },
1353
+ { onMessage: w, onError: t.callbacks.onError },
1335
1354
  t.externalId
1336
- ), p = ue(
1355
+ ), v = ue(
1337
1356
  () => ar(
1338
1357
  l,
1339
1358
  {
@@ -1342,7 +1361,7 @@ async function dr(e, t) {
1342
1361
  callbacks: {
1343
1362
  ...t.callbacks,
1344
1363
  onVideoIdChange: B,
1345
- onMessage: v
1364
+ onMessage: w
1346
1365
  }
1347
1366
  },
1348
1367
  m,
@@ -1351,28 +1370,28 @@ async function dr(e, t) {
1351
1370
  ),
1352
1371
  {
1353
1372
  limit: 3,
1354
- timeout: at,
1373
+ timeout: it,
1355
1374
  timeoutErrorMessage: "Timeout initializing the stream",
1356
1375
  shouldRetryFn: (T) => (T == null ? void 0 : T.message) !== "Could not connect" && T.status !== 429 && (T == null ? void 0 : T.message) !== "InsufficientCreditsError",
1357
1376
  delayMs: 1e3
1358
1377
  }
1359
1378
  ).catch((T) => {
1360
- var A, K;
1361
- throw I(x.Maintenance), (K = (A = t.callbacks).onConnectionStateChange) == null || K.call(A, L.Fail), T;
1362
- }), [y, { streamingManager: C, chat: R }] = await Promise.all([g, p]);
1363
- R && R.id !== ((f = n.chat) == null ? void 0 : f.id) && ((b = (h = t.callbacks).onNewChat) == null || b.call(h, R.id)), n.streamingManager = C, n.socketManager = y, n.chat = R, _(), r = !1, i.enrich({
1379
+ var A, U;
1380
+ throw I(x.Maintenance), (U = (A = t.callbacks).onConnectionStateChange) == null || U.call(A, L.Fail), T;
1381
+ }), [y, { streamingManager: S, chat: R }] = await Promise.all([g, v]);
1382
+ R && R.id !== ((f = n.chat) == null ? void 0 : f.id) && ((b = (h = t.callbacks).onNewChat) == null || b.call(h, R.id)), n.streamingManager = S, n.socketManager = y, n.chat = R, _(), r = !1, i.enrich({
1364
1383
  chatId: R == null ? void 0 : R.id,
1365
- streamId: C == null ? void 0 : C.streamId,
1384
+ streamId: S == null ? void 0 : S.streamId,
1366
1385
  mode: n.chatMode
1367
1386
  }), I((R == null ? void 0 : R.chat_mode) ?? o);
1368
1387
  }
1369
1388
  async function O() {
1370
- var u, g, p, y;
1371
- (u = n.socketManager) == null || u.disconnect(), await ((g = n.streamingManager) == null ? void 0 : g.disconnect()), delete n.streamingManager, delete n.socketManager, (y = (p = t.callbacks).onConnectionStateChange) == null || y.call(p, L.Disconnected);
1389
+ var u, g, v, y;
1390
+ (u = n.socketManager) == null || u.disconnect(), await ((g = n.streamingManager) == null ? void 0 : g.disconnect()), delete n.streamingManager, delete n.socketManager, (y = (v = t.callbacks).onConnectionStateChange) == null || y.call(v, L.Disconnected);
1372
1391
  }
1373
1392
  async function I(u) {
1374
- var g, p;
1375
- u !== n.chatMode && (i.track("agent-mode-change", { mode: u }), n.chatMode = u, n.chatMode !== x.Functional && await O(), (p = (g = t.callbacks).onModeChange) == null || p.call(g, u));
1393
+ var g, v;
1394
+ u !== n.chatMode && (i.track("agent-mode-change", { mode: u }), n.chatMode = u, n.chatMode !== x.Functional && await O(), (v = (g = t.callbacks).onModeChange) == null || v.call(g, u));
1376
1395
  }
1377
1396
  return {
1378
1397
  agent: l,
@@ -1396,7 +1415,7 @@ async function dr(e, t) {
1396
1415
  },
1397
1416
  async reconnect() {
1398
1417
  const u = n.streamingManager;
1399
- if (w && (u != null && u.reconnect)) {
1418
+ if (p && (u != null && u.reconnect)) {
1400
1419
  try {
1401
1420
  await u.reconnect(), i.track("agent-chat", {
1402
1421
  event: "reconnect",
@@ -1439,9 +1458,9 @@ async function dr(e, t) {
1439
1458
  return (u = n.streamingManager) != null && u.unpublishCameraStream ? n.streamingManager.unpublishCameraStream() : Promise.resolve();
1440
1459
  },
1441
1460
  async chat(u) {
1442
- var C, R, j, z, F;
1461
+ var S, R, j, z, F;
1443
1462
  const g = () => {
1444
- if ($e(o))
1463
+ if (ze(o))
1445
1464
  throw new G(`${o} is enabled, chat is disabled`);
1446
1465
  if (u.length >= 800)
1447
1466
  throw new G("Message cannot be more than 800 characters");
@@ -1455,10 +1474,10 @@ async function dr(e, t) {
1455
1474
  if (!n.chat)
1456
1475
  throw new G("Chat is not initialized");
1457
1476
  }
1458
- }, p = async () => {
1477
+ }, v = async () => {
1459
1478
  var E, f;
1460
1479
  if (!n.chat) {
1461
- const h = await Ve(
1480
+ const h = await Ke(
1462
1481
  l,
1463
1482
  m,
1464
1483
  i,
@@ -1466,28 +1485,28 @@ async function dr(e, t) {
1466
1485
  t.persistentChat
1467
1486
  );
1468
1487
  if (!h.chat)
1469
- throw new Oe(n.chatMode, !!t.persistentChat);
1488
+ throw new He(n.chatMode, !!t.persistentChat);
1470
1489
  n.chat = h.chat, (f = (E = t.callbacks).onNewChat) == null || f.call(E, n.chat.id);
1471
1490
  }
1472
1491
  return n.chat.id;
1473
1492
  }, y = async (E, f) => {
1474
1493
  const h = n.chatMode === x.Playground;
1475
- return ue(w && !h ? async () => {
1476
- var A, K;
1477
- return await ((K = (A = n.streamingManager) == null ? void 0 : A.sendTextMessage) == null ? void 0 : K.call(A, u)), Promise.resolve({});
1494
+ return ue(p && !h ? async () => {
1495
+ var A, U;
1496
+ return await ((U = (A = n.streamingManager) == null ? void 0 : A.sendTextMessage) == null ? void 0 : U.call(A, u)), Promise.resolve({});
1478
1497
  } : async () => {
1479
- var A, K;
1498
+ var A, U;
1480
1499
  return m.chat(
1481
1500
  l.id,
1482
1501
  f,
1483
1502
  {
1484
1503
  chatMode: n.chatMode,
1485
1504
  streamId: (A = n.streamingManager) == null ? void 0 : A.streamId,
1486
- sessionId: (K = n.streamingManager) == null ? void 0 : K.sessionId,
1487
- messages: E.map(({ matches: Ue, ...se }) => se)
1505
+ sessionId: (U = n.streamingManager) == null ? void 0 : U.sessionId,
1506
+ messages: E.map(({ matches: We, ...se }) => se)
1488
1507
  },
1489
1508
  {
1490
- ...Ne(n.chatMode),
1509
+ ...Ve(n.chatMode),
1491
1510
  skipErrorHandler: !0
1492
1511
  }
1493
1512
  );
@@ -1495,8 +1514,8 @@ async function dr(e, t) {
1495
1514
  limit: 2,
1496
1515
  shouldRetryFn: (A) => {
1497
1516
  var se, ve, ye, Ce;
1498
- const K = (se = A == null ? void 0 : A.message) == null ? void 0 : se.includes("missing or invalid session_id");
1499
- return !((ve = A == null ? void 0 : A.message) == null ? void 0 : ve.includes("Stream Error")) && !K ? ((Ce = (ye = t.callbacks).onError) == null || Ce.call(ye, A), !1) : !0;
1517
+ const U = (se = A == null ? void 0 : A.message) == null ? void 0 : se.includes("missing or invalid session_id");
1518
+ return !((ve = A == null ? void 0 : A.message) == null ? void 0 : ve.includes("Stream Error")) && !U ? ((Ce = (ye = t.callbacks).onError) == null || Ce.call(ye, A), !1) : !0;
1500
1519
  },
1501
1520
  onRetry: async () => {
1502
1521
  await O(), await X(!1);
@@ -1504,19 +1523,19 @@ async function dr(e, t) {
1504
1523
  });
1505
1524
  };
1506
1525
  try {
1507
- k(), g(), n.messages.push({
1526
+ C(), g(), n.messages.push({
1508
1527
  id: Q(),
1509
1528
  role: "user",
1510
1529
  content: u,
1511
1530
  parts: re(u),
1512
1531
  created_at: new Date(H.update()).toISOString()
1513
- }), (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "user");
1514
- const E = await p(), f = await y([...n.messages], E);
1515
- return n.messages.push({
1532
+ }), (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...n.messages], "user");
1533
+ const E = await v(), f = await y([...n.messages], E);
1534
+ return f.result && n.messages.push({
1516
1535
  id: Q(),
1517
1536
  role: "assistant",
1518
- content: f.result || "",
1519
- parts: re(f.result || ""),
1537
+ content: f.result,
1538
+ parts: re(f.result),
1520
1539
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1521
1540
  context: f.context,
1522
1541
  matches: f.matches
@@ -1534,29 +1553,29 @@ async function dr(e, t) {
1534
1553
  }), E;
1535
1554
  }
1536
1555
  },
1537
- rate(u, g, p) {
1556
+ rate(u, g, v) {
1538
1557
  var R, j, z, F;
1539
1558
  const y = n.messages.find((E) => E.id === u);
1540
1559
  if (n.chat) {
1541
1560
  if (!y)
1542
1561
  throw new Error("Message not found");
1543
1562
  } else throw new Error("Chat is not initialized");
1544
- const C = ((R = y.matches) == null ? void 0 : R.map((E) => [E.document_id, E.id])) ?? [];
1563
+ const S = ((R = y.matches) == null ? void 0 : R.map((E) => [E.document_id, E.id])) ?? [];
1545
1564
  return i.track("agent-rate", {
1546
- event: p ? "update" : "create",
1565
+ event: v ? "update" : "create",
1547
1566
  thumb: g === 1 ? "up" : "down",
1548
1567
  knowledge_id: ((j = l.knowledge) == null ? void 0 : j.id) ?? "",
1549
- matches: C,
1568
+ matches: S,
1550
1569
  score: g
1551
- }), p ? m.updateRating(l.id, n.chat.id, p, {
1570
+ }), v ? m.updateRating(l.id, n.chat.id, v, {
1552
1571
  knowledge_id: ((z = l.knowledge) == null ? void 0 : z.id) ?? "",
1553
1572
  message_id: u,
1554
- matches: C,
1573
+ matches: S,
1555
1574
  score: g
1556
1575
  }) : m.createRating(l.id, n.chat.id, {
1557
1576
  knowledge_id: ((F = l.knowledge) == null ? void 0 : F.id) ?? "",
1558
1577
  message_id: u,
1559
- matches: C,
1578
+ matches: S,
1560
1579
  score: g
1561
1580
  });
1562
1581
  },
@@ -1566,7 +1585,7 @@ async function dr(e, t) {
1566
1585
  return i.track("agent-rate-delete", { type: "text" }), m.deleteRating(l.id, n.chat.id, u);
1567
1586
  },
1568
1587
  async speak(u) {
1569
- var C, R, j;
1588
+ var S, R, j;
1570
1589
  function g() {
1571
1590
  if (typeof u == "string") {
1572
1591
  if (!l.presenter.voice)
@@ -1590,14 +1609,14 @@ async function dr(e, t) {
1590
1609
  }
1591
1610
  return u;
1592
1611
  }
1593
- const p = g();
1594
- if (i.track("agent-speak", p), H.update(), n.messages && p.type === "text" && (n.messages.push({
1612
+ const v = g();
1613
+ if (i.track("agent-speak", v), H.update(), n.messages && v.type === "text" && (n.messages.push({
1595
1614
  id: Q(),
1596
1615
  role: "assistant",
1597
- content: p.input,
1598
- parts: re(p.input),
1616
+ content: v.input,
1617
+ parts: re(v.input),
1599
1618
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1600
- }), (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "answer")), lt(n.chatMode))
1619
+ }), (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...n.messages], "answer")), ut(n.chatMode))
1601
1620
  return {
1602
1621
  duration: 0,
1603
1622
  video_id: "",
@@ -1606,7 +1625,7 @@ async function dr(e, t) {
1606
1625
  if (!n.streamingManager)
1607
1626
  throw new Error("Please connect to the agent first");
1608
1627
  return n.streamingManager.speak({
1609
- script: p,
1628
+ script: v,
1610
1629
  metadata: { chat_id: (j = n.chat) == null ? void 0 : j.id, agent_id: l.id }
1611
1630
  });
1612
1631
  },
@@ -1617,36 +1636,36 @@ async function dr(e, t) {
1617
1636
  }
1618
1637
  export {
1619
1638
  ne as A,
1620
- U as C,
1621
- tt as D,
1622
- et as K,
1623
- Ye as P,
1624
- Qe as R,
1639
+ N as C,
1640
+ rt as D,
1641
+ tt as K,
1642
+ Ge as P,
1643
+ Ze as R,
1625
1644
  P as S,
1626
- he as T,
1627
- Xe as U,
1645
+ pe as T,
1646
+ Ye as U,
1628
1647
  G as V,
1629
- qe as W,
1648
+ Xe as W,
1630
1649
  Pt as a,
1631
1650
  W as b,
1632
- Fe as c,
1651
+ Ne as c,
1633
1652
  de as d,
1634
1653
  L as e,
1635
1654
  te as f,
1636
1655
  Kt as g,
1637
1656
  cr as h,
1638
- S as i,
1639
- Oe as j,
1640
- He as k,
1657
+ k as i,
1658
+ He as j,
1659
+ qe as k,
1641
1660
  H as l,
1642
1661
  dr as m,
1643
1662
  or as n,
1644
- Ge as o,
1645
- ft as p,
1663
+ Qe as o,
1664
+ gt as p,
1646
1665
  x as q,
1647
- Ze as r,
1648
- Pe as s,
1666
+ et as r,
1667
+ je as s,
1649
1668
  sr as t,
1650
- rt as u,
1651
- nt as v
1669
+ nt as u,
1670
+ at as v
1652
1671
  };