@d-id/client-sdk 1.1.68-staging.324 → 1.1.68-staging.326

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 || {}), z = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(z || {}), 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);
@@ -377,21 +381,21 @@ function we() {
377
381
  };
378
382
  }
379
383
  const H = we(), fe = we(), _e = we();
380
- function Ve(e) {
381
- return e === x.Playground ? { headers: { [st]: "true" } } : {};
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,12 +403,12 @@ 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))}`);
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))}`);
408
412
  l.onmessage = n, l.onclose = d, l.onerror = (w) => {
409
413
  console.error(w), m == null || m("Websocket failed to connect", w), r(w);
410
414
  }, l.onopen = (w) => {
@@ -412,12 +416,12 @@ function Et(e) {
412
416
  };
413
417
  });
414
418
  }
415
- async function _t(e) {
419
+ async function Tt(e) {
416
420
  const { retries: t = 1 } = 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,15 +429,15 @@ async function _t(e) {
425
429
  }
426
430
  return r;
427
431
  }
428
- async function Tt(e, t, r, a) {
429
- const c = r != null && r.onMessage ? [r.onMessage] : [], s = await _t({
432
+ async function At(e, t, r, a) {
433
+ const c = r != null && r.onMessage ? [r.onMessage] : [], s = await Tt({
430
434
  auth: e,
431
435
  host: t,
432
436
  externalId: 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);
@@ -455,7 +459,7 @@ function Te(e) {
455
459
  r += e[t++];
456
460
  return r;
457
461
  }
458
- function At(e, t, r) {
462
+ function bt(e, t, r) {
459
463
  if (!e.content)
460
464
  return;
461
465
  const a = {
@@ -468,9 +472,9 @@ function At(e, t, r) {
468
472
  };
469
473
  t.messages.push(a), r == null || r([...t.messages], "user");
470
474
  }
471
- function bt(e, t, r, a, c, s, o) {
475
+ function xt(e, t, r, a, c, s, o) {
472
476
  if (e === z.Transcribe && t.content) {
473
- At(t, a, c);
477
+ bt(t, a, c);
474
478
  return;
475
479
  }
476
480
  if (!(e === z.Partial || e === z.Answer))
@@ -502,7 +506,7 @@ function bt(e, t, r, a, c, s, o) {
502
506
  const p = Te(r);
503
507
  (m.content !== p || e === z.Answer) && (m.content = p, m.parts = re(p), c == null || c([...a.messages], e));
504
508
  }
505
- function xt(e, t, r, a, c) {
509
+ function Lt(e, t, r, a, c) {
506
510
  const s = {}, o = () => {
507
511
  for (const d of Object.keys(s))
508
512
  delete s[d];
@@ -518,7 +522,7 @@ function xt(e, t, r, a, c) {
518
522
  var l, w;
519
523
  if ("content" in m) {
520
524
  const p = d === P.ChatAnswer ? z.Answer : d === P.ChatAudioTranscribed ? z.Transcribe : d;
521
- bt(
525
+ xt(
522
526
  p,
523
527
  m,
524
528
  s,
@@ -532,25 +536,25 @@ function xt(e, t, r, a, c) {
532
536
  mode: t.chatMode
533
537
  });
534
538
  } else {
535
- const p = P, y = [p.StreamVideoDone, p.StreamVideoError, p.StreamVideoRejected], B = [p.StreamFailed, p.StreamVideoError, p.StreamVideoRejected], M = kt(m, a, { mode: t.chatMode });
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 });
536
540
  if (d = d, d === p.StreamVideoCreated && (e.linkTrack("agent-video", M, p.StreamVideoCreated, ["start"]), m.sentiment)) {
537
- const D = t.messages[t.messages.length - 1];
538
- if ((D == null ? void 0 : D.role) === "assistant") {
539
- const $ = { ...D, sentiment: 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 };
540
544
  t.messages[t.messages.length - 1] = $, i == null || i([...t.messages], n ?? "answer");
541
545
  }
542
546
  }
543
547
  if (y.includes(d)) {
544
- const D = d.split("/")[1];
545
- B.includes(d) ? e.track("agent-video", { ...M, event: D }) : e.linkTrack("agent-video", { ...M, event: D }, d, ["done"]);
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"]);
546
550
  }
547
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();
548
552
  }
549
553
  }
550
554
  };
551
555
  }
552
- function Lt(e, t, r, a) {
553
- const c = Ne(e, `${t}/agents/${r}`, a);
556
+ function Pt(e, t, r, a) {
557
+ const c = Ve(e, `${t}/agents/${r}`, a);
554
558
  return {
555
559
  createStream(s, o) {
556
560
  return c.post("/streams", s, { signal: o });
@@ -586,8 +590,8 @@ function Lt(e, t, r, a) {
586
590
  }
587
591
  };
588
592
  }
589
- const Pt = (e, t) => (r, a) => e && console.log(`[${t}] ${r}`, a ?? "");
590
- function jt(e, t, r) {
593
+ const jt = (e, t) => (r, a) => e && console.log(`[${t}] ${r}`, a ?? "");
594
+ function Bt(e, t, r) {
591
595
  const a = (t.timestamp - e.timestamp) / 1e3;
592
596
  return {
593
597
  duration: a,
@@ -607,7 +611,7 @@ function jt(e, t, r) {
607
611
  lowFpsCount: r
608
612
  };
609
613
  }
610
- function Bt(e) {
614
+ function $t(e) {
611
615
  return e.filter(
612
616
  (t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
613
617
  ).map((t) => {
@@ -618,7 +622,7 @@ function Bt(e) {
618
622
  };
619
623
  });
620
624
  }
621
- function $t(e) {
625
+ function zt(e) {
622
626
  var o;
623
627
  let t = "", r = 0, a = null;
624
628
  const c = /* @__PURE__ */ new Map();
@@ -705,14 +709,14 @@ function Ae(e, t, r) {
705
709
  framesPerSecond: i.framesPerSecond,
706
710
  freezeCount: i.freezeCount - e[d - 1].freezeCount,
707
711
  freezeDuration: i.freezeDuration - e[d - 1].freezeDuration
708
- }), 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);
709
713
  return {
710
714
  webRTCStats: {
711
715
  anomalies: c,
712
716
  minRtt: Math.min(...n),
713
717
  avgRtt: Me(n),
714
718
  maxRtt: Math.max(...n),
715
- aggregateReport: jt(e[0], e[e.length - 1], s),
719
+ aggregateReport: Bt(e[0], e[e.length - 1], s),
716
720
  minJitterDelayInInterval: Math.min(...o),
717
721
  maxJitterDelayInInterval: Math.max(...o),
718
722
  avgJitterDelayInInterval: Me(o)
@@ -721,14 +725,14 @@ function Ae(e, t, r) {
721
725
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
722
726
  };
723
727
  }
724
- function Ue(e, t) {
728
+ function We(e, t) {
725
729
  for (const r of e.values())
726
730
  if ((r == null ? void 0 : r.type) === "inbound-rtp" && r.kind === t)
727
731
  return r;
728
732
  return null;
729
733
  }
730
734
  const ee = 10;
731
- function cr(e, t) {
735
+ function dr(e, t) {
732
736
  let r = !1, a = !1, c = null, s = 0, o = 0, n = {};
733
737
  async function i() {
734
738
  if (r) {
@@ -738,7 +742,7 @@ function cr(e, t) {
738
742
  c = setTimeout(i, ee);
739
743
  return;
740
744
  }
741
- const m = Ue(d, "audio");
745
+ const m = We(d, "audio");
742
746
  if (!m) {
743
747
  c = setTimeout(i, ee);
744
748
  return;
@@ -767,11 +771,11 @@ function cr(e, t) {
767
771
  }
768
772
  };
769
773
  }
770
- const oe = 100, zt = Math.max(Math.ceil(400 / oe), 1), Ft = 0.25, Nt = 0.28;
771
- function Vt() {
774
+ const oe = 100, Ft = Math.max(Math.ceil(400 / oe), 1), Nt = 0.25, Vt = 0.28;
775
+ function Kt() {
772
776
  let e = 0, t, r, a = 0;
773
777
  return (c) => {
774
- const s = Ue(c, "video");
778
+ const s = We(c, "video");
775
779
  if (!s)
776
780
  return { isReceiving: !1, avgJitterDelayInInterval: a };
777
781
  const o = s.jitterBufferDelay, n = s.jitterBufferEmittedCount;
@@ -784,17 +788,17 @@ function Vt() {
784
788
  return e = i, { isReceiving: d, avgJitterDelayInInterval: a, freezeCount: s.freezeCount };
785
789
  };
786
790
  }
787
- function Kt(e, t, r, a, c) {
791
+ function Ut(e, t, r, a, c) {
788
792
  let s = null, o = [], n, i = 0, d = !1, m = te.Unknown, l = te.Unknown, w = 0, p = 0;
789
- const y = Vt();
793
+ const y = Kt();
790
794
  async function B() {
791
795
  const M = await e();
792
796
  if (!M)
793
797
  return;
794
- const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: T } = y(M), q = $t(M);
795
- if (D)
796
- i = 0, w = T - p, l = $ < Ft ? te.Strong : $ > Nt && 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);
797
- else if (d && (i++, i >= zt)) {
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)) {
798
802
  const J = Ae(o, oe, n);
799
803
  a == null || a(k.Stop, J), t() || r(), p = T, d = !1;
800
804
  }
@@ -809,7 +813,7 @@ function Kt(e, t, r, a, c) {
809
813
  getReport: () => Ae(o, oe, n)
810
814
  };
811
815
  }
812
- const Ut = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
816
+ const Wt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
813
817
  function be(e) {
814
818
  switch (e) {
815
819
  case "connected":
@@ -830,7 +834,7 @@ function be(e) {
830
834
  return L.New;
831
835
  }
832
836
  }
833
- const Wt = (e) => (t) => {
837
+ const Jt = (e) => (t) => {
834
838
  const [r, a = ""] = t.split(/:(.+)/);
835
839
  try {
836
840
  const c = JSON.parse(a);
@@ -839,7 +843,7 @@ const Wt = (e) => (t) => {
839
843
  return e("Failed to parse data channel message, returning data as string", { subject: r, rawData: a, error: c }), { subject: r, data: a };
840
844
  }
841
845
  };
842
- function Jt({
846
+ function Ot({
843
847
  statsSignal: e,
844
848
  dataChannelSignal: t,
845
849
  onVideoStateChange: r,
@@ -848,7 +852,7 @@ function Jt({
848
852
  }) {
849
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));
850
854
  }
851
- function Ot({
855
+ function Ht({
852
856
  statsSignal: e,
853
857
  dataChannelSignal: t,
854
858
  onVideoStateChange: r,
@@ -867,7 +871,7 @@ function xe({
867
871
  report: s,
868
872
  log: o
869
873
  }) {
870
- 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({
871
875
  statsSignal: e,
872
876
  dataChannelSignal: t,
873
877
  onVideoStateChange: r,
@@ -876,11 +880,11 @@ function xe({
876
880
  log: o
877
881
  });
878
882
  }
879
- 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) {
880
884
  var E;
881
- const i = Pt(r, "WebRTCStreamingManager"), d = Wt(i);
885
+ const i = jt(r, "WebRTCStreamingManager"), d = Jt(i);
882
886
  let m = !1, l = !1, w = k.Stop, p = k.Stop;
883
- const { startConnection: y, sendStreamRequest: B, close: M, createStream: D, addIceCandidate: $ } = Lt(
887
+ const { startConnection: y, sendStreamRequest: B, close: M, createStream: I, addIceCandidate: $ } = Pt(
884
888
  c,
885
889
  s,
886
890
  e,
@@ -892,9 +896,9 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
892
896
  session_id: V,
893
897
  fluent: X,
894
898
  interrupt_enabled: O
895
- } = await D(t, n);
899
+ } = await I(t, n);
896
900
  (E = a.onStreamCreated) == null || E.call(a, { stream_id: T, session_id: V, agent_id: e });
897
- const I = new Ut({ iceServers: J }), Y = I.createDataChannel("JanusDataChannel");
901
+ const D = new Wt({ iceServers: J }), Y = D.createDataChannel("JanusDataChannel");
898
902
  if (!V)
899
903
  throw new Error("Could not create session_id");
900
904
  const K = X ? W.Fluent : W.Legacy;
@@ -904,8 +908,8 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
904
908
  const ae = t.stream_warmup && !X, ie = () => m, u = () => {
905
909
  var f;
906
910
  m = !0, l && (i("CALLBACK: onConnectionStateChange(Connected)"), (f = a.onConnectionStateChange) == null || f.call(a, L.Connected));
907
- }, g = Kt(
908
- () => I.getStats(),
911
+ }, g = Ut(
912
+ () => D.getStats(),
909
913
  ie,
910
914
  u,
911
915
  (f, h) => xe({
@@ -922,7 +926,7 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
922
926
  return (h = a.onConnectivityStateChange) == null ? void 0 : h.call(a, f);
923
927
  }
924
928
  );
925
- g.start(), I.onicecandidate = (f) => {
929
+ g.start(), D.onicecandidate = (f) => {
926
930
  var h;
927
931
  i("peerConnection.onicecandidate", f);
928
932
  try {
@@ -975,17 +979,17 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
975
979
  var _;
976
980
  const { subject: h, data: A } = d(f.data);
977
981
  (_ = j[h]) == null || _.call(j, h, A);
978
- }, I.oniceconnectionstatechange = () => {
982
+ }, D.oniceconnectionstatechange = () => {
979
983
  var h;
980
- i("peerConnection.oniceconnectionstatechange => " + I.iceConnectionState);
981
- const f = be(I.iceConnectionState);
984
+ i("peerConnection.oniceconnectionstatechange => " + D.iceConnectionState);
985
+ const f = be(D.iceConnectionState);
982
986
  f !== L.Connected && ((h = a.onConnectionStateChange) == null || h.call(a, f));
983
- }, I.ontrack = (f) => {
987
+ }, D.ontrack = (f) => {
984
988
  var h;
985
989
  i("peerConnection.ontrack", f), i("CALLBACK: onSrcObjectReady"), (h = a.onSrcObjectReady) == null || h.call(a, f.streams[0]);
986
- }, await I.setRemoteDescription(q), i("set remote description OK");
987
- const F = await I.createAnswer();
988
- i("create answer OK"), await I.setLocalDescription(F), i("set local description OK"), await y(T, F, V, n), i("start connection OK");
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");
989
993
  function N(f) {
990
994
  var h, A;
991
995
  if (!m || Y.readyState !== "open") {
@@ -1014,13 +1018,13 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
1014
1018
  async disconnect() {
1015
1019
  var f;
1016
1020
  if (T) {
1017
- const h = be(I.iceConnectionState);
1018
- if (I) {
1021
+ const h = be(D.iceConnectionState);
1022
+ if (D) {
1019
1023
  if (h === L.New) {
1020
1024
  g.stop();
1021
1025
  return;
1022
1026
  }
1023
- 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;
1024
1028
  }
1025
1029
  try {
1026
1030
  h === L.Connected && await M(T, V).catch((A) => {
@@ -1060,18 +1064,18 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
1060
1064
  };
1061
1065
  }
1062
1066
  var ge = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(ge || {});
1063
- async function qt(e, t, r, a) {
1067
+ async function Xt(e, t, r, a) {
1064
1068
  const c = e.id;
1065
1069
  switch (t.version) {
1066
1070
  case "v1": {
1067
1071
  const { version: s, ...o } = t;
1068
- return Ht(c, o, r, a);
1072
+ return qt(c, o, r, a);
1069
1073
  }
1070
1074
  case "v2": {
1071
1075
  const { version: s, ...o } = t;
1072
1076
  switch (o.transport.provider) {
1073
1077
  case pe.Livekit:
1074
- const { createLiveKitStreamingManager: n } = await import("./livekit-manager-_ObM1JYd.js");
1078
+ const { createLiveKitStreamingManager: n } = await import("./livekit-manager-vNfdN45F.js");
1075
1079
  return n(c, o, r);
1076
1080
  default:
1077
1081
  throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
@@ -1081,15 +1085,15 @@ async function qt(e, t, r, a) {
1081
1085
  throw new Error(`Invalid stream version: ${t.version}`);
1082
1086
  }
1083
1087
  }
1084
- const Xt = "cht";
1085
- function Yt() {
1088
+ const Yt = "cht";
1089
+ function Gt() {
1086
1090
  return {
1087
1091
  transport: {
1088
1092
  provider: pe.Livekit
1089
1093
  }
1090
1094
  };
1091
1095
  }
1092
- function Gt(e) {
1096
+ function Qt(e) {
1093
1097
  var c, s;
1094
1098
  const { streamOptions: t } = e ?? {}, r = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
1095
1099
  plan: (s = e.mixpanelAdditionalProperties) == null ? void 0 : s.plan
@@ -1102,16 +1106,16 @@ function Gt(e) {
1102
1106
  fluent: t == null ? void 0 : t.fluent
1103
1107
  }, ...r && { end_user_data: r } };
1104
1108
  }
1105
- function Qt(e, t) {
1106
- 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) };
1107
1111
  }
1108
- function Zt(e, t, r) {
1112
+ function er(e, t, r) {
1109
1113
  r.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
1110
1114
  }
1111
- function er(e, t, r, a, c) {
1112
- c === W.Fluent ? tr(e, t, r, a, c) : rr(e, t, r, a, c);
1113
- }
1114
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) {
1115
1119
  e === k.Start ? a.track("stream-session", { event: "start", "stream-type": c }) : e === k.Stop && a.track("stream-session", {
1116
1120
  event: "stop",
1117
1121
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
@@ -1135,7 +1139,7 @@ function Le(e, t, r, a, c) {
1135
1139
  [P.StreamVideoDone]
1136
1140
  );
1137
1141
  }
1138
- function rr(e, t, r, a, c) {
1142
+ function nr(e, t, r, a, c) {
1139
1143
  e === k.Start ? a.linkTrack(
1140
1144
  "agent-video",
1141
1145
  { event: "start", latency: H.get(!0), "stream-type": c },
@@ -1154,7 +1158,7 @@ function rr(e, t, r, a, c) {
1154
1158
  [P.StreamVideoDone]
1155
1159
  );
1156
1160
  }
1157
- function nr(e, t, r) {
1161
+ function ar(e, t, r) {
1158
1162
  const a = {
1159
1163
  call_id: t.call_id,
1160
1164
  name: t.name
@@ -1175,13 +1179,13 @@ function Pe(e, t, r, a) {
1175
1179
  return H.reset(), _e.update(), new Promise(async (c, s) => {
1176
1180
  try {
1177
1181
  let o, n = !1;
1178
- const i = Qt(e, t);
1182
+ const i = Zt(e, t);
1179
1183
  r.enrich({
1180
1184
  "stream-version": i.version.toString()
1181
1185
  });
1182
1186
  let d = null;
1183
1187
  const m = e.presenter.type === "expressive";
1184
- o = await qt(
1188
+ o = await Xt(
1185
1189
  e,
1186
1190
  i,
1187
1191
  {
@@ -1191,11 +1195,11 @@ function Pe(e, t, r, a) {
1191
1195
  ...t.callbacks,
1192
1196
  onConnectionStateChange: (l, w) => {
1193
1197
  var p, y;
1194
- (y = (p = t.callbacks).onConnectionStateChange) == null || y.call(p, l), Zt(l, w, r), l === L.Connected && (o ? c(o) : n = !0);
1198
+ (y = (p = t.callbacks).onConnectionStateChange) == null || y.call(p, l), er(l, w, r), l === L.Connected && (o ? c(o) : n = !0);
1195
1199
  },
1196
1200
  onVideoStateChange: (l, w) => {
1197
1201
  var p, y;
1198
- (y = (p = t.callbacks).onVideoStateChange) == null || y.call(p, l), er(
1202
+ (y = (p = t.callbacks).onVideoStateChange) == null || y.call(p, l), tr(
1199
1203
  l,
1200
1204
  e,
1201
1205
  w,
@@ -1229,7 +1233,7 @@ function Pe(e, t, r, a) {
1229
1233
  },
1230
1234
  onToolEvent: ((l, w) => {
1231
1235
  var p, y;
1232
- (y = (p = t.callbacks).onToolEvent) == null || y.call(p, l, w), nr(l, w, r);
1236
+ (y = (p = t.callbacks).onToolEvent) == null || y.call(p, l, w), ar(l, w, r);
1233
1237
  })
1234
1238
  }
1235
1239
  },
@@ -1240,11 +1244,11 @@ function Pe(e, t, r, a) {
1240
1244
  }
1241
1245
  });
1242
1246
  }
1243
- async function ar(e, t, r, a, c) {
1247
+ async function ir(e, t, r, a, c) {
1244
1248
  var m, l, w, p;
1245
1249
  const s = async () => {
1246
1250
  if (he(e.presenter.type)) {
1247
- const y = await Pe(e, t, a), B = `${Xt}_${y.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
1251
+ const y = await Pe(e, t, a), B = `${Yt}_${y.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
1248
1252
  return { chatResult: {
1249
1253
  chatMode: x.Functional,
1250
1254
  chat: {
@@ -1263,27 +1267,27 @@ async function ar(e, t, r, a, c) {
1263
1267
  const y = new AbortController(), B = y.signal;
1264
1268
  let M;
1265
1269
  try {
1266
- const D = Ke(
1270
+ const I = Ue(
1267
1271
  e,
1268
1272
  r,
1269
1273
  a,
1270
1274
  t.mode,
1271
1275
  t.persistentChat,
1272
1276
  c
1273
- ), $ = Pe(e, t, a, B).then((J) => (M = J, J)), [T, q] = await Promise.all([D, $]);
1277
+ ), $ = Pe(e, t, a, B).then((J) => (M = J, J)), [T, q] = await Promise.all([I, $]);
1274
1278
  return { chatResult: T, streamingManager: q };
1275
- } catch (D) {
1279
+ } catch (I) {
1276
1280
  throw y.abort(), M && await M.disconnect().catch(() => {
1277
- }), D;
1281
+ }), I;
1278
1282
  }
1279
1283
  }
1280
1284
  }, { chatResult: o, streamingManager: n } = await s(), { chat: i, chatMode: d } = o;
1281
- 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 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 };
1282
1286
  }
1283
- async function dr(e, t) {
1287
+ async function lr(e, t) {
1284
1288
  var Y, K, ae, ie;
1285
1289
  let r = !0;
1286
- 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 = {
1287
1291
  messages: [],
1288
1292
  chatMode: o
1289
1293
  }, i = Dt({
@@ -1296,15 +1300,15 @@ async function dr(e, t) {
1296
1300
  Ee(() => {
1297
1301
  i.track("agent-sdk", { event: "init" }, d);
1298
1302
  });
1299
- 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);
1300
1304
  t.debug = t.debug || ((Y = l == null ? void 0 : l.advanced_settings) == null ? void 0 : Y.ui_debug_mode);
1301
1305
  const w = he(l.presenter.type);
1302
- i.enrich(Ct(l));
1303
- const { onMessage: p, clearQueue: y } = xt(i, n, t, l, () => {
1306
+ i.enrich(St(l));
1307
+ const { onMessage: p, clearQueue: y } = Lt(i, n, t, l, () => {
1304
1308
  var u, g, v;
1305
1309
  (u = n.socketManager) == null || u.disconnect(), (v = (g = t.callbacks).onConnectionStateChange) == null || v.call(g, L.Disconnected);
1306
1310
  });
1307
- 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");
1308
1312
  const B = (u) => {
1309
1313
  }, M = ({ type: u }) => {
1310
1314
  var v, C, S, R;
@@ -1315,10 +1319,10 @@ async function dr(e, t) {
1315
1319
  video_duration_to_interrupt: fe.get(!0),
1316
1320
  message_duration_to_interrupt: H.get(!0)
1317
1321
  }), g.interrupted = !0, (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...n.messages], "answer"), n.streamingManager.interrupt(u);
1318
- }, D = /* @__PURE__ */ new Map();
1322
+ }, I = /* @__PURE__ */ new Map();
1319
1323
  function $(u) {
1320
1324
  return async (g) => {
1321
- const v = D.get(u);
1325
+ const v = I.get(u);
1322
1326
  if (!v)
1323
1327
  throw new Error(`No handler registered for client tool: ${u}`);
1324
1328
  try {
@@ -1331,32 +1335,32 @@ async function dr(e, t) {
1331
1335
  }
1332
1336
  function T() {
1333
1337
  var u, g, v, C;
1334
- for (const [S] of D)
1338
+ for (const [S] of I)
1335
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));
1336
1340
  }
1337
1341
  function q(u, g) {
1338
1342
  var C, S;
1339
- const v = !D.has(u);
1340
- D.set(u, g), v && ((S = (C = n.streamingManager) == null ? void 0 : C.registerRpcMethod) == null || S.call(C, u, $(u)));
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)));
1341
1345
  }
1342
1346
  function J(u) {
1343
1347
  var g, v;
1344
- 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);
1345
1349
  }
1346
1350
  const V = Date.now();
1347
1351
  Ee(() => {
1348
- i.track("agent-sdk", { event: "loaded", ...yt(l) }, V);
1352
+ i.track("agent-sdk", { event: "loaded", ...Ct(l) }, V);
1349
1353
  });
1350
1354
  async function X(u) {
1351
1355
  var j, F, N, E, f, h, A;
1352
- (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"));
1353
- const g = o === x.DirectPlayback || w ? Promise.resolve(void 0) : Tt(
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(
1354
1358
  t.auth,
1355
1359
  c,
1356
1360
  { onMessage: p, onError: t.callbacks.onError },
1357
1361
  t.externalId
1358
- ), v = ue(
1359
- () => ar(
1362
+ ), v = me(
1363
+ () => ir(
1360
1364
  l,
1361
1365
  {
1362
1366
  ...t,
@@ -1373,26 +1377,26 @@ async function dr(e, t) {
1373
1377
  ),
1374
1378
  {
1375
1379
  limit: 3,
1376
- timeout: it,
1380
+ timeout: ot,
1377
1381
  timeoutErrorMessage: "Timeout initializing the stream",
1378
1382
  shouldRetryFn: (_) => (_ == null ? void 0 : _.message) !== "Could not connect" && _.status !== 429 && (_ == null ? void 0 : _.message) !== "InsufficientCreditsError",
1379
1383
  delayMs: 1e3
1380
1384
  }
1381
1385
  ).catch((_) => {
1382
1386
  var b, U;
1383
- throw I(x.Maintenance), (U = (b = t.callbacks).onConnectionStateChange) == null || U.call(b, L.Fail), _;
1387
+ throw D(x.Maintenance), (U = (b = t.callbacks).onConnectionStateChange) == null || U.call(b, L.Fail), _;
1384
1388
  }), [C, { streamingManager: S, chat: R }] = await Promise.all([g, v]);
1385
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({
1386
1390
  chatId: R == null ? void 0 : R.id,
1387
1391
  streamId: S == null ? void 0 : S.streamId,
1388
1392
  mode: n.chatMode
1389
- }), I((R == null ? void 0 : R.chat_mode) ?? o);
1393
+ }), D((R == null ? void 0 : R.chat_mode) ?? o);
1390
1394
  }
1391
1395
  async function O() {
1392
1396
  var u, g, v, C;
1393
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);
1394
1398
  }
1395
- async function I(u) {
1399
+ async function D(u) {
1396
1400
  var g, v;
1397
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));
1398
1402
  }
@@ -1408,7 +1412,7 @@ async function dr(e, t) {
1408
1412
  },
1409
1413
  starterMessages: ((ie = l.knowledge) == null ? void 0 : ie.starter_message) || [],
1410
1414
  getSTTToken: () => m.getSTTToken(l.id),
1411
- changeMode: I,
1415
+ changeMode: D,
1412
1416
  enrichAnalytics: i.enrich,
1413
1417
  async connect() {
1414
1418
  await X(!0), i.track("agent-chat", {
@@ -1463,24 +1467,24 @@ async function dr(e, t) {
1463
1467
  async chat(u) {
1464
1468
  var S, R, j, F, N;
1465
1469
  const g = () => {
1466
- if (ze(o))
1467
- throw new G(`${o} is enabled, chat is disabled`);
1470
+ if (Ne(o))
1471
+ throw new Q(`${o} is enabled, chat is disabled`);
1468
1472
  if (u.length >= 800)
1469
- throw new G("Message cannot be more than 800 characters");
1473
+ throw new Q("Message cannot be more than 800 characters");
1470
1474
  if (u.length === 0)
1471
- throw new G("Message cannot be empty");
1475
+ throw new Q("Message cannot be empty");
1472
1476
  if (n.chatMode === x.Maintenance)
1473
- throw new G("Chat is in maintenance mode");
1477
+ throw new Q("Chat is in maintenance mode");
1474
1478
  if (![x.TextOnly, x.Playground].includes(n.chatMode)) {
1475
1479
  if (!n.streamingManager)
1476
- throw new G("Streaming manager is not initialized");
1480
+ throw new Q("Streaming manager is not initialized");
1477
1481
  if (!n.chat)
1478
- throw new G("Chat is not initialized");
1482
+ throw new Q("Chat is not initialized");
1479
1483
  }
1480
1484
  }, v = async () => {
1481
1485
  var E, f;
1482
1486
  if (!n.chat) {
1483
- const h = await Ke(
1487
+ const h = await Ue(
1484
1488
  l,
1485
1489
  m,
1486
1490
  i,
@@ -1488,13 +1492,13 @@ async function dr(e, t) {
1488
1492
  t.persistentChat
1489
1493
  );
1490
1494
  if (!h.chat)
1491
- throw new He(n.chatMode, !!t.persistentChat);
1495
+ throw new qe(n.chatMode, !!t.persistentChat);
1492
1496
  n.chat = h.chat, (f = (E = t.callbacks).onNewChat) == null || f.call(E, n.chat.id);
1493
1497
  }
1494
1498
  return n.chat.id;
1495
1499
  }, C = async (E, f) => {
1496
1500
  const h = n.chatMode === x.Playground;
1497
- return ue(w && !h ? async () => {
1501
+ return me(w && !h ? async () => {
1498
1502
  var b, U;
1499
1503
  return await ((U = (b = n.streamingManager) == null ? void 0 : b.sendTextMessage) == null ? void 0 : U.call(b, u)), Promise.resolve({});
1500
1504
  } : async () => {
@@ -1506,10 +1510,10 @@ async function dr(e, t) {
1506
1510
  chatMode: n.chatMode,
1507
1511
  streamId: (b = n.streamingManager) == null ? void 0 : b.streamId,
1508
1512
  sessionId: (U = n.streamingManager) == null ? void 0 : U.sessionId,
1509
- messages: E.map(({ matches: We, ...se }) => se)
1513
+ messages: E.map(({ matches: Je, ...se }) => se)
1510
1514
  },
1511
1515
  {
1512
- ...Ve(n.chatMode),
1516
+ ...Ke(n.chatMode),
1513
1517
  skipErrorHandler: !0
1514
1518
  }
1515
1519
  );
@@ -1527,7 +1531,7 @@ async function dr(e, t) {
1527
1531
  };
1528
1532
  try {
1529
1533
  y(), g(), n.messages.push({
1530
- id: Q(),
1534
+ id: G(),
1531
1535
  role: "user",
1532
1536
  content: u,
1533
1537
  parts: re(u),
@@ -1535,7 +1539,7 @@ async function dr(e, t) {
1535
1539
  }), (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...n.messages], "user");
1536
1540
  const E = await v(), f = await C([...n.messages], E);
1537
1541
  return f.result && n.messages.push({
1538
- id: Q(),
1542
+ id: G(),
1539
1543
  role: "assistant",
1540
1544
  content: f.result,
1541
1545
  parts: re(f.result),
@@ -1614,12 +1618,12 @@ async function dr(e, t) {
1614
1618
  }
1615
1619
  const v = g();
1616
1620
  if (i.track("agent-speak", v), H.update(), n.messages && v.type === "text" && (n.messages.push({
1617
- id: Q(),
1621
+ id: G(),
1618
1622
  role: "assistant",
1619
1623
  content: v.input,
1620
1624
  parts: re(v.input),
1621
1625
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1622
- }), (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))
1623
1627
  return {
1624
1628
  duration: 0,
1625
1629
  video_id: "",
@@ -1640,35 +1644,35 @@ async function dr(e, t) {
1640
1644
  export {
1641
1645
  ne as A,
1642
1646
  z as C,
1643
- rt as D,
1644
- tt as K,
1645
- Ge as P,
1646
- Ze as R,
1647
+ nt as D,
1648
+ rt as K,
1649
+ Qe as P,
1650
+ et as R,
1647
1651
  P as S,
1648
1652
  pe as T,
1649
- Ye as U,
1650
- G as V,
1651
- Xe as W,
1652
- Pt as a,
1653
+ Ge as U,
1654
+ Q as V,
1655
+ Ye as W,
1656
+ jt as a,
1653
1657
  W as b,
1654
- Ne as c,
1658
+ Ve as c,
1655
1659
  de as d,
1656
1660
  L as e,
1657
1661
  te as f,
1658
- Kt as g,
1659
- cr as h,
1662
+ Ut as g,
1663
+ dr as h,
1660
1664
  k as i,
1661
- Qe as j,
1662
- He as k,
1665
+ Ze as j,
1666
+ qe as k,
1663
1667
  H as l,
1664
1668
  x as m,
1665
- or as n,
1666
- qe as o,
1667
- nt as p,
1668
- et as q,
1669
+ cr as n,
1670
+ Xe as o,
1671
+ at as p,
1672
+ tt as q,
1669
1673
  je as r,
1670
- at as s,
1671
- dr as t,
1672
- sr as u,
1673
- gt as v
1674
+ it as s,
1675
+ lr as t,
1676
+ or as u,
1677
+ ht as v
1674
1678
  };