@d-id/client-sdk 1.1.64 → 1.1.65-staging.304

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