@d-id/client-sdk 1.2.4-staging.353 → 1.2.4

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