@d-id/client-sdk 1.2.4 → 1.2.5-staging.357

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