@d-id/client-sdk 1.1.68-staging.323 → 1.1.68-staging.325

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