@d-id/client-sdk 1.1.70 → 1.2.0-staging.339

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