@d-id/client-sdk 1.2.10 → 2.0.0-staging.377

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,7 +1,7 @@
1
- var it = Object.defineProperty;
2
- var st = (e, t, n) => t in e ? it(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var K = (e, t, n) => st(e, typeof t != "symbol" ? t + "" : t, n);
4
- class G extends Error {
1
+ var at = Object.defineProperty;
2
+ var it = (e, t, n) => t in e ? at(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var O = (e, t, n) => it(e, typeof t != "symbol" ? t + "" : t, n);
4
+ class X extends Error {
5
5
  constructor(t, n = "Error", i) {
6
6
  super(t), this.kind = n, this.originalError = i, Object.setPrototypeOf(this, new.target.prototype);
7
7
  }
@@ -14,20 +14,20 @@ class G extends Error {
14
14
  };
15
15
  }
16
16
  }
17
- function Tn(e) {
17
+ function Dn(e) {
18
18
  return e instanceof Error && typeof e.kind == "string";
19
19
  }
20
- class ot extends G {
20
+ class st extends X {
21
21
  constructor(t, n) {
22
22
  super(`Failed to create ${n ? "persistent" : ""} chat, mode: ${t}`, "ChatCreationFailed");
23
23
  }
24
24
  }
25
- class ct extends G {
25
+ class ot extends X {
26
26
  constructor(t) {
27
27
  super(`Chat mode downgraded to ${t}`, "ChatModeDowngraded");
28
28
  }
29
29
  }
30
- function dt(e) {
30
+ function ct(e) {
31
31
  try {
32
32
  const t = JSON.parse(e);
33
33
  if (t && typeof t == "object" && typeof t.kind == "string")
@@ -35,13 +35,13 @@ function dt(e) {
35
35
  } catch {
36
36
  }
37
37
  }
38
- class Ke extends G {
38
+ class Ke extends X {
39
39
  constructor(n, i, c = {}) {
40
- const o = dt(i);
40
+ const o = ct(i);
41
41
  super(((o == null ? void 0 : o.description) ?? i).slice(0, 256), (o == null ? void 0 : o.kind) ?? "HttpError");
42
- K(this, "status");
43
- K(this, "url");
44
- K(this, "method");
42
+ O(this, "status");
43
+ O(this, "url");
44
+ O(this, "method");
45
45
  this.status = n, this.url = c.url, this.method = c.method;
46
46
  }
47
47
  toJson() {
@@ -53,14 +53,14 @@ class Ke extends G {
53
53
  };
54
54
  }
55
55
  }
56
- class lt extends G {
56
+ class dt extends X {
57
57
  constructor(n, i = {}) {
58
58
  super("Network request failed", "NetworkError", n);
59
- K(this, "endpoint");
60
- K(this, "method");
61
- K(this, "durationMs");
62
- K(this, "online");
63
- K(this, "visibility");
59
+ O(this, "endpoint");
60
+ O(this, "method");
61
+ O(this, "durationMs");
62
+ O(this, "online");
63
+ O(this, "visibility");
64
64
  this.endpoint = i.url, this.method = i.method, this.durationMs = i.durationMs, this.online = i.online, this.visibility = i.visibility;
65
65
  }
66
66
  toJson() {
@@ -74,23 +74,23 @@ class lt extends G {
74
74
  };
75
75
  }
76
76
  }
77
- class We extends G {
77
+ class Oe extends X {
78
78
  constructor(t, n) {
79
79
  super(t, "StreamError", n);
80
80
  }
81
81
  }
82
- class $ extends G {
82
+ class U extends X {
83
83
  constructor(t, n) {
84
84
  super(t, "ValidationError"), this.key = n;
85
85
  }
86
86
  }
87
- class ut extends G {
87
+ class lt extends X {
88
88
  constructor(t) {
89
89
  super(t, "WSError");
90
90
  }
91
91
  }
92
- var ft = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(ft || {}), mt = /* @__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))(mt || {}), ht = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(ht || {}), gt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(gt || {}), T = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(T || {}), F = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(F || {}), pt = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(pt || {}), wt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(wt || {}), yt = /* @__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))(yt || {}), He = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(He || {});
93
- const An = (e) => {
92
+ var ut = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(ut || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), z = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(z || {}), ft = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(ft || {}), mt = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(mt || {}), gt = /* @__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))(gt || {}), We = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(We || {});
93
+ const In = (e) => {
94
94
  switch (e) {
95
95
  case "clip":
96
96
  return "clip";
@@ -102,13 +102,13 @@ const An = (e) => {
102
102
  throw new Error(`Unknown video type: ${e}`);
103
103
  }
104
104
  };
105
- var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), ie = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ie || {}), x = /* @__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))(x || {}), A = /* @__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))(A || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), Se = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Se || {}), vt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(vt || {}), kt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(kt || {});
106
- const xn = (...e) => {
107
- }, qe = (e) => new Promise((t) => setTimeout(t, e)), ee = (e = 16) => {
105
+ var k = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(k || {}), ne = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ne || {}), ae = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ae || {}), L = /* @__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))(L || {}), P = /* @__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))(P || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), Se = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(Se || {}), ht = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(ht || {}), pt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(pt || {});
106
+ const En = (...e) => {
107
+ }, He = (e) => new Promise((t) => setTimeout(t, e)), ee = (e = 16) => {
108
108
  const t = new Uint8Array(e);
109
109
  return window.crypto.getRandomValues(t), Array.from(t, (n) => n.toString(16).padStart(2, "0")).join("").slice(0, 13);
110
110
  };
111
- function we(e) {
111
+ function pe(e) {
112
112
  if (e !== void 0)
113
113
  return window.localStorage.setItem("did_external_key_id", e), e;
114
114
  let t = window.localStorage.getItem("did_external_key_id");
@@ -118,20 +118,20 @@ function we(e) {
118
118
  }
119
119
  return t;
120
120
  }
121
- let ue = ee();
122
- function Ct() {
123
- ue = ee();
121
+ let le = ee();
122
+ function wt() {
123
+ le = ee();
124
124
  }
125
- function Xe(e, t) {
125
+ function qe(e, t) {
126
126
  if (e.type === "bearer")
127
- return `Bearer ${e.token}~${ue}`;
127
+ return `Bearer ${e.token}~${le}`;
128
128
  if (e.type === "basic")
129
- return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}~${ue}`;
129
+ return `Basic ${"token" in e ? e.token : btoa(`${e.username}:${e.password}`)}~${le}`;
130
130
  if (e.type === "key")
131
- return `Client-Key ${e.clientKey}.${we(t)}_${ue}`;
131
+ return `Client-Key ${e.clientKey}.${pe(t)}_${le}`;
132
132
  throw new Error(`Unknown auth type: ${e}`);
133
133
  }
134
- const St = 45 * 1e3, Mt = "X-Playground-Chat", be = 2e3, me = "https://api.d-id.com", Rt = "wss://notifications.d-id.com", Dt = "79f81a83a67430be2bc0fd61042b8faa", Ge = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, It = (e) => {
134
+ const yt = 45 * 1e3, vt = "X-Playground-Chat", Ee = 2e3, fe = "https://api.d-id.com", Ct = "wss://notifications.d-id.com", St = "79f81a83a67430be2bc0fd61042b8faa", Ge = (e) => e.type, kt = (e) => {
135
135
  switch (e.type) {
136
136
  case "expressive":
137
137
  return "v4";
@@ -140,18 +140,18 @@ const St = 45 * 1e3, Mt = "X-Playground-Chat", be = 2e3, me = "https://api.d-id.
140
140
  case "talk":
141
141
  return "v2";
142
142
  }
143
- }, Et = (e) => e.type === "talk" ? e.source_url : e.presenter_id, Me = (e) => e === He.Expressive, bt = (e) => [T.TextOnly, T.Playground, T.Maintenance].includes(e), Qe = (e) => e && [T.DirectPlayback, T.Off].includes(e), _e = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, Te = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, _t = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
144
- function Tt(e) {
143
+ }, ke = (e) => e === We.Expressive, Mt = (e) => [x.TextOnly, x.Playground, x.Maintenance].includes(e), Xe = (e) => e && [x.DirectPlayback, x.Off].includes(e), be = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, Te = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, Rt = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
144
+ function Dt(e) {
145
145
  const t = e.split("?")[0].split("#")[0].toLowerCase();
146
- return _t.some((n) => t.endsWith(n));
146
+ return Rt.some((n) => t.endsWith(n));
147
147
  }
148
- const Ae = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), xe = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
149
- function At(e) {
148
+ const _e = new RegExp("(?<!!)\\[([^\\[\\]]+)\\]\\(([^)\\s]+)\\)", "g"), Ae = /<a\s+href="([^"]*)"[^>]*?>([^<]*)<\/a>/gi;
149
+ function It(e) {
150
150
  if (e.length === 0)
151
151
  return [];
152
152
  const t = [];
153
153
  let n;
154
- for (_e.lastIndex = 0; (n = _e.exec(e)) !== null; )
154
+ for (be.lastIndex = 0; (n = be.exec(e)) !== null; )
155
155
  t.push({
156
156
  index: n.index,
157
157
  length: n[0].length,
@@ -161,15 +161,15 @@ function At(e) {
161
161
  if (!t.some((s) => n.index >= s.index && n.index < s.index + s.length)) {
162
162
  const s = n[2], r = n[1];
163
163
  let a;
164
- Tt(s) ? a = { type: "video", src: s, alt: r } : (a = { type: "image", src: s, alt: r }, s.toLowerCase().endsWith(".gif") && (a.mimeType = "image/gif")), t.push({ index: n.index, length: n[0].length, part: a });
164
+ Dt(s) ? a = { type: "video", src: s, alt: r } : (a = { type: "image", src: s, alt: r }, s.toLowerCase().endsWith(".gif") && (a.mimeType = "image/gif")), t.push({ index: n.index, length: n[0].length, part: a });
165
165
  }
166
- for (Ae.lastIndex = 0; (n = Ae.exec(e)) !== null; )
166
+ for (_e.lastIndex = 0; (n = _e.exec(e)) !== null; )
167
167
  t.some((s) => n.index >= s.index && n.index < s.index + s.length) || t.push({
168
168
  index: n.index,
169
169
  length: n[0].length,
170
170
  part: { type: "link", href: n[2], label: n[1] }
171
171
  });
172
- for (xe.lastIndex = 0; (n = xe.exec(e)) !== null; )
172
+ for (Ae.lastIndex = 0; (n = Ae.exec(e)) !== null; )
173
173
  t.some((s) => n.index >= s.index && n.index < s.index + s.length) || t.push({
174
174
  index: n.index,
175
175
  length: n[0].length,
@@ -184,11 +184,11 @@ function At(e) {
184
184
  o.index > c && i.push({ type: "text", text: e.slice(c, o.index) }), i.push(o.part), c = o.index + o.length;
185
185
  return c < e.length && i.push({ type: "text", text: e.slice(c) }), i;
186
186
  }
187
- let Pe = "", he = [];
188
- function ae(e) {
189
- return e === Pe || (Pe = e, he = At(e)), he;
187
+ let xe = "", me = [];
188
+ function re(e) {
189
+ return e === xe || (xe = e, me = It(e)), me;
190
190
  }
191
- function xt(e, t) {
191
+ function Et(e, t) {
192
192
  let n;
193
193
  return {
194
194
  promise: new Promise((c, o) => {
@@ -197,7 +197,7 @@ function xt(e, t) {
197
197
  clear: () => clearTimeout(n)
198
198
  };
199
199
  }
200
- async function ye(e, t) {
200
+ async function we(e, t) {
201
201
  const n = {
202
202
  limit: (t == null ? void 0 : t.limit) ?? 3,
203
203
  delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
@@ -212,32 +212,32 @@ async function ye(e, t) {
212
212
  try {
213
213
  if (!n.timeout)
214
214
  return await e();
215
- const { promise: o, clear: s } = xt(n.timeout, n.timeoutErrorMessage), r = e().finally(s);
215
+ const { promise: o, clear: s } = Et(n.timeout, n.timeoutErrorMessage), r = e().finally(s);
216
216
  return await Promise.race([r, o]);
217
217
  } catch (o) {
218
218
  if (i = o, !n.shouldRetryFn(o) || c >= n.limit)
219
219
  throw o;
220
- await qe(n.delayMs), n.onRetry(o);
220
+ await He(n.delayMs), n.onRetry(o);
221
221
  }
222
222
  throw i;
223
223
  }
224
- const Pt = (e) => ye(e, {
224
+ const bt = (e) => we(e, {
225
225
  limit: 3,
226
226
  delayMs: 1e3,
227
227
  timeout: 0,
228
228
  shouldRetryFn: (t) => t.status === 429
229
229
  });
230
- function Ye(e, t = me, n, i) {
230
+ function Qe(e, t = fe, n, i) {
231
231
  const c = async (o, s) => {
232
232
  const { skipErrorHandler: r, ...a } = s || {}, d = a.method ?? "GET", m = performance.now();
233
233
  let u;
234
234
  try {
235
- u = await Pt(
235
+ u = await bt(
236
236
  () => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
237
237
  ...a,
238
238
  headers: {
239
239
  ...a.headers,
240
- Authorization: Xe(e, i),
240
+ Authorization: qe(e, i),
241
241
  "Content-Type": "application/json"
242
242
  }
243
243
  })
@@ -245,7 +245,7 @@ function Ye(e, t = me, n, i) {
245
245
  } catch (f) {
246
246
  if ((f == null ? void 0 : f.name) === "AbortError")
247
247
  throw f;
248
- const v = new lt(f, {
248
+ const v = new dt(f, {
249
249
  url: o,
250
250
  method: d,
251
251
  durationMs: Math.round(performance.now() - m),
@@ -255,8 +255,8 @@ function Ye(e, t = me, n, i) {
255
255
  throw r || n == null || n(v, { url: o, options: a }), v;
256
256
  }
257
257
  if (!u.ok) {
258
- const f = await u.text().catch(() => `Failed to fetch with status ${u.status}`), w = new Ke(u.status, f, { url: o, method: d });
259
- throw r || n == null || n(w, { url: o, options: a, headers: u.headers }), w;
258
+ const f = await u.text().catch(() => `Failed to fetch with status ${u.status}`), p = new Ke(u.status, f, { url: o, method: d });
259
+ throw r || n == null || n(p, { url: o, options: a, headers: u.headers }), p;
260
260
  }
261
261
  return u.json();
262
262
  };
@@ -275,23 +275,11 @@ function Ye(e, t = me, n, i) {
275
275
  }
276
276
  };
277
277
  }
278
- function Lt(e, t = me, n, i) {
279
- const c = Ye(e, `${t}/agents`, n, i);
278
+ function Tt(e, t = fe, n, i) {
279
+ const c = Qe(e, `${t}/agents`, n, i);
280
280
  return {
281
- create(o, s) {
282
- return c.post("/", o, s);
283
- },
284
- getAgents(o, s) {
285
- return c.get(`/${o ? `?tag=${o}` : ""}`, s).then((r) => r ?? []);
286
- },
287
- getById(o, s) {
288
- return c.get(`/${o}`, s);
289
- },
290
- delete(o, s) {
291
- return c.delete(`/${o}`, void 0, s);
292
- },
293
- update(o, s, r) {
294
- return c.patch(`/${o}`, s, r);
281
+ getRuntimeById(o, s) {
282
+ return c.get(`/${o}/runtime`, s);
295
283
  },
296
284
  newChat(o, s, r) {
297
285
  return c.post(`/${o}/chat`, s, r);
@@ -316,12 +304,12 @@ function Lt(e, t = me, n, i) {
316
304
  }
317
305
  };
318
306
  }
319
- function jt(e) {
320
- var c, o, s, r;
307
+ function _t(e) {
308
+ var c, o;
321
309
  const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", n = () => {
322
- const a = navigator.platform;
323
- return a.toLowerCase().includes("win") ? "Windows" : a.toLowerCase().includes("mac") ? "Mac OS X" : a.toLowerCase().includes("linux") ? "Linux" : "Unknown";
324
- }, i = e.presenter;
310
+ const s = navigator.platform;
311
+ return s.toLowerCase().includes("win") ? "Windows" : s.toLowerCase().includes("mac") ? "Mac OS X" : s.toLowerCase().includes("linux") ? "Linux" : "Unknown";
312
+ }, i = e.avatar;
325
313
  return {
326
314
  $os: `${n()}`,
327
315
  isMobile: `${t() == "Mobile"}`,
@@ -329,76 +317,59 @@ function jt(e) {
329
317
  origin: window.location.origin,
330
318
  agentType: Ge(i),
331
319
  agentVoice: {
332
- voiceId: (o = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : o.voice_id,
333
- provider: (r = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : r.type
320
+ language: (o = (c = e.avatar) == null ? void 0 : c.voice) == null ? void 0 : o.language
334
321
  }
335
322
  };
336
323
  }
337
- function $t(e) {
338
- var n, i, c, o, s, r;
339
- const t = (n = e.llm) == null ? void 0 : n.prompt_customization;
324
+ function At(e) {
325
+ var t;
340
326
  return {
341
- agentType: Ge(e.presenter),
342
- presenterType: It(e.presenter),
343
- presenter: Et(e.presenter),
327
+ agentType: Ge(e.avatar),
328
+ presenterType: kt(e.avatar),
344
329
  owner_id: e.owner_id ?? "",
345
- promptVersion: (i = e.llm) == null ? void 0 : i.prompt_version,
346
- behavior: {
347
- role: t == null ? void 0 : t.role,
348
- personality: t == null ? void 0 : t.personality,
349
- instructions: (c = e.llm) == null ? void 0 : c.instructions
350
- },
351
- temperature: (o = e.llm) == null ? void 0 : o.temperature,
352
- knowledgeSource: t == null ? void 0 : t.knowledge_source,
353
- starterQuestionsCount: (r = (s = e.knowledge) == null ? void 0 : s.starter_message) == null ? void 0 : r.length,
354
- topicsToAvoid: t == null ? void 0 : t.topics_to_avoid,
355
- maxResponseLength: t == null ? void 0 : t.max_response_length,
330
+ starterQuestionsCount: (t = e.starter_message) == null ? void 0 : t.length,
356
331
  agentId: e.id,
357
- access: e.access,
358
- agentName: e.preview_name,
359
- ...e.access === "public" ? { from: "agent-template" } : {}
332
+ agentName: e.name
360
333
  };
361
334
  }
362
- const Bt = (e) => {
335
+ const xt = (e) => {
363
336
  try {
364
337
  return String((e == null ? void 0 : e.message) ?? e ?? "").slice(0, 256);
365
338
  } catch {
366
339
  return "Unknown error";
367
340
  }
368
- }, Ft = (e) => e.reduce((t, n) => t + n, 0), Le = (e) => Ft(e) / e.length, je = (e) => Math.min(...e), $e = (e) => Math.max(...e), le = (e, t = 0) => {
341
+ }, Pt = (e) => e.reduce((t, n) => t + n, 0), Pe = (e) => Pt(e) / e.length, Le = (e) => Math.min(...e), je = (e) => Math.max(...e), de = (e, t = 0) => {
369
342
  const n = 10 ** t;
370
343
  return Math.round(e * n) / n;
371
- }, zt = (e, t) => {
344
+ }, Lt = (e, t) => {
372
345
  const n = [...e].sort((i, c) => i - c);
373
346
  return n[Math.min(n.length - 1, Math.floor(t * (n.length - 1)))];
374
- }, Nt = (e) => zt(e, 0.5), Vt = (e, t) => {
347
+ }, jt = (e) => Lt(e, 0.5), $t = (e, t) => {
375
348
  try {
376
349
  return e();
377
350
  } catch {
378
351
  return t;
379
352
  }
380
353
  };
381
- function Ut(e, t, n) {
382
- var a, d, m;
383
- const { event: i, ...c } = e, { template: o } = (t == null ? void 0 : t.llm) || {}, { language: s } = ((a = t == null ? void 0 : t.presenter) == null ? void 0 : a.voice) || {};
354
+ function Bt(e, t, n) {
355
+ var r, a;
356
+ const { event: i, ...c } = e, { language: o } = ((r = t == null ? void 0 : t.avatar) == null ? void 0 : r.voice) || {};
384
357
  return {
385
358
  ...c,
386
- llm: { ...c.llm, template: o },
387
- script: { ...c.script, provider: { ...(d = c == null ? void 0 : c.script) == null ? void 0 : d.provider, language: s } },
388
- stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (m = t == null ? void 0 : t.presenter) == null ? void 0 : m.stitch : void 0,
359
+ script: { ...c.script, provider: { ...(a = c == null ? void 0 : c.script) == null ? void 0 : a.provider, language: o } },
389
360
  ...n
390
361
  };
391
362
  }
392
- function Be(e) {
363
+ function $e(e) {
393
364
  "requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
394
365
  }
395
366
  function ge(e) {
396
- return e instanceof G ? e.toJson() : { kind: "UnknownError", message: Bt(e) || "UnknownError" };
367
+ return e instanceof X ? e.toJson() : { kind: "UnknownError", message: xt(e) || "UnknownError" };
397
368
  }
398
- const Jt = "1.2.10", Ot = "https://api-js.mixpanel.com/track/?verbose=1&ip=1", Ze = 50, Z = [];
399
- let pe = !1;
400
- async function et(e) {
401
- const t = await fetch(Ot, {
369
+ const zt = "2.0.0-staging.377", Ft = "https://api-js.mixpanel.com/track/?verbose=1&ip=1", Ye = 50, Z = [];
370
+ let he = !1;
371
+ async function Ze(e) {
372
+ const t = await fetch(Ft, {
402
373
  method: "POST",
403
374
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
404
375
  body: new URLSearchParams({ data: JSON.stringify(e) })
@@ -406,31 +377,31 @@ async function et(e) {
406
377
  if (!t.ok)
407
378
  throw new Error(`Mixpanel responded with ${t.status}`);
408
379
  }
409
- function Kt(e) {
410
- Z.push(e), Z.splice(Ze);
380
+ function Nt(e) {
381
+ Z.push(e), Z.splice(Ye);
411
382
  }
412
- function ve() {
413
- if (pe || !Z.length)
383
+ function ye() {
384
+ if (he || !Z.length)
414
385
  return;
415
- pe = !0;
386
+ he = !0;
416
387
  const e = Z.splice(0, Z.length);
417
- et(e).catch(() => {
418
- Z.unshift(...e), Z.splice(Ze);
388
+ Ze(e).catch(() => {
389
+ Z.unshift(...e), Z.splice(Ye);
419
390
  }).finally(() => {
420
- pe = !1;
391
+ he = !1;
421
392
  });
422
393
  }
423
- typeof window < "u" && typeof window.addEventListener == "function" && (window.addEventListener("online", ve), typeof document < "u" && document.addEventListener("visibilitychange", () => {
424
- document.visibilityState === "visible" && ve();
394
+ typeof window < "u" && typeof window.addEventListener == "function" && (window.addEventListener("online", ye), typeof document < "u" && document.addEventListener("visibilitychange", () => {
395
+ document.visibilityState === "visible" && ye();
425
396
  }));
426
- function Wt(e) {
397
+ function Ut(e) {
427
398
  const t = window != null && window.hasOwnProperty("DID_AGENTS_API") ? "agents-ui" : "agents-sdk", n = {};
428
399
  return {
429
400
  token: e.token || "testKey",
430
- distinct_id: we(e.externalId),
401
+ distinct_id: pe(e.externalId),
431
402
  agentId: e.agentId,
432
403
  additionalProperties: {
433
- id: we(e.externalId),
404
+ id: pe(e.externalId),
434
405
  ...e.mixpanelAdditionalProperties || {}
435
406
  },
436
407
  isEnabled: e.isEnabled ?? !0,
@@ -449,7 +420,7 @@ function Wt(e) {
449
420
  agentId: this.agentId,
450
421
  source: t,
451
422
  emittedBy: "agents-sdk",
452
- sdkVersion: Jt,
423
+ sdkVersion: zt,
453
424
  token: this.token,
454
425
  time: a,
455
426
  $insert_id: this.getRandom(),
@@ -459,7 +430,7 @@ function Wt(e) {
459
430
  "User Agent": navigator.userAgent
460
431
  }
461
432
  };
462
- return ve(), et([d]).catch(() => Kt(d)), Promise.resolve();
433
+ return ye(), Ze([d]).catch(() => Nt(d)), Promise.resolve();
463
434
  },
464
435
  linkTrack(i, c, o, s) {
465
436
  n[i] || (n[i] = { events: {}, resolvedDependencies: [] }), s.includes(o) || s.push(o);
@@ -477,7 +448,7 @@ function Wt(e) {
477
448
  }
478
449
  };
479
450
  }
480
- function Re() {
451
+ function Me() {
481
452
  let e = 0;
482
453
  return {
483
454
  reset: () => e = 0,
@@ -485,23 +456,23 @@ function Re() {
485
456
  get: (t = !1) => t ? Date.now() - e : e
486
457
  };
487
458
  }
488
- const X = Re(), ke = Re(), Fe = Re();
489
- function tt(e) {
490
- return e === T.Playground ? { headers: { [Mt]: "true" } } : {};
459
+ const G = Me(), ve = Me(), Be = Me();
460
+ function et(e) {
461
+ return e === x.Playground ? { headers: { [vt]: "true" } } : {};
491
462
  }
492
- async function nt(e, t, n, i, c = !1, o) {
493
- return !o && !Qe(i) && (o = await t.newChat(e.id, { persist: c }, tt(i)), n.track("agent-chat", {
463
+ async function tt(e, t, n, i, c = !1, o) {
464
+ return !o && !Xe(i) && (o = await t.newChat(e.id, { persist: c }, et(i)), n.track("agent-chat", {
494
465
  event: "created",
495
466
  chatId: o.id,
496
467
  mode: i
497
468
  })), { chat: o, chatMode: (o == null ? void 0 : o.chat_mode) ?? i };
498
469
  }
499
- function Ht(e) {
470
+ function Jt(e) {
500
471
  return e && e.length > 0 ? e : [];
501
472
  }
502
- function qt(e) {
473
+ function Vt(e) {
503
474
  return new Promise((t, n) => {
504
- const { callbacks: i, host: c, auth: o, externalId: s } = e, { onMessage: r = null, onOpen: a = null, onClose: d = null, onError: m = null } = i || {}, u = new WebSocket(`${c}?authorization=${encodeURIComponent(Xe(o, s))}`);
475
+ const { callbacks: i, host: c, auth: o, externalId: s } = e, { onMessage: r = null, onOpen: a = null, onClose: d = null, onError: m = null } = i || {}, u = new WebSocket(`${c}?authorization=${encodeURIComponent(qe(o, s))}`);
505
476
  u.onmessage = r, u.onclose = d, u.onerror = (f) => {
506
477
  console.error(f), m == null || m("Websocket failed to connect", f), n(f);
507
478
  }, u.onopen = (f) => {
@@ -509,28 +480,28 @@ function qt(e) {
509
480
  };
510
481
  });
511
482
  }
512
- async function Xt(e) {
483
+ async function Kt(e) {
513
484
  const { retries: t = 1 } = e;
514
485
  let n = null;
515
486
  for (let i = 0; (n == null ? void 0 : n.readyState) !== WebSocket.OPEN; i++)
516
487
  try {
517
- n = await qt(e);
488
+ n = await Vt(e);
518
489
  } catch (c) {
519
490
  if (i === t)
520
491
  throw c;
521
- await qe(i * 500);
492
+ await He(i * 500);
522
493
  }
523
494
  return n;
524
495
  }
525
- async function Gt(e, t, n, i) {
526
- const c = n != null && n.onMessage ? [n.onMessage] : [], o = await Xt({
496
+ async function Ot(e, t, n, i) {
497
+ const c = n != null && n.onMessage ? [n.onMessage] : [], o = await Kt({
527
498
  auth: e,
528
499
  host: t,
529
500
  externalId: i,
530
501
  callbacks: {
531
502
  onError: (s) => {
532
503
  var r;
533
- return (r = n.onError) == null ? void 0 : r.call(n, new ut(s));
504
+ return (r = n.onError) == null ? void 0 : r.call(n, new lt(s));
534
505
  },
535
506
  onMessage(s) {
536
507
  const r = JSON.parse(s.data);
@@ -552,28 +523,28 @@ function ze(e) {
552
523
  n += e[t++];
553
524
  return n;
554
525
  }
555
- function Qt(e, t, n) {
526
+ function Wt(e, t, n) {
556
527
  if (!e.content)
557
528
  return;
558
529
  const i = {
559
530
  id: e.id || `user-${Date.now()}`,
560
531
  role: e.role,
561
532
  content: e.content,
562
- parts: ae(e.content),
533
+ parts: re(e.content),
563
534
  created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
564
535
  transcribed: !0
565
536
  };
566
537
  t.messages.push(i), n == null || n([...t.messages], "user");
567
538
  }
568
- function Yt(e, t, n, i, c, o, s) {
569
- if (e === F.Transcribe && t.content) {
570
- Qt(t, i, c);
539
+ function Ht(e, t, n, i, c, o, s) {
540
+ if (e === z.Transcribe && t.content) {
541
+ Wt(t, i, c);
571
542
  return;
572
543
  }
573
- if (!(e === F.Partial || e === F.Answer))
544
+ if (!(e === z.Partial || e === z.Answer))
574
545
  return;
575
546
  const r = i.messages[i.messages.length - 1];
576
- if (e === F.Answer && (r == null ? void 0 : r.role) === "user" && s === "partial")
547
+ if (e === z.Answer && (r == null ? void 0 : r.role) === "user" && s === "partial")
577
548
  return;
578
549
  const d = s === "answer";
579
550
  let m;
@@ -590,16 +561,16 @@ function Yt(e, t, n, i, c, o, s) {
590
561
  else
591
562
  return;
592
563
  const { content: u, sequence: f } = t;
593
- if (e === F.Partial)
564
+ if (e === z.Partial)
594
565
  n[f] = u;
595
566
  else {
596
567
  const v = ze(n);
597
568
  !!(u && u.length < v.length) && (m.interrupted = !0), n.answer = u;
598
569
  }
599
- const w = ze(n);
600
- (m.content !== w || e === F.Answer) && (m.content = w, m.parts = ae(w), c == null || c([...i.messages], e));
570
+ const p = ze(n);
571
+ (m.content !== p || e === z.Answer) && (m.content = p, m.parts = re(p), c == null || c([...i.messages], e));
601
572
  }
602
- function Zt(e, t, n, i, c) {
573
+ function qt(e, t, n, i, c) {
603
574
  const o = {}, s = () => {
604
575
  for (const d of Object.keys(o))
605
576
  delete o[d];
@@ -614,40 +585,40 @@ function Zt(e, t, n, i, c) {
614
585
  onMessage: (d, m) => {
615
586
  var u, f;
616
587
  if ("content" in m) {
617
- const w = d === x.ChatAnswer ? F.Answer : d === x.ChatAudioTranscribed ? F.Transcribe : d;
618
- Yt(
619
- w,
588
+ const p = d === L.ChatAnswer ? z.Answer : d === L.ChatAudioTranscribed ? z.Transcribe : d;
589
+ Ht(
590
+ p,
620
591
  m,
621
592
  o,
622
593
  t,
623
594
  a,
624
595
  s,
625
596
  r
626
- ), w === F.Partial ? r = "partial" : w === F.Answer && (r = "answer", s()), w === F.Answer && e.track("agent-message-received", {
597
+ ), p === z.Partial ? r = "partial" : p === z.Answer && (r = "answer", s()), p === z.Answer && e.track("agent-message-received", {
627
598
  content: m.content,
628
599
  messages: t.messages.length,
629
600
  mode: t.chatMode
630
601
  });
631
602
  } else {
632
- const w = x, v = [w.StreamVideoDone, w.StreamVideoError, w.StreamVideoRejected], j = [w.StreamFailed, w.StreamVideoError, w.StreamVideoRejected], I = Ut(m, i, { mode: t.chatMode });
633
- if (d = d, d === w.StreamVideoCreated && (e.linkTrack("agent-video", I, w.StreamVideoCreated, ["start"]), m.sentiment)) {
603
+ const p = L, v = [p.StreamVideoDone, p.StreamVideoError, p.StreamVideoRejected], B = [p.StreamFailed, p.StreamVideoError, p.StreamVideoRejected], D = Bt(m, i, { mode: t.chatMode });
604
+ if (d = d, d === p.StreamVideoCreated && (e.linkTrack("agent-video", D, p.StreamVideoCreated, ["start"]), m.sentiment)) {
634
605
  const b = t.messages[t.messages.length - 1];
635
606
  if ((b == null ? void 0 : b.role) === "assistant") {
636
- const P = { ...b, sentiment: m.sentiment };
637
- t.messages[t.messages.length - 1] = P, a == null || a([...t.messages], r ?? "answer");
607
+ const j = { ...b, sentiment: m.sentiment };
608
+ t.messages[t.messages.length - 1] = j, a == null || a([...t.messages], r ?? "answer");
638
609
  }
639
610
  }
640
611
  if (v.includes(d)) {
641
612
  const b = d.split("/")[1];
642
- j.includes(d) ? e.track("agent-video", { ...I, event: b }) : e.linkTrack("agent-video", { ...I, event: b }, d, ["done"]);
613
+ B.includes(d) ? e.track("agent-video", { ...D, event: b }) : e.linkTrack("agent-video", { ...D, event: b }, d, ["done"]);
643
614
  }
644
- j.includes(d) && ((f = (u = n.callbacks).onError) == null || f.call(u, new We(`Stream failed with event ${d}`), { data: m })), m.event === w.StreamDone && c();
615
+ B.includes(d) && ((f = (u = n.callbacks).onError) == null || f.call(u, new Oe(`Stream failed with event ${d}`), { data: m })), m.event === p.StreamDone && c();
645
616
  }
646
617
  }
647
618
  };
648
619
  }
649
- function en(e, t, n, i) {
650
- const c = Ye(e, `${t}/agents/${n}`, i);
620
+ function Gt(e, t, n, i) {
621
+ const c = Qe(e, `${t}/agents/${n}`, i);
651
622
  return {
652
623
  createStream(o, s) {
653
624
  return c.post("/streams", o, { signal: s });
@@ -683,23 +654,23 @@ function en(e, t, n, i) {
683
654
  }
684
655
  };
685
656
  }
686
- const tn = (e, t) => (n, i) => e && console.log(`[${t}] ${n}`, i ?? ""), nn = 45;
687
- function rn(e) {
657
+ const Xt = (e, t) => (n, i) => e && console.log(`[${t}] ${n}`, i ?? ""), Qt = 45;
658
+ function Yt(e) {
688
659
  const t = e.map((a) => a.av).filter((a) => !!a && a.audioPlayout > 0 && a.videoPlayout > 0);
689
660
  if (t.length < 2)
690
661
  return null;
691
662
  const n = t[0].localTs, i = t[t.length - 1].localTs - n, c = t.map((a) => a.audioPlayout - a.videoPlayout), o = c.filter(
692
- (a) => a > nn || a < -100
663
+ (a) => a > Qt || a < -100
693
664
  ), s = t.filter((a) => a.localTs - n >= Math.min(5e3, i / 2)), r = (s.length ? s : t).map((a) => a.audioPlayout - a.videoPlayout);
694
665
  return {
695
666
  sampleCount: t.length,
696
- durationMs: le(i),
697
- desyncDurationMs: le(i * (o.length / c.length)),
698
- maxOffsetMs: le(c.reduce((a, d) => Math.abs(d) > Math.abs(a) ? d : a)),
699
- residualOffsetMs: le(Nt(r))
667
+ durationMs: de(i),
668
+ desyncDurationMs: de(i * (o.length / c.length)),
669
+ maxOffsetMs: de(c.reduce((a, d) => Math.abs(d) > Math.abs(a) ? d : a)),
670
+ residualOffsetMs: de(jt(r))
700
671
  };
701
672
  }
702
- function an(e, t, n) {
673
+ function Zt(e, t, n) {
703
674
  const i = (t.timestamp - e.timestamp) / 1e3;
704
675
  return {
705
676
  duration: i,
@@ -719,7 +690,7 @@ function an(e, t, n) {
719
690
  lowFpsCount: n
720
691
  };
721
692
  }
722
- function sn(e) {
693
+ function en(e) {
723
694
  return e.filter(
724
695
  (t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
725
696
  ).map((t) => {
@@ -730,7 +701,7 @@ function sn(e) {
730
701
  };
731
702
  });
732
703
  }
733
- function on(e) {
704
+ function tn(e) {
734
705
  var a;
735
706
  let t = "", n = 0, i = null, c = null;
736
707
  const o = /* @__PURE__ */ new Map();
@@ -771,7 +742,7 @@ function on(e) {
771
742
  localTs: s.timestamp
772
743
  }), r;
773
744
  }
774
- function Ne(e, t, n) {
745
+ function Fe(e, t, n) {
775
746
  const i = e.map((a, d) => d === 0 ? n ? {
776
747
  timestamp: a.timestamp,
777
748
  duration: 0,
@@ -823,74 +794,74 @@ function Ne(e, t, n) {
823
794
  framesPerSecond: a.framesPerSecond,
824
795
  freezeCount: a.freezeCount - e[d - 1].freezeCount,
825
796
  freezeDuration: a.freezeDuration - e[d - 1].freezeDuration
826
- }), c = sn(i), o = c.reduce((a, d) => a + (d.causes.includes("low fps") ? 1 : 0), 0), s = i.filter((a) => !!a.avgJitterDelayInInterval).map((a) => a.avgJitterDelayInInterval), r = i.filter((a) => !!a.rtt).map((a) => a.rtt);
797
+ }), c = en(i), o = c.reduce((a, d) => a + (d.causes.includes("low fps") ? 1 : 0), 0), s = i.filter((a) => !!a.avgJitterDelayInInterval).map((a) => a.avgJitterDelayInInterval), r = i.filter((a) => !!a.rtt).map((a) => a.rtt);
827
798
  return {
828
799
  webRTCStats: {
829
800
  anomalies: c,
830
- avSync: Vt(() => rn(e), null),
831
- minRtt: je(r),
832
- avgRtt: Le(r),
833
- maxRtt: $e(r),
834
- aggregateReport: an(e[0], e[e.length - 1], o),
835
- minJitterDelayInInterval: je(s),
836
- maxJitterDelayInInterval: $e(s),
837
- avgJitterDelayInInterval: Le(s)
801
+ avSync: $t(() => Yt(e), null),
802
+ minRtt: Le(r),
803
+ avgRtt: Pe(r),
804
+ maxRtt: je(r),
805
+ aggregateReport: Zt(e[0], e[e.length - 1], o),
806
+ minJitterDelayInInterval: Le(s),
807
+ maxJitterDelayInInterval: je(s),
808
+ avgJitterDelayInInterval: Pe(s)
838
809
  },
839
810
  codec: e[0].codec,
840
811
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
841
812
  };
842
813
  }
843
- function rt(e, t) {
814
+ function nt(e, t) {
844
815
  for (const n of e.values())
845
816
  if ((n == null ? void 0 : n.type) === "inbound-rtp" && n.kind === t)
846
817
  return n;
847
818
  return null;
848
819
  }
849
- const ne = 10;
850
- function Pn(e, t) {
820
+ const te = 10;
821
+ function bn(e, t) {
851
822
  let n = !1, i = !1, c = null, o = 0, s = 0, r = {};
852
823
  async function a() {
853
824
  if (n) {
854
825
  try {
855
826
  const d = await e();
856
827
  if (!d) {
857
- c = setTimeout(a, ne);
828
+ c = setTimeout(a, te);
858
829
  return;
859
830
  }
860
- const m = rt(d, "audio");
831
+ const m = nt(d, "audio");
861
832
  if (!m) {
862
- c = setTimeout(a, ne);
833
+ c = setTimeout(a, te);
863
834
  return;
864
835
  }
865
836
  const u = m.totalAudioEnergy ?? 0, f = m.totalSamplesReceived ?? 0;
866
837
  if (!i) {
867
- o = u, s = f, i = !0, c = setTimeout(a, ne);
838
+ o = u, s = f, i = !0, c = setTimeout(a, te);
868
839
  return;
869
840
  }
870
- const w = u - o, v = f - s;
871
- if (o = u, s = f, v > 0 && w > 0) {
841
+ const p = u - o, v = f - s;
842
+ if (o = u, s = f, v > 0 && p > 0) {
872
843
  n = !1, t(r);
873
844
  return;
874
845
  }
875
846
  } catch {
876
847
  }
877
- n && (c = setTimeout(a, ne));
848
+ n && (c = setTimeout(a, te));
878
849
  }
879
850
  }
880
851
  return {
881
852
  arm(d = {}) {
882
- r = d, n = !0, i = !1, performance.now(), c !== null && clearTimeout(c), c = setTimeout(a, ne);
853
+ r = d, n = !0, i = !1, performance.now(), c !== null && clearTimeout(c), c = setTimeout(a, te);
883
854
  },
884
855
  destroy() {
885
856
  n = !1, c !== null && (clearTimeout(c), c = null);
886
857
  }
887
858
  };
888
859
  }
889
- const fe = 100, cn = Math.max(Math.ceil(400 / fe), 1), dn = 0.25, ln = 0.28;
890
- function un() {
860
+ const ue = 100, nn = Math.max(Math.ceil(400 / ue), 1), rn = 0.25, an = 0.28;
861
+ function sn() {
891
862
  let e = 0, t, n, i = 0;
892
863
  return (c) => {
893
- const o = rt(c, "video");
864
+ const o = nt(c, "video");
894
865
  if (!o)
895
866
  return { isReceiving: !1, avgJitterDelayInInterval: i };
896
867
  const s = o.jitterBufferDelay, r = o.jitterBufferEmittedCount;
@@ -903,53 +874,53 @@ function un() {
903
874
  return e = a, { isReceiving: d, avgJitterDelayInInterval: i, freezeCount: o.freezeCount };
904
875
  };
905
876
  }
906
- function fn(e, t, n, i, c) {
907
- let o = null, s = [], r, a = 0, d = !1, m = re.Unknown, u = re.Unknown, f = 0, w = 0;
908
- const v = un();
909
- async function j() {
910
- const I = await e();
911
- if (!I)
877
+ function on(e, t, n, i, c) {
878
+ let o = null, s = [], r, a = 0, d = !1, m = ne.Unknown, u = ne.Unknown, f = 0, p = 0;
879
+ const v = sn();
880
+ async function B() {
881
+ const D = await e();
882
+ if (!D)
912
883
  return;
913
- const { isReceiving: b, avgJitterDelayInInterval: P, freezeCount: E } = v(I), Q = on(I);
884
+ const { isReceiving: b, avgJitterDelayInInterval: j, freezeCount: E } = v(D), Q = tn(D);
914
885
  if (b)
915
- a = 0, f = E - w, u = P < dn ? re.Strong : P > ln && f > 1 ? re.Weak : m, u !== m && (c == null || c(u), m = u, w += f, f = 0), d || (i == null || i(C.Start), r = s[s.length - 1], s = [], d = !0), s.push(Q);
916
- else if (d && (a++, a >= cn)) {
917
- const H = Ne(s, fe, r);
918
- i == null || i(C.Stop, H), t() || n(), w = E, d = !1;
886
+ a = 0, f = E - p, u = j < rn ? ne.Strong : j > an && f > 1 ? ne.Weak : m, u !== m && (c == null || c(u), m = u, p += f, f = 0), d || (i == null || i(k.Start), r = s[s.length - 1], s = [], d = !0), s.push(Q);
887
+ else if (d && (a++, a >= nn)) {
888
+ const H = Fe(s, ue, r);
889
+ i == null || i(k.Stop, H), t() || n(), p = E, d = !1;
919
890
  }
920
891
  }
921
892
  return {
922
893
  start: () => {
923
- o || (o = setInterval(j, fe));
894
+ o || (o = setInterval(B, ue));
924
895
  },
925
896
  stop: () => {
926
897
  o && (clearInterval(o), o = null);
927
898
  },
928
- getReport: () => Ne(s, fe, r)
899
+ getReport: () => Fe(s, ue, r)
929
900
  };
930
901
  }
931
- const mn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
932
- function Ve(e) {
902
+ const cn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
903
+ function Ne(e) {
933
904
  switch (e) {
934
905
  case "connected":
935
- return A.Connected;
906
+ return P.Connected;
936
907
  case "checking":
937
- return A.Connecting;
908
+ return P.Connecting;
938
909
  case "failed":
939
- return A.Fail;
910
+ return P.Fail;
940
911
  case "new":
941
- return A.New;
912
+ return P.New;
942
913
  case "closed":
943
- return A.Closed;
914
+ return P.Closed;
944
915
  case "disconnected":
945
- return A.Disconnected;
916
+ return P.Disconnected;
946
917
  case "completed":
947
- return A.Completed;
918
+ return P.Completed;
948
919
  default:
949
- return A.New;
920
+ return P.New;
950
921
  }
951
922
  }
952
- const hn = (e) => (t) => {
923
+ const dn = (e) => (t) => {
953
924
  const [n, i = ""] = t.split(/:(.+)/);
954
925
  try {
955
926
  const c = JSON.parse(i);
@@ -958,16 +929,16 @@ const hn = (e) => (t) => {
958
929
  return e("Failed to parse data channel message, returning data as string", { subject: n, rawData: i, error: c }), { subject: n, data: i };
959
930
  }
960
931
  };
961
- function gn({
932
+ function ln({
962
933
  statsSignal: e,
963
934
  dataChannelSignal: t,
964
935
  onVideoStateChange: n,
965
936
  report: i,
966
937
  log: c
967
938
  }) {
968
- e === C.Start && t === C.Start ? (c("CALLBACK: onVideoStateChange(Start)"), n == null || n(C.Start)) : e === C.Stop && t === C.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), n == null || n(C.Stop, i));
939
+ e === k.Start && t === k.Start ? (c("CALLBACK: onVideoStateChange(Start)"), n == null || n(k.Start)) : e === k.Stop && t === k.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), n == null || n(k.Stop, i));
969
940
  }
970
- function pn({
941
+ function un({
971
942
  statsSignal: e,
972
943
  dataChannelSignal: t,
973
944
  onVideoStateChange: n,
@@ -975,7 +946,7 @@ function pn({
975
946
  report: c,
976
947
  log: o
977
948
  }) {
978
- e === C.Start ? (o("CALLBACK: onVideoStateChange(Start)"), n == null || n(C.Start)) : e === C.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), n == null || n(C.Stop, c)), t === C.Start ? i == null || i(ie.Talking) : t === C.Stop && (i == null || i(ie.Idle));
949
+ e === k.Start ? (o("CALLBACK: onVideoStateChange(Start)"), n == null || n(k.Start)) : e === k.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), n == null || n(k.Stop, c)), t === k.Start ? i == null || i(ae.Talking) : t === k.Stop && (i == null || i(ae.Idle));
979
950
  }
980
951
  function Ue({
981
952
  statsSignal: e,
@@ -986,7 +957,7 @@ function Ue({
986
957
  report: o,
987
958
  log: s
988
959
  }) {
989
- c === W.Legacy ? gn({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: n, report: o, log: s }) : c === W.Fluent && pn({
960
+ c === W.Legacy ? ln({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: n, report: o, log: s }) : c === W.Fluent && un({
990
961
  statsSignal: e,
991
962
  dataChannelSignal: t,
992
963
  onVideoStateChange: n,
@@ -995,11 +966,11 @@ function Ue({
995
966
  log: s
996
967
  });
997
968
  }
998
- async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me, analytics: s }, r) {
999
- var N;
1000
- const a = tn(n, "WebRTCStreamingManager"), d = hn(a);
1001
- let m = !1, u = !1, f = C.Stop, w = C.Stop;
1002
- const { startConnection: v, sendStreamRequest: j, close: I, createStream: b, addIceCandidate: P } = en(
969
+ async function fn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = fe, analytics: s }, r) {
970
+ var I;
971
+ const a = Xt(n, "WebRTCStreamingManager"), d = dn(a);
972
+ let m = !1, u = !1, f = k.Stop, p = k.Stop;
973
+ const { startConnection: v, sendStreamRequest: B, close: D, createStream: b, addIceCandidate: j } = Gt(
1003
974
  c,
1004
975
  o,
1005
976
  e,
@@ -1008,115 +979,115 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
1008
979
  id: E,
1009
980
  offer: Q,
1010
981
  ice_servers: H,
1011
- session_id: V,
1012
- fluent: se,
982
+ session_id: J,
983
+ fluent: ie,
1013
984
  interrupt_enabled: Y
1014
985
  } = await b(t, r);
1015
- (N = i.onStreamCreated) == null || N.call(i, { stream_id: E, session_id: V, agent_id: e });
1016
- const R = new mn({ iceServers: H }), q = R.createDataChannel("JanusDataChannel");
1017
- if (!V)
986
+ (I = i.onStreamCreated) == null || I.call(i, { stream_id: E, session_id: J, agent_id: e });
987
+ const M = new cn({ iceServers: H }), q = M.createDataChannel("JanusDataChannel");
988
+ if (!J)
1018
989
  throw new Error("Could not create session_id");
1019
- const U = se ? W.Fluent : W.Legacy;
990
+ const V = ie ? W.Fluent : W.Legacy;
1020
991
  s.enrich({
1021
- "stream-type": U
992
+ "stream-type": V
1022
993
  });
1023
- const oe = t.stream_warmup && !se, ce = () => m, te = () => {
994
+ const se = t.stream_warmup && !ie, oe = () => m, l = () => {
1024
995
  var h;
1025
- m = !0, u && (a("CALLBACK: onConnectionStateChange(Connected)"), (h = i.onConnectionStateChange) == null || h.call(i, A.Connected));
1026
- }, l = fn(
1027
- () => R.getStats(),
1028
- ce,
1029
- te,
1030
- (h, p) => Ue({
1031
- statsSignal: w = h,
1032
- dataChannelSignal: U === W.Legacy ? f : void 0,
996
+ m = !0, u && (a("CALLBACK: onConnectionStateChange(Connected)"), (h = i.onConnectionStateChange) == null || h.call(i, P.Connected));
997
+ }, g = on(
998
+ () => M.getStats(),
999
+ oe,
1000
+ l,
1001
+ (h, w) => Ue({
1002
+ statsSignal: p = h,
1003
+ dataChannelSignal: V === W.Legacy ? f : void 0,
1033
1004
  onVideoStateChange: i.onVideoStateChange,
1034
1005
  onAgentActivityStateChange: i.onAgentActivityStateChange,
1035
- report: p,
1036
- streamType: U,
1006
+ report: w,
1007
+ streamType: V,
1037
1008
  log: a
1038
1009
  }),
1039
1010
  (h) => {
1040
- var p;
1041
- return (p = i.onConnectivityStateChange) == null ? void 0 : p.call(i, h);
1011
+ var w;
1012
+ return (w = i.onConnectivityStateChange) == null ? void 0 : w.call(i, h);
1042
1013
  }
1043
1014
  );
1044
- l.start(), R.onicecandidate = (h) => {
1045
- var p;
1015
+ g.start(), M.onicecandidate = (h) => {
1016
+ var w;
1046
1017
  a("peerConnection.onicecandidate", h);
1047
1018
  try {
1048
- h.candidate && h.candidate.sdpMid && h.candidate.sdpMLineIndex !== null ? P(
1019
+ h.candidate && h.candidate.sdpMid && h.candidate.sdpMLineIndex !== null ? j(
1049
1020
  E,
1050
1021
  {
1051
1022
  candidate: h.candidate.candidate,
1052
1023
  sdpMid: h.candidate.sdpMid,
1053
1024
  sdpMLineIndex: h.candidate.sdpMLineIndex
1054
1025
  },
1055
- V,
1026
+ J,
1056
1027
  r
1057
- ) : P(E, { candidate: null }, V, r);
1058
- } catch (D) {
1059
- (p = i.onError) == null || p.call(i, D, { streamId: E });
1028
+ ) : j(E, { candidate: null }, J, r);
1029
+ } catch (T) {
1030
+ (w = i.onError) == null || w.call(i, T, { streamId: E });
1060
1031
  }
1061
1032
  }, q.onopen = () => {
1062
- u = !0, (!oe || m) && te();
1033
+ u = !0, (!se || m) && l();
1063
1034
  };
1064
- let g = null;
1065
- const y = (h) => {
1066
- var p;
1067
- g = h, (p = i.onVideoIdChange) == null || p.call(i, h);
1035
+ let y = null;
1036
+ const C = (h) => {
1037
+ var w;
1038
+ y = h, (w = i.onVideoIdChange) == null || w.call(i, h);
1068
1039
  };
1069
- function k(h, p) {
1070
- if (h === x.StreamStarted && typeof p == "object" && "metadata" in p) {
1071
- const D = p.metadata;
1072
- y(D.videoId);
1040
+ function S(h, w) {
1041
+ if (h === L.StreamStarted && typeof w == "object" && "metadata" in w) {
1042
+ const T = w.metadata;
1043
+ C(T.videoId);
1073
1044
  }
1074
- h === x.StreamDone && y(null), f = h === x.StreamStarted ? C.Start : C.Stop, Ue({
1075
- statsSignal: U === W.Legacy ? w : void 0,
1045
+ h === L.StreamDone && C(null), f = h === L.StreamStarted ? k.Start : k.Stop, Ue({
1046
+ statsSignal: V === W.Legacy ? p : void 0,
1076
1047
  dataChannelSignal: f,
1077
1048
  onVideoStateChange: i.onVideoStateChange,
1078
1049
  onAgentActivityStateChange: i.onAgentActivityStateChange,
1079
- streamType: U,
1050
+ streamType: V,
1080
1051
  log: a
1081
1052
  });
1082
1053
  }
1083
- function S(h, p) {
1084
- var B;
1085
- const D = typeof p == "string" ? p : p == null ? void 0 : p.metadata;
1086
- D && s.enrich({ streamMetadata: D }), (B = i.onStreamReady) == null || B.call(i);
1054
+ function R(h, w) {
1055
+ var _;
1056
+ const T = typeof w == "string" ? w : w == null ? void 0 : w.metadata;
1057
+ T && s.enrich({ streamMetadata: T }), (_ = i.onStreamReady) == null || _.call(i);
1087
1058
  }
1088
- const M = {
1089
- [x.StreamStarted]: k,
1090
- [x.StreamDone]: k,
1091
- [x.StreamReady]: S
1059
+ const $ = {
1060
+ [L.StreamStarted]: S,
1061
+ [L.StreamDone]: S,
1062
+ [L.StreamReady]: R
1092
1063
  };
1093
1064
  q.onmessage = (h) => {
1094
- var B;
1095
- const { subject: p, data: D } = d(h.data);
1096
- (B = M[p]) == null || B.call(M, p, D);
1097
- }, R.oniceconnectionstatechange = () => {
1098
- var p;
1099
- a("peerConnection.oniceconnectionstatechange => " + R.iceConnectionState);
1100
- const h = Ve(R.iceConnectionState);
1101
- h !== A.Connected && ((p = i.onConnectionStateChange) == null || p.call(i, h, `webrtc:ice-${R.iceConnectionState}`));
1102
- }, R.ontrack = (h) => {
1103
- var p;
1104
- a("peerConnection.ontrack", h), a("CALLBACK: onSrcObjectReady"), (p = i.onSrcObjectReady) == null || p.call(i, h.streams[0]);
1105
- }, await R.setRemoteDescription(Q), a("set remote description OK");
1106
- const L = await R.createAnswer();
1107
- a("create answer OK"), await R.setLocalDescription(L), a("set local description OK"), await v(E, L, V, r), a("start connection OK");
1108
- function z(h) {
1109
- var p, D;
1065
+ var _;
1066
+ const { subject: w, data: T } = d(h.data);
1067
+ (_ = $[w]) == null || _.call($, w, T);
1068
+ }, M.oniceconnectionstatechange = () => {
1069
+ var w;
1070
+ a("peerConnection.oniceconnectionstatechange => " + M.iceConnectionState);
1071
+ const h = Ne(M.iceConnectionState);
1072
+ h !== P.Connected && ((w = i.onConnectionStateChange) == null || w.call(i, h, `webrtc:ice-${M.iceConnectionState}`));
1073
+ }, M.ontrack = (h) => {
1074
+ var w;
1075
+ a("peerConnection.ontrack", h), a("CALLBACK: onSrcObjectReady"), (w = i.onSrcObjectReady) == null || w.call(i, h.streams[0]);
1076
+ }, await M.setRemoteDescription(Q), a("set remote description OK");
1077
+ const F = await M.createAnswer();
1078
+ a("create answer OK"), await M.setLocalDescription(F), a("set local description OK"), await v(E, F, J, r), a("start connection OK");
1079
+ function N(h) {
1080
+ var w, T;
1110
1081
  if (!m || q.readyState !== "open") {
1111
- a("Data channel is not ready for sending messages"), (p = i.onError) == null || p.call(i, new We("Data channel is not ready for sending messages"), {
1082
+ a("Data channel is not ready for sending messages"), (w = i.onError) == null || w.call(i, new Oe("Data channel is not ready for sending messages"), {
1112
1083
  streamId: E
1113
1084
  });
1114
1085
  return;
1115
1086
  }
1116
1087
  try {
1117
1088
  q.send(h);
1118
- } catch (B) {
1119
- a("Error sending data channel message", B), (D = i.onError) == null || D.call(i, B, { streamId: E });
1089
+ } catch (_) {
1090
+ a("Error sending data channel message", _), (T = i.onError) == null || T.call(i, _, { streamId: E });
1120
1091
  }
1121
1092
  }
1122
1093
  return {
@@ -1125,7 +1096,7 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
1125
1096
  * @param payload
1126
1097
  */
1127
1098
  speak(h) {
1128
- return j(E, V, h);
1099
+ return B(E, J, h);
1129
1100
  },
1130
1101
  /**
1131
1102
  * Method to close RTC connection
@@ -1133,64 +1104,64 @@ async function wn(e, t, { debug: n = !1, callbacks: i, auth: c, baseURL: o = me,
1133
1104
  async disconnect() {
1134
1105
  var h;
1135
1106
  if (E) {
1136
- const p = Ve(R.iceConnectionState);
1137
- if (R) {
1138
- if (p === A.New) {
1139
- l.stop();
1107
+ const w = Ne(M.iceConnectionState);
1108
+ if (M) {
1109
+ if (w === P.New) {
1110
+ g.stop();
1140
1111
  return;
1141
1112
  }
1142
- R.close(), R.oniceconnectionstatechange = null, R.onnegotiationneeded = null, R.onicecandidate = null, R.ontrack = null;
1113
+ M.close(), M.oniceconnectionstatechange = null, M.onnegotiationneeded = null, M.onicecandidate = null, M.ontrack = null;
1143
1114
  }
1144
1115
  try {
1145
- p === A.Connected && await I(E, V).catch((D) => {
1116
+ w === P.Connected && await D(E, J).catch((T) => {
1146
1117
  });
1147
- } catch (D) {
1148
- a("Error on close stream connection", D);
1118
+ } catch (T) {
1119
+ a("Error on close stream connection", T);
1149
1120
  }
1150
- (h = i.onAgentActivityStateChange) == null || h.call(i, ie.Idle), l.stop();
1121
+ (h = i.onAgentActivityStateChange) == null || h.call(i, ae.Idle), g.stop();
1151
1122
  }
1152
1123
  },
1153
- sendDataChannelMessage: z,
1124
+ sendDataChannelMessage: N,
1154
1125
  /**
1155
1126
  * Session identifier information, should be returned in the body of all streaming requests
1156
1127
  */
1157
- sessionId: V,
1128
+ sessionId: J,
1158
1129
  /**
1159
1130
  * Id of current RTC stream
1160
1131
  */
1161
1132
  streamId: E,
1162
- streamType: U,
1133
+ streamType: V,
1163
1134
  interruptAvailable: Y ?? !1,
1164
1135
  isInterruptible: !0,
1165
1136
  interrupt(h) {
1166
1137
  if (!Y)
1167
1138
  throw new Error("Interrupt is not enabled for this stream");
1168
- if (U !== W.Fluent)
1139
+ if (V !== W.Fluent)
1169
1140
  throw new Error("Interrupt only available for Fluent streams");
1170
- if (!g)
1141
+ if (!y)
1171
1142
  throw new Error("No active video to interrupt");
1172
- const p = {
1173
- type: x.StreamInterrupt,
1174
- videoId: g,
1143
+ const w = {
1144
+ type: L.StreamInterrupt,
1145
+ videoId: y,
1175
1146
  timestamp: Date.now()
1176
1147
  };
1177
- z(JSON.stringify(p));
1148
+ N(JSON.stringify(w));
1178
1149
  }
1179
1150
  };
1180
1151
  }
1181
1152
  var Ce = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Ce || {});
1182
- async function yn(e, t, n, i) {
1153
+ async function mn(e, t, n, i) {
1183
1154
  const c = e.id;
1184
1155
  switch (t.version) {
1185
1156
  case "v1": {
1186
1157
  const { version: o, ...s } = t;
1187
- return wn(c, s, n, i);
1158
+ return fn(c, s, n, i);
1188
1159
  }
1189
1160
  case "v2": {
1190
1161
  const { version: o, ...s } = t;
1191
1162
  switch (s.transport.provider) {
1192
1163
  case Se.Livekit:
1193
- const { createLiveKitStreamingManager: r } = await import("./livekit-manager-Bpqug2PD.js");
1164
+ const { createLiveKitStreamingManager: r } = await import("./livekit-manager-CAEsFehe.js");
1194
1165
  return r(c, s, n);
1195
1166
  default:
1196
1167
  throw new Error(`Unsupported transport provider: ${s.transport.provider}`);
@@ -1200,15 +1171,15 @@ async function yn(e, t, n, i) {
1200
1171
  throw new Error(`Invalid stream version: ${t.version}`);
1201
1172
  }
1202
1173
  }
1203
- const vn = "cht";
1204
- function kn() {
1174
+ const gn = "cht";
1175
+ function hn() {
1205
1176
  return {
1206
1177
  transport: {
1207
1178
  provider: Se.Livekit
1208
1179
  }
1209
1180
  };
1210
1181
  }
1211
- function Cn(e) {
1182
+ function pn(e) {
1212
1183
  var c, o;
1213
1184
  const { streamOptions: t } = e ?? {}, n = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
1214
1185
  plan: (o = e.mixpanelAdditionalProperties) == null ? void 0 : o.plan
@@ -1221,86 +1192,80 @@ function Cn(e) {
1221
1192
  fluent: t == null ? void 0 : t.fluent
1222
1193
  }, ...n && { end_user_data: n } };
1223
1194
  }
1224
- function Sn(e, t) {
1225
- return Me(e.presenter.type) ? { version: Ce.V2, ...kn() } : { version: Ce.V1, ...Cn(t) };
1195
+ function wn(e, t) {
1196
+ return ke(e.avatar.type) ? { version: Ce.V2, ...hn() } : { version: Ce.V1, ...pn(t) };
1226
1197
  }
1227
- function Mn(e, t, n) {
1198
+ function yn(e, t, n) {
1228
1199
  n.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
1229
1200
  }
1230
- function Rn(e, t, n, i, c) {
1231
- c === W.Fluent ? Dn(e, t, n, i, c) : In(e, t, n, i, c);
1201
+ function vn(e, t, n, i, c) {
1202
+ c === W.Fluent ? Cn(e, t, n, i, c) : Sn(e, t, n, i, c);
1232
1203
  }
1233
- function Dn(e, t, n, i, c) {
1234
- e === C.Start ? i.track("stream-session", { event: "start", "stream-type": c }) : e === C.Stop && i.track("stream-session", {
1204
+ function Cn(e, t, n, i, c) {
1205
+ e === k.Start ? i.track("stream-session", { event: "start", "stream-type": c }) : e === k.Stop && i.track("stream-session", {
1235
1206
  event: "stop",
1236
- is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1237
- background: t.presenter.type === "clip" && t.presenter.background,
1238
1207
  "stream-type": c,
1239
1208
  ...n
1240
1209
  });
1241
1210
  }
1242
1211
  function Je(e, t, n, i, c) {
1243
- e === C.Start ? n.linkTrack("agent-video", { event: "start", ...c, "stream-type": i }, "start", [
1244
- x.StreamVideoCreated
1245
- ]) : e === C.Stop && n.linkTrack(
1212
+ e === k.Start ? n.linkTrack("agent-video", { event: "start", ...c, "stream-type": i }, "start", [
1213
+ L.StreamVideoCreated
1214
+ ]) : e === k.Stop && n.linkTrack(
1246
1215
  "agent-video",
1247
1216
  {
1248
1217
  event: "stop",
1249
- is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1250
- background: t.presenter.type === "clip" && t.presenter.background,
1251
1218
  "stream-type": i
1252
1219
  },
1253
1220
  "done",
1254
- [x.StreamVideoDone]
1221
+ [L.StreamVideoDone]
1255
1222
  );
1256
1223
  }
1257
- function In(e, t, n, i, c) {
1258
- e === C.Start ? i.linkTrack(
1224
+ function Sn(e, t, n, i, c) {
1225
+ e === k.Start ? i.linkTrack(
1259
1226
  "agent-video",
1260
- { event: "start", latency: X.get(!0), "stream-type": c },
1227
+ { event: "start", latency: G.get(!0), "stream-type": c },
1261
1228
  "start",
1262
- [x.StreamVideoCreated]
1263
- ) : e === C.Stop && i.linkTrack(
1229
+ [L.StreamVideoCreated]
1230
+ ) : e === k.Stop && i.linkTrack(
1264
1231
  "agent-video",
1265
1232
  {
1266
1233
  event: "stop",
1267
- is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1268
- background: t.presenter.type === "clip" && t.presenter.background,
1269
1234
  "stream-type": c,
1270
1235
  ...n
1271
1236
  },
1272
1237
  "done",
1273
- [x.StreamVideoDone]
1238
+ [L.StreamVideoDone]
1274
1239
  );
1275
1240
  }
1276
- function En(e, t, n) {
1241
+ function kn(e, t, n) {
1277
1242
  const i = {
1278
1243
  call_id: t.call_id,
1279
1244
  name: t.name
1280
1245
  };
1281
- if (e === x.ToolCallStarted) {
1246
+ if (e === L.ToolCallStarted) {
1282
1247
  n.track("agent-tool-call", { ...i, event: "started" });
1283
1248
  return;
1284
1249
  }
1285
1250
  const c = t;
1286
1251
  n.track("agent-tool-call", {
1287
1252
  ...i,
1288
- event: e === x.ToolCallDone ? "done" : "error",
1253
+ event: e === L.ToolCallDone ? "done" : "error",
1289
1254
  duration_ms: c.duration_ms,
1290
1255
  extra_keys: c.extra ? Object.keys(c.extra).length : 0
1291
1256
  });
1292
1257
  }
1293
- function Oe(e, t, n, i) {
1294
- return X.reset(), Fe.update(), new Promise(async (c, o) => {
1258
+ function Ve(e, t, n, i) {
1259
+ return G.reset(), Be.update(), new Promise(async (c, o) => {
1295
1260
  try {
1296
1261
  let s, r = !1;
1297
- const a = Sn(e, t);
1262
+ const a = wn(e, t);
1298
1263
  n.enrich({
1299
1264
  "stream-version": a.version.toString()
1300
1265
  });
1301
1266
  let d = null;
1302
- const m = e.presenter.type === "expressive";
1303
- s = await yn(
1267
+ const m = e.avatar.type === "expressive";
1268
+ s = await mn(
1304
1269
  e,
1305
1270
  a,
1306
1271
  {
@@ -1309,12 +1274,12 @@ function Oe(e, t, n, i) {
1309
1274
  callbacks: {
1310
1275
  ...t.callbacks,
1311
1276
  onConnectionStateChange: (u, f) => {
1312
- var w, v;
1313
- (v = (w = t.callbacks).onConnectionStateChange) == null || v.call(w, u), Mn(u, f, n), u === A.Connected && (s ? c(s) : r = !0);
1277
+ var p, v;
1278
+ (v = (p = t.callbacks).onConnectionStateChange) == null || v.call(p, u), yn(u, f, n), u === P.Connected && (s ? c(s) : r = !0);
1314
1279
  },
1315
1280
  onVideoStateChange: (u, f) => {
1316
- var w, v;
1317
- (v = (w = t.callbacks).onVideoStateChange) == null || v.call(w, u), Rn(
1281
+ var p, v;
1282
+ (v = (p = t.callbacks).onVideoStateChange) == null || v.call(p, u), vn(
1318
1283
  u,
1319
1284
  e,
1320
1285
  f,
@@ -1323,17 +1288,17 @@ function Oe(e, t, n, i) {
1323
1288
  );
1324
1289
  },
1325
1290
  onAgentActivityStateChange: (u) => {
1326
- var f, w;
1327
- (w = (f = t.callbacks).onAgentActivityStateChange) == null || w.call(f, u), u === ie.Talking ? (ke.update(), d = (v) => {
1291
+ var f, p;
1292
+ (p = (f = t.callbacks).onAgentActivityStateChange) == null || p.call(f, u), u === ae.Talking ? (ve.update(), d = (v) => {
1328
1293
  Je(
1329
- C.Start,
1294
+ k.Start,
1330
1295
  e,
1331
1296
  n,
1332
1297
  s.streamType,
1333
1298
  v
1334
1299
  ), d = null;
1335
- }, m || d({ latency: X.get(!0) })) : (ke.reset(), d = null, Je(
1336
- C.Stop,
1300
+ }, m || d({ latency: G.get(!0) })) : (ve.reset(), d = null, Je(
1301
+ k.Stop,
1337
1302
  e,
1338
1303
  n,
1339
1304
  s.streamType
@@ -1343,12 +1308,12 @@ function Oe(e, t, n, i) {
1343
1308
  d == null || d(u);
1344
1309
  },
1345
1310
  onStreamReady: () => {
1346
- const u = Fe.get(!0);
1311
+ const u = Be.get(!0);
1347
1312
  n.track("agent-chat", { event: "ready", latency: u });
1348
1313
  },
1349
1314
  onToolEvent: ((u, f) => {
1350
- var w, v;
1351
- (v = (w = t.callbacks).onToolEvent) == null || v.call(w, u, f), En(u, f, n);
1315
+ var p, v;
1316
+ (v = (p = t.callbacks).onToolEvent) == null || v.call(p, u, f), kn(u, f, n);
1352
1317
  })
1353
1318
  }
1354
1319
  },
@@ -1359,135 +1324,135 @@ function Oe(e, t, n, i) {
1359
1324
  }
1360
1325
  });
1361
1326
  }
1362
- async function bn(e, t, n, i, c) {
1363
- var m, u, f, w;
1327
+ async function Mn(e, t, n, i, c) {
1328
+ var m, u, f, p;
1364
1329
  const o = async () => {
1365
- if (Me(e.presenter.type)) {
1366
- const v = await Oe(e, t, i), j = `${vn}_${v.sessionId}`, I = (/* @__PURE__ */ new Date()).toISOString();
1330
+ if (ke(e.avatar.type)) {
1331
+ const v = await Ve(e, t, i), B = `${gn}_${v.sessionId}`, D = (/* @__PURE__ */ new Date()).toISOString();
1367
1332
  return { chatResult: {
1368
- chatMode: T.Functional,
1333
+ chatMode: x.Functional,
1369
1334
  chat: {
1370
- id: j,
1335
+ id: B,
1371
1336
  agent_id: e.id,
1372
1337
  owner_id: e.owner_id ?? "",
1373
- created: I,
1374
- modified: I,
1375
- agent_id__created_at: I,
1376
- agent_id__modified_at: I,
1377
- chat_mode: T.Functional,
1338
+ created: D,
1339
+ modified: D,
1340
+ agent_id__created_at: D,
1341
+ agent_id__modified_at: D,
1342
+ chat_mode: x.Functional,
1378
1343
  messages: []
1379
1344
  }
1380
1345
  }, streamingManager: v };
1381
1346
  } else {
1382
- const v = new AbortController(), j = v.signal;
1383
- let I;
1347
+ const v = new AbortController(), B = v.signal;
1348
+ let D;
1384
1349
  try {
1385
- const b = nt(
1350
+ const b = tt(
1386
1351
  e,
1387
1352
  n,
1388
1353
  i,
1389
1354
  t.mode,
1390
1355
  t.persistentChat,
1391
1356
  c
1392
- ), P = Oe(e, t, i, j).then((H) => (I = H, H)), [E, Q] = await Promise.all([b, P]);
1357
+ ), j = Ve(e, t, i, B).then((H) => (D = H, H)), [E, Q] = await Promise.all([b, j]);
1393
1358
  return { chatResult: E, streamingManager: Q };
1394
1359
  } catch (b) {
1395
- throw v.abort(), I && await I.disconnect().catch(() => {
1360
+ throw v.abort(), D && await D.disconnect().catch(() => {
1396
1361
  }), b;
1397
1362
  }
1398
1363
  }
1399
1364
  }, { chatResult: s, streamingManager: r } = await o(), { chat: a, chatMode: d } = s;
1400
- return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (u = (m = t.callbacks).onModeChange) == null || u.call(m, d), d !== T.Functional) ? ((w = (f = t.callbacks).onError) == null || w.call(f, new ct(d)), r == null || r.disconnect(), { chat: a }) : { chat: a, streamingManager: r };
1365
+ return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (u = (m = t.callbacks).onModeChange) == null || u.call(m, d), d !== x.Functional) ? ((p = (f = t.callbacks).onError) == null || p.call(f, new ot(d)), r == null || r.disconnect(), { chat: a }) : { chat: a, streamingManager: r };
1401
1366
  }
1402
- async function Ln(e, t) {
1403
- var U, oe, ce, te;
1367
+ async function Tn(e, t) {
1368
+ var V, se, oe;
1404
1369
  let n = !0;
1405
- const i = t.mixpanelKey || Dt, c = t.wsURL || Rt, o = t.baseURL || me, s = t.mode || T.Functional, r = {
1370
+ const i = t.mixpanelKey || St, c = t.wsURL || Ct, o = t.baseURL || fe, s = t.mode || x.Functional, r = {
1406
1371
  messages: [],
1407
1372
  chatMode: s
1408
- }, a = Wt({
1373
+ }, a = Ut({
1409
1374
  token: i,
1410
1375
  agentId: e,
1411
1376
  isEnabled: t.enableAnalytics ?? t.enableAnalitics,
1412
1377
  externalId: t.externalId,
1413
1378
  mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
1414
1379
  }), d = Date.now();
1415
- Be(() => {
1380
+ $e(() => {
1416
1381
  a.track("agent-sdk", { event: "init" }, d);
1417
1382
  });
1418
1383
  const m = t.callbacks.onError;
1419
1384
  t.callbacks.onError = (l, g) => {
1420
1385
  a.track("agent-error", { error: ge(l) }), m == null || m(l, g);
1421
1386
  };
1422
- const u = Lt(t.auth, o, t.callbacks.onError, t.externalId), f = await u.getById(e);
1423
- t.debug = t.debug || ((U = f == null ? void 0 : f.advanced_settings) == null ? void 0 : U.ui_debug_mode);
1424
- const w = Me(f.presenter.type);
1425
- a.enrich($t(f));
1426
- const { onMessage: v, clearQueue: j } = Zt(a, r, t, f, () => {
1387
+ const u = Tt(t.auth, o, t.callbacks.onError, t.externalId), f = await u.getRuntimeById(e);
1388
+ t.debug = t.debug || ((V = f == null ? void 0 : f.advanced_settings) == null ? void 0 : V.ui_debug_mode);
1389
+ const p = ke(f.avatar.type);
1390
+ a.enrich(At(f));
1391
+ const { onMessage: v, clearQueue: B } = qt(a, r, t, f, () => {
1427
1392
  var l, g, y;
1428
- (l = r.socketManager) == null || l.disconnect(), (y = (g = t.callbacks).onConnectionStateChange) == null || y.call(g, A.Disconnected);
1393
+ (l = r.socketManager) == null || l.disconnect(), (y = (g = t.callbacks).onConnectionStateChange) == null || y.call(g, P.Disconnected);
1429
1394
  });
1430
- r.messages = Ht(t.initialMessages), (ce = (oe = t.callbacks).onNewMessage) == null || ce.call(oe, [...r.messages], "answer");
1431
- const I = (l) => {
1395
+ r.messages = Jt(t.initialMessages), (oe = (se = t.callbacks).onNewMessage) == null || oe.call(se, [...r.messages], "answer");
1396
+ const D = (l) => {
1432
1397
  a.enrich({ videoId: l });
1433
1398
  }, b = ({ type: l }) => {
1434
- var y, k, S, M;
1435
- if (!((y = r.streamingManager) != null && y.interruptAvailable) || !((k = r.streamingManager) != null && k.isInterruptible)) return;
1399
+ var y, C, S, R;
1400
+ if (!((y = r.streamingManager) != null && y.interruptAvailable) || !((C = r.streamingManager) != null && C.isInterruptible)) return;
1436
1401
  const g = r.messages[r.messages.length - 1];
1437
1402
  a.track("agent-video-interrupt", {
1438
1403
  type: l || "click",
1439
- video_duration_to_interrupt: ke.get(!0),
1440
- message_duration_to_interrupt: X.get(!0)
1441
- }), g.interrupted = !0, (M = (S = t.callbacks).onNewMessage) == null || M.call(S, [...r.messages], "answer"), r.streamingManager.interrupt(l);
1442
- }, P = /* @__PURE__ */ new Map();
1404
+ video_duration_to_interrupt: ve.get(!0),
1405
+ message_duration_to_interrupt: G.get(!0)
1406
+ }), g.interrupted = !0, (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...r.messages], "answer"), r.streamingManager.interrupt(l);
1407
+ }, j = /* @__PURE__ */ new Map();
1443
1408
  function E(l) {
1444
1409
  return async (g) => {
1445
- const y = P.get(l);
1410
+ const y = j.get(l);
1446
1411
  if (!y)
1447
1412
  throw new Error(`No handler registered for client tool: ${l}`);
1448
1413
  try {
1449
- const k = JSON.parse(g.payload);
1450
- return await y(k);
1451
- } catch (k) {
1452
- throw new Error(`Client tool "${l}" failed: ${k.message}`);
1414
+ const C = JSON.parse(g.payload);
1415
+ return await y(C);
1416
+ } catch (C) {
1417
+ throw new Error(`Client tool "${l}" failed: ${C.message}`);
1453
1418
  }
1454
1419
  };
1455
1420
  }
1456
1421
  function Q() {
1457
- var l, g, y, k;
1458
- for (const [S] of P)
1459
- (g = (l = r.streamingManager) == null ? void 0 : l.unregisterRpcMethod) == null || g.call(l, S), (k = (y = r.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || k.call(y, S, E(S));
1422
+ var l, g, y, C;
1423
+ for (const [S] of j)
1424
+ (g = (l = r.streamingManager) == null ? void 0 : l.unregisterRpcMethod) == null || g.call(l, S), (C = (y = r.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || C.call(y, S, E(S));
1460
1425
  }
1461
1426
  function H(l, g) {
1462
- var k, S;
1463
- const y = !P.has(l);
1464
- P.set(l, g), y && ((S = (k = r.streamingManager) == null ? void 0 : k.registerRpcMethod) == null || S.call(k, l, E(l)));
1427
+ var C, S;
1428
+ const y = !j.has(l);
1429
+ j.set(l, g), y && ((S = (C = r.streamingManager) == null ? void 0 : C.registerRpcMethod) == null || S.call(C, l, E(l)));
1465
1430
  }
1466
- function V(l) {
1431
+ function J(l) {
1467
1432
  var g, y;
1468
- P.delete(l), (y = (g = r.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || y.call(g, l);
1433
+ j.delete(l), (y = (g = r.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || y.call(g, l);
1469
1434
  }
1470
- const se = Date.now();
1471
- Be(() => {
1472
- a.track("agent-sdk", { event: "loaded", ...jt(f) }, se);
1435
+ const ie = Date.now();
1436
+ $e(() => {
1437
+ a.track("agent-sdk", { event: "loaded", ..._t(f) }, ie);
1473
1438
  });
1474
1439
  async function Y(l) {
1475
- var L, z, N, h, p, D, B;
1476
- Ct(), (z = (L = t.callbacks).onConnectionStateChange) == null || z.call(L, A.Connecting), X.reset(), l && !n && (delete r.chat, (h = (N = t.callbacks).onNewMessage) == null || h.call(N, [...r.messages], "answer"));
1477
- const g = s === T.DirectPlayback || w ? Promise.resolve(void 0) : Gt(
1440
+ var $, F, N, I, h, w, T;
1441
+ wt(), (F = ($ = t.callbacks).onConnectionStateChange) == null || F.call($, P.Connecting), G.reset(), l && !n && (delete r.chat, (I = (N = t.callbacks).onNewMessage) == null || I.call(N, [...r.messages], "answer"));
1442
+ const g = s === x.DirectPlayback || p ? Promise.resolve(void 0) : Ot(
1478
1443
  t.auth,
1479
1444
  c,
1480
1445
  { onMessage: v, onError: t.callbacks.onError },
1481
1446
  t.externalId
1482
- ), y = ye(
1483
- () => bn(
1447
+ ), y = we(
1448
+ () => Mn(
1484
1449
  f,
1485
1450
  {
1486
1451
  ...t,
1487
1452
  mode: s,
1488
1453
  callbacks: {
1489
1454
  ...t.callbacks,
1490
- onVideoIdChange: I,
1455
+ onVideoIdChange: D,
1491
1456
  onMessage: v
1492
1457
  }
1493
1458
  },
@@ -1497,28 +1462,28 @@ async function Ln(e, t) {
1497
1462
  ),
1498
1463
  {
1499
1464
  limit: 3,
1500
- timeout: St,
1465
+ timeout: yt,
1501
1466
  timeoutErrorMessage: "Timeout initializing the stream",
1502
- shouldRetryFn: (O) => (O == null ? void 0 : O.message) !== "Could not connect" && !(O instanceof Ke && (O.status === 429 || O.kind === "InsufficientCreditsError")),
1467
+ shouldRetryFn: (_) => (_ == null ? void 0 : _.message) !== "Could not connect" && !(_ instanceof Ke && (_.status === 429 || _.kind === "InsufficientCreditsError")),
1503
1468
  delayMs: 1e3
1504
1469
  }
1505
- ).catch((O) => {
1506
- var _, J;
1507
- throw q(T.Maintenance), (J = (_ = t.callbacks).onConnectionStateChange) == null || J.call(_, A.Fail), O;
1508
- }), [k, { streamingManager: S, chat: M }] = await Promise.all([g, y]);
1509
- M && M.id !== ((p = r.chat) == null ? void 0 : p.id) && ((B = (D = t.callbacks).onNewChat) == null || B.call(D, M.id)), r.streamingManager = S, r.socketManager = k, r.chat = M, Q(), n = !1, a.enrich({
1510
- chatId: M == null ? void 0 : M.id,
1470
+ ).catch((_) => {
1471
+ var A, K;
1472
+ throw q(x.Maintenance), (K = (A = t.callbacks).onConnectionStateChange) == null || K.call(A, P.Fail), _;
1473
+ }), [C, { streamingManager: S, chat: R }] = await Promise.all([g, y]);
1474
+ R && R.id !== ((h = r.chat) == null ? void 0 : h.id) && ((T = (w = t.callbacks).onNewChat) == null || T.call(w, R.id)), r.streamingManager = S, r.socketManager = C, r.chat = R, Q(), n = !1, a.enrich({
1475
+ chatId: R == null ? void 0 : R.id,
1511
1476
  streamId: S == null ? void 0 : S.streamId,
1512
1477
  mode: r.chatMode
1513
- }), q((M == null ? void 0 : M.chat_mode) ?? s);
1478
+ }), q((R == null ? void 0 : R.chat_mode) ?? s);
1514
1479
  }
1515
- async function R() {
1516
- var l, g, y, k;
1517
- (l = r.socketManager) == null || l.disconnect(), await ((g = r.streamingManager) == null ? void 0 : g.disconnect()), delete r.streamingManager, delete r.socketManager, (k = (y = t.callbacks).onConnectionStateChange) == null || k.call(y, A.Disconnected);
1480
+ async function M() {
1481
+ var l, g, y, C;
1482
+ (l = r.socketManager) == null || l.disconnect(), await ((g = r.streamingManager) == null ? void 0 : g.disconnect()), delete r.streamingManager, delete r.socketManager, (C = (y = t.callbacks).onConnectionStateChange) == null || C.call(y, P.Disconnected);
1518
1483
  }
1519
1484
  async function q(l) {
1520
1485
  var g, y;
1521
- l !== r.chatMode && (a.track("agent-mode-change", { mode: l }), r.chatMode = l, r.chatMode !== T.Functional && await R(), (y = (g = t.callbacks).onModeChange) == null || y.call(g, l));
1486
+ l !== r.chatMode && (a.track("agent-mode-change", { mode: l }), r.chatMode = l, r.chatMode !== x.Functional && await M(), (y = (g = t.callbacks).onModeChange) == null || y.call(g, l));
1522
1487
  }
1523
1488
  return {
1524
1489
  agent: f,
@@ -1530,7 +1495,7 @@ async function Ln(e, t) {
1530
1495
  var l;
1531
1496
  return ((l = r.streamingManager) == null ? void 0 : l.interruptAvailable) ?? !1;
1532
1497
  },
1533
- starterMessages: ((te = f.knowledge) == null ? void 0 : te.starter_message) || [],
1498
+ starterMessages: f.starter_message || [],
1534
1499
  getSTTToken: () => u.getSTTToken(f.id),
1535
1500
  changeMode: q,
1536
1501
  enrichAnalytics: a.enrich,
@@ -1543,14 +1508,14 @@ async function Ln(e, t) {
1543
1508
  async reconnect() {
1544
1509
  const l = r.streamingManager;
1545
1510
  let g;
1546
- if (w && (l != null && l.reconnect))
1511
+ if (p && (l != null && l.reconnect))
1547
1512
  try {
1548
1513
  await l.reconnect();
1549
1514
  } catch (y) {
1550
- g = ge(y).kind, await R(), await Y(!1);
1515
+ g = ge(y).kind, await M(), await Y(!1);
1551
1516
  }
1552
1517
  else
1553
- await R(), await Y(!1);
1518
+ await M(), await Y(!1);
1554
1519
  a.track("agent-chat", {
1555
1520
  event: "reconnect",
1556
1521
  mode: r.chatMode,
@@ -1559,7 +1524,7 @@ async function Ln(e, t) {
1559
1524
  });
1560
1525
  },
1561
1526
  async disconnect() {
1562
- await R(), a.track("agent-chat", {
1527
+ await M(), a.track("agent-chat", {
1563
1528
  event: "disconnect",
1564
1529
  mode: r.chatMode
1565
1530
  });
@@ -1585,118 +1550,118 @@ async function Ln(e, t) {
1585
1550
  return (l = r.streamingManager) != null && l.unpublishCameraStream ? r.streamingManager.unpublishCameraStream() : Promise.resolve();
1586
1551
  },
1587
1552
  async chat(l) {
1588
- var S, M, L, z, N;
1553
+ var S, R, $, F, N;
1589
1554
  const g = () => {
1590
- if (Qe(s))
1591
- throw new $(`${s} is enabled, chat is disabled`);
1592
- if (l.length >= be)
1593
- throw new $(`Message cannot be more than ${be} characters`);
1555
+ if (Xe(s))
1556
+ throw new U(`${s} is enabled, chat is disabled`);
1557
+ if (l.length >= Ee)
1558
+ throw new U(`Message cannot be more than ${Ee} characters`);
1594
1559
  if (l.length === 0)
1595
- throw new $("Message cannot be empty");
1596
- if (r.chatMode === T.Maintenance)
1597
- throw new $("Chat is in maintenance mode");
1598
- if (![T.TextOnly, T.Playground].includes(r.chatMode)) {
1560
+ throw new U("Message cannot be empty");
1561
+ if (r.chatMode === x.Maintenance)
1562
+ throw new U("Chat is in maintenance mode");
1563
+ if (![x.TextOnly, x.Playground].includes(r.chatMode)) {
1599
1564
  if (!r.streamingManager)
1600
- throw new $("Streaming manager is not initialized");
1565
+ throw new U("Streaming manager is not initialized");
1601
1566
  if (!r.chat)
1602
- throw new $("Chat is not initialized");
1567
+ throw new U("Chat is not initialized");
1603
1568
  }
1604
1569
  }, y = async () => {
1605
- var h, p;
1570
+ var I, h;
1606
1571
  if (!r.chat) {
1607
- const D = await nt(
1572
+ const w = await tt(
1608
1573
  f,
1609
1574
  u,
1610
1575
  a,
1611
1576
  r.chatMode,
1612
1577
  t.persistentChat
1613
1578
  );
1614
- if (!D.chat)
1615
- throw new ot(r.chatMode, !!t.persistentChat);
1616
- r.chat = D.chat, (p = (h = t.callbacks).onNewChat) == null || p.call(h, r.chat.id);
1579
+ if (!w.chat)
1580
+ throw new st(r.chatMode, !!t.persistentChat);
1581
+ r.chat = w.chat, (h = (I = t.callbacks).onNewChat) == null || h.call(I, r.chat.id);
1617
1582
  }
1618
1583
  return r.chat.id;
1619
- }, k = async (h, p) => {
1620
- const D = r.chatMode === T.Playground;
1621
- return ye(w && !D ? async () => {
1622
- var _, J;
1623
- return await ((J = (_ = r.streamingManager) == null ? void 0 : _.sendTextMessage) == null ? void 0 : J.call(_, l)), Promise.resolve({});
1584
+ }, C = async (I, h) => {
1585
+ const w = r.chatMode === x.Playground;
1586
+ return we(p && !w ? async () => {
1587
+ var A, K;
1588
+ return await ((K = (A = r.streamingManager) == null ? void 0 : A.sendTextMessage) == null ? void 0 : K.call(A, l)), Promise.resolve({});
1624
1589
  } : async () => {
1625
- var _, J;
1590
+ var A, K;
1626
1591
  return u.chat(
1627
1592
  f.id,
1628
- p,
1593
+ h,
1629
1594
  {
1630
1595
  chatMode: r.chatMode,
1631
- streamId: (_ = r.streamingManager) == null ? void 0 : _.streamId,
1632
- sessionId: (J = r.streamingManager) == null ? void 0 : J.sessionId,
1633
- messages: h.map(({ matches: at, ...de }) => de)
1596
+ streamId: (A = r.streamingManager) == null ? void 0 : A.streamId,
1597
+ sessionId: (K = r.streamingManager) == null ? void 0 : K.sessionId,
1598
+ messages: I.map(({ matches: rt, ...ce }) => ce)
1634
1599
  },
1635
1600
  {
1636
- ...tt(r.chatMode),
1601
+ ...et(r.chatMode),
1637
1602
  skipErrorHandler: !0
1638
1603
  }
1639
1604
  );
1640
1605
  }, {
1641
1606
  limit: 2,
1642
- shouldRetryFn: (_) => {
1643
- var de, De, Ie, Ee;
1644
- const J = (de = _ == null ? void 0 : _.message) == null ? void 0 : de.includes("missing or invalid session_id");
1645
- return !((De = _ == null ? void 0 : _.message) == null ? void 0 : De.includes("Stream Error")) && !J ? ((Ee = (Ie = t.callbacks).onError) == null || Ee.call(Ie, _), !1) : !0;
1607
+ shouldRetryFn: (A) => {
1608
+ var ce, Re, De, Ie;
1609
+ const K = (ce = A == null ? void 0 : A.message) == null ? void 0 : ce.includes("missing or invalid session_id");
1610
+ return !((Re = A == null ? void 0 : A.message) == null ? void 0 : Re.includes("Stream Error")) && !K ? ((Ie = (De = t.callbacks).onError) == null || Ie.call(De, A), !1) : !0;
1646
1611
  },
1647
1612
  onRetry: async () => {
1648
- await R(), await Y(!1);
1613
+ await M(), await Y(!1);
1649
1614
  }
1650
1615
  });
1651
1616
  };
1652
1617
  try {
1653
- j(), g(), r.messages.push({
1618
+ B(), g(), r.messages.push({
1654
1619
  id: ee(),
1655
1620
  role: "user",
1656
1621
  content: l,
1657
- parts: ae(l),
1658
- created_at: new Date(X.update()).toISOString()
1659
- }), (M = (S = t.callbacks).onNewMessage) == null || M.call(S, [...r.messages], "user");
1660
- const h = await y(), p = await k([...r.messages], h);
1661
- return p.result && r.messages.push({
1622
+ parts: re(l),
1623
+ created_at: new Date(G.update()).toISOString()
1624
+ }), (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...r.messages], "user");
1625
+ const I = await y(), h = await C([...r.messages], I);
1626
+ return h.result && r.messages.push({
1662
1627
  id: ee(),
1663
1628
  role: "assistant",
1664
- content: p.result,
1665
- parts: ae(p.result),
1629
+ content: h.result,
1630
+ parts: re(h.result),
1666
1631
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1667
- context: p.context,
1668
- matches: p.matches
1632
+ context: h.context,
1633
+ matches: h.matches
1669
1634
  }), a.track("agent-message-send", {
1670
1635
  event: "success",
1671
1636
  messages: r.messages.length + 1
1672
- }), p.result && ((z = (L = t.callbacks).onNewMessage) == null || z.call(L, [...r.messages], "answer"), a.track("agent-message-received", {
1673
- latency: X.get(!0),
1637
+ }), h.result && ((F = ($ = t.callbacks).onNewMessage) == null || F.call($, [...r.messages], "answer"), a.track("agent-message-received", {
1638
+ latency: G.get(!0),
1674
1639
  messages: r.messages.length
1675
- })), p;
1676
- } catch (h) {
1640
+ })), h;
1641
+ } catch (I) {
1677
1642
  throw ((N = r.messages[r.messages.length - 1]) == null ? void 0 : N.role) === "assistant" && r.messages.pop(), a.track("agent-message-send", {
1678
1643
  event: "error",
1679
1644
  messages: r.messages.length,
1680
- error: ge(h)
1681
- }), h;
1645
+ error: ge(I)
1646
+ }), I;
1682
1647
  }
1683
1648
  },
1684
1649
  rate(l, g, y) {
1685
- var M, L, z, N;
1686
- const k = r.messages.find((h) => h.id === l);
1650
+ var R, $, F, N;
1651
+ const C = r.messages.find((I) => I.id === l);
1687
1652
  if (r.chat) {
1688
- if (!k)
1689
- throw new $("Message not found");
1690
- } else throw new $("Chat is not initialized");
1691
- const S = ((M = k.matches) == null ? void 0 : M.map((h) => [h.document_id, h.id])) ?? [];
1653
+ if (!C)
1654
+ throw new U("Message not found");
1655
+ } else throw new U("Chat is not initialized");
1656
+ const S = ((R = C.matches) == null ? void 0 : R.map((I) => [I.document_id, I.id])) ?? [];
1692
1657
  return a.track("agent-rate", {
1693
1658
  event: y ? "update" : "create",
1694
1659
  thumb: g === 1 ? "up" : "down",
1695
- knowledge_id: ((L = f.knowledge) == null ? void 0 : L.id) ?? "",
1660
+ knowledge_id: (($ = f.knowledge) == null ? void 0 : $.id) ?? "",
1696
1661
  matches: S,
1697
1662
  score: g
1698
1663
  }), y ? u.updateRating(f.id, r.chat.id, y, {
1699
- knowledge_id: ((z = f.knowledge) == null ? void 0 : z.id) ?? "",
1664
+ knowledge_id: ((F = f.knowledge) == null ? void 0 : F.id) ?? "",
1700
1665
  message_id: l,
1701
1666
  matches: S,
1702
1667
  score: g
@@ -1709,105 +1674,90 @@ async function Ln(e, t) {
1709
1674
  },
1710
1675
  deleteRate(l) {
1711
1676
  if (!r.chat)
1712
- throw new $("Chat is not initialized");
1677
+ throw new U("Chat is not initialized");
1713
1678
  return a.track("agent-rate-delete", { type: "text" }), u.deleteRating(f.id, r.chat.id, l);
1714
1679
  },
1715
1680
  submitFeedback(l, g) {
1716
1681
  if (!r.chat)
1717
- throw new $("Chat is not initialized");
1682
+ throw new U("Chat is not initialized");
1718
1683
  return a.track("agent-feedback", { rating: l, hasAnswer: !!g }), u.submitFeedback(f.id, r.chat.id, { rating: l, answer: g });
1719
1684
  },
1720
1685
  async speak(l) {
1721
- var S, M, L;
1686
+ var S, R, $;
1722
1687
  function g() {
1723
- if (typeof l == "string") {
1724
- if (!f.presenter.voice)
1725
- throw new $("Presenter voice is not initialized");
1726
- return {
1727
- type: "text",
1728
- provider: f.presenter.voice,
1729
- input: l,
1730
- ssml: !1
1731
- };
1732
- }
1733
- if (l.type === "text" && !l.provider) {
1734
- if (!f.presenter.voice)
1735
- throw new $("Presenter voice is not initialized");
1736
- return {
1737
- type: "text",
1738
- provider: f.presenter.voice,
1739
- input: l.input,
1740
- ssml: l.ssml,
1741
- should_queue_speaks: l.should_queue_speaks,
1742
- sentiment: l.sentiment
1743
- };
1744
- }
1745
- return l;
1688
+ return typeof l == "string" ? {
1689
+ type: "text",
1690
+ input: l,
1691
+ ssml: !1
1692
+ } : l.type === "text" && !l.provider ? {
1693
+ type: "text",
1694
+ input: l.input,
1695
+ ssml: l.ssml,
1696
+ should_queue_speaks: l.should_queue_speaks,
1697
+ sentiment: l.sentiment
1698
+ } : l;
1746
1699
  }
1747
1700
  const y = g();
1748
- if (a.track("agent-speak", y), X.update(), r.messages && y.type === "text" && (r.messages.push({
1701
+ if (a.track("agent-speak", y), G.update(), r.messages && y.type === "text" && (r.messages.push({
1749
1702
  id: ee(),
1750
1703
  role: "assistant",
1751
1704
  content: y.input,
1752
- parts: ae(y.input),
1705
+ parts: re(y.input),
1753
1706
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1754
- }), (M = (S = t.callbacks).onNewMessage) == null || M.call(S, [...r.messages], "answer")), bt(r.chatMode))
1707
+ }), (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...r.messages], "answer")), Mt(r.chatMode))
1755
1708
  return {
1756
1709
  duration: 0,
1757
1710
  video_id: "",
1758
1711
  status: "success"
1759
1712
  };
1760
1713
  if (!r.streamingManager)
1761
- throw new $("Please connect to the agent first");
1714
+ throw new U("Please connect to the agent first");
1762
1715
  return r.streamingManager.speak({
1763
1716
  script: y,
1764
- metadata: { chat_id: (L = r.chat) == null ? void 0 : L.id, agent_id: f.id }
1717
+ metadata: { chat_id: ($ = r.chat) == null ? void 0 : $.id, agent_id: f.id }
1765
1718
  });
1766
1719
  },
1767
1720
  interrupt: b,
1768
1721
  registerClientTool: H,
1769
- unregisterClientTool: V
1722
+ unregisterClientTool: J
1770
1723
  };
1771
1724
  }
1772
1725
  export {
1773
- ie as A,
1774
- G as B,
1775
- F as C,
1776
- yt as D,
1726
+ ae as A,
1727
+ X as B,
1728
+ z as C,
1729
+ gt as D,
1777
1730
  Ke as H,
1778
- wt as K,
1779
- lt as N,
1780
- mt as P,
1781
- gt as R,
1782
- x as S,
1731
+ mt as K,
1732
+ dt as N,
1733
+ ht as P,
1734
+ ut as R,
1735
+ L as S,
1783
1736
  Se as T,
1784
- ft as U,
1785
- $ as V,
1786
- ut as W,
1787
- tn as a,
1737
+ U as V,
1738
+ lt as W,
1739
+ Xt as a,
1788
1740
  W as b,
1789
- Ye as c,
1790
- me as d,
1791
- We as e,
1792
- A as f,
1793
- re as g,
1794
- fn as h,
1795
- Pn as i,
1796
- C as j,
1797
- ht as k,
1798
- X as l,
1799
- ot as m,
1800
- xn as n,
1801
- T as o,
1802
- ct as p,
1803
- vt as q,
1804
- Jt as r,
1741
+ Qe as c,
1742
+ fe as d,
1743
+ Oe as e,
1744
+ P as f,
1745
+ ne as g,
1746
+ on as h,
1747
+ bn as i,
1748
+ k as j,
1749
+ st as k,
1750
+ G as l,
1751
+ x as m,
1752
+ En as n,
1753
+ ot as o,
1754
+ zt as p,
1755
+ ft as q,
1756
+ We as r,
1805
1757
  pt as s,
1806
1758
  ge as t,
1807
- He as u,
1808
- kt as v,
1809
- Ln as w,
1810
- Tn as x,
1811
- An as y,
1812
- At as z
1759
+ Tn as u,
1760
+ Dn as v,
1761
+ In as w,
1762
+ It as x
1813
1763
  };