@d-id/client-sdk 1.1.68 → 1.1.69

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 We = Object.defineProperty;
2
- var Je = (e, t, r) => t in e ? We(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var Z = (e, t, r) => Je(e, typeof t != "symbol" ? t + "" : t, r);
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 Oe extends ce {
13
+ class qe extends ce {
14
14
  constructor(t, r) {
15
15
  super({
16
16
  kind: "ChatCreationFailed",
@@ -18,25 +18,25 @@ class Oe extends ce {
18
18
  });
19
19
  }
20
20
  }
21
- class He 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 qe extends ce {
33
+ class Ye extends ce {
34
34
  constructor(t) {
35
35
  super({ kind: "WSError", description: t });
36
36
  }
37
37
  }
38
- var Xe = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(Xe || {}), Ye = /* @__PURE__ */ ((e) => (e.TRIAL = "deid-trial", e.PRO = "deid-pro", e.ENTERPRISE = "deid-enterprise", e.LITE = "deid-lite", e.ADVANCED = "deid-advanced", e.BUILD = "deid-api-build", e.LAUNCH = "deid-api-launch", e.SCALE = "deid-api-scale", e))(Ye || {}), Ge = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(Ge || {}), Qe = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(Qe || {}), x = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(x || {}), U = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(U || {}), Ze = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(Ze || {}), et = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(et || {}), tt = /* @__PURE__ */ ((e) => (e.Pdf = "pdf", e.Text = "text", e.Html = "html", e.Word = "word", e.Json = "json", e.Markdown = "markdown", e.Csv = "csv", e.Excel = "excel", e.Powerpoint = "powerpoint", e.Archive = "archive", e.Image = "image", e.Audio = "audio", e.Video = "video", e))(tt || {}), Pe = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Pe || {});
39
- const sr = (e) => {
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 S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), te = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(te || {}), ne = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e.ToolActive = "TOOL_ACTIVE", e))(ne || {}), P = /* @__PURE__ */ ((e) => (e.ChatAnswer = "chat/answer", e.ChatPartial = "chat/partial", e.ChatAudioTranscribed = "chat/audio-transcribed", e.StreamDone = "stream/done", e.StreamStarted = "stream/started", e.StreamFailed = "stream/error", e.StreamReady = "stream/ready", e.StreamCreated = "stream/created", e.StreamInterrupt = "stream/interrupt", e.StreamVideoCreated = "stream-video/started", e.StreamVideoDone = "stream-video/done", e.StreamVideoError = "stream-video/error", e.StreamVideoRejected = "stream-video/rejected", e.ToolCallStarted = "tool-call/started", e.ToolCallDone = "tool-call/done", e.ToolCallError = "tool-call/error", e))(P || {}), L = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnecting = "disconnecting", e.Disconnected = "disconnected", e))(L || {}), W = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(W || {}), he = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(he || {}), rt = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(rt || {}), nt = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(nt || {});
52
- const at = 45 * 1e3, it = "X-Playground-Chat", de = "https://api.d-id.com", st = "wss://notifications.d-id.com", ot = "79f81a83a67430be2bc0fd61042b8faa", or = (...e) => {
53
- }, je = (e) => new Promise((t) => setTimeout(t, e)), Q = (e = 16) => {
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
- }, Be = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, ct = (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 at = 45 * 1e3, it = "X-Playground-Chat", de = "https://api.d-id.com", st =
62
86
  case "talk":
63
87
  return "v2";
64
88
  }
65
- }, dt = (e) => e.type === "talk" ? e.source_url : e.presenter_id, pe = (e) => e === Pe.Expressive, lt = (e) => [x.TextOnly, x.Playground, x.Maintenance].includes(e), $e = (e) => e && [x.DirectPlayback, x.Off].includes(e), Se = /\[!\[([^\[\]]*)\]\(([^)\s]+)\)\]\(([^)\s]+)\)/g, ke = /!\[([^\[\]]*)\]\(([^)\s]+)\)/g, ut = [".mp4", ".webm", ".mkv", ".mov", ".m4v", ".ogv"];
66
- function mt(e) {
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 ut.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 ft(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 ft(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
- mt(o) ? i = { type: "video", src: o, alt: n } : (i = { type: "image", src: o, alt: n }, o.toLowerCase().endsWith(".gif") && (i.mimeType = "image/gif")), t.push({ index: r.index, length: r[0].length, part: i });
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 ft(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 ft(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 = ft(e)), le;
135
+ return e === De || (De = e, le = ht(e)), le;
112
136
  }
113
- function gt(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 gt(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,47 +158,27 @@ async function ue(e, t) {
134
158
  try {
135
159
  if (!r.timeout)
136
160
  return await e();
137
- const { promise: s, clear: o } = gt(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)
141
165
  throw s;
142
- await je(r.delayMs), r.onRetry(s);
166
+ await Be(r.delayMs), r.onRetry(s);
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 ze(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 pt = (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 Fe(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 pt(
181
+ d = await vt(
178
182
  () => fetch(t + (s != null && s.startsWith("/") ? s : `/${s}`), {
179
183
  ...i,
180
184
  headers: {
@@ -209,8 +213,8 @@ function Fe(e, t = de, r, a) {
209
213
  }
210
214
  };
211
215
  }
212
- function wt(e, t = de, r, a) {
213
- const c = Fe(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 wt(e, t = de, r, a) {
247
251
  }
248
252
  };
249
253
  }
250
- function vt(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 vt(e) {
258
262
  isMobile: `${t() == "Mobile"}`,
259
263
  browser: navigator.userAgent,
260
264
  origin: window.location.origin,
261
- agentType: Be(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 yt(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: Be(e.presenter),
273
- presenterType: ct(e.presenter),
274
- presenter: dt(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 yt(e) {
290
294
  ...e.access === "public" ? { from: "agent-template" } : {}
291
295
  };
292
296
  }
293
- const Ct = (e) => e.reduce((t, r) => t + r, 0), Me = (e) => Ct(e) / e.length;
294
- function St(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 St(e, t, r) {
305
309
  function Ee(e) {
306
310
  "requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
307
311
  }
308
- const kt = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
309
- function Rt(e) {
312
+ const It = "https://api-js.mixpanel.com/track/?verbose=1&ip=1";
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 Rt(e) {
350
354
  ])
351
355
  })
352
356
  };
353
- return fetch(kt, 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 Ne(e) {
381
- return e === x.Playground ? { headers: { [it]: "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 Ve(e, t, r, a, c = !1, s) {
387
+ async function Ue(e, t, r, a, c = !1, s) {
384
388
  try {
385
- return !s && !$e(a) && (s = await t.newChat(e.id, { persist: c }, Ne(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 Dt(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 Dt = (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,10 +403,10 @@ const Dt = (e) => {
399
403
  return "UnknownError";
400
404
  }
401
405
  };
402
- function It(e) {
406
+ function Et(e) {
403
407
  return e && e.length > 0 ? e : [];
404
408
  }
405
- function Mt(e) {
409
+ function _t(e) {
406
410
  return new Promise((t, r) => {
407
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) => {
@@ -412,28 +416,28 @@ function Mt(e) {
412
416
  };
413
417
  });
414
418
  }
415
- async function Et(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 Mt(e);
424
+ r = await _t(e);
421
425
  } catch (c) {
422
426
  if (a === t)
423
427
  throw c;
424
- await je(a * 500);
428
+ await Be(a * 500);
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 Et({
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 qe(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 Tt(e, t, r, a) {
447
451
  subscribeToEvents: (o) => c.push(o)
448
452
  };
449
453
  }
450
- function _t(e) {
454
+ function Te(e) {
451
455
  if (e.answer !== void 0)
452
456
  return e.answer;
453
457
  let t = 0, r = "";
@@ -458,9 +462,7 @@ function _t(e) {
458
462
  function bt(e, t, r) {
459
463
  if (!e.content)
460
464
  return;
461
- const a = t.messages[t.messages.length - 1];
462
- (a == null ? void 0 : a.role) === "assistant" && !a.interrupted && (a.interrupted = !0);
463
- const c = {
465
+ const a = {
464
466
  id: e.id || `user-${Date.now()}`,
465
467
  role: e.role,
466
468
  content: e.content,
@@ -468,73 +470,91 @@ function bt(e, t, r) {
468
470
  created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
469
471
  transcribed: !0
470
472
  };
471
- t.messages.push(c), r == null || r([...t.messages], "user");
473
+ t.messages.push(a), r == null || r([...t.messages], "user");
472
474
  }
473
- function At(e, t, r, a, c, s) {
474
- if (e === U.Transcribe && t.content) {
475
+ function xt(e, t, r, a, c, s, o) {
476
+ if (e === z.Transcribe && t.content) {
475
477
  bt(t, a, c);
476
478
  return;
477
479
  }
478
- if (!(e === U.Partial || e === U.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")
479
484
  return;
480
- const o = a.messages[a.messages.length - 1], n = t.id && (o == null ? void 0 : o.role) === "assistant" && o.id !== t.id;
481
- let i;
482
- if ((o == null ? void 0 : o.role) === "assistant" && !n)
483
- i = o;
484
- else if (!o || o.transcribed && o.role === "user" || n)
485
- n && s(), i = {
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 = {
486
491
  id: t.id || `assistant-${Date.now()}`,
487
492
  role: t.role || "assistant",
488
493
  content: t.content || "",
489
494
  parts: [],
490
495
  created_at: t.created_at || (/* @__PURE__ */ new Date()).toISOString()
491
- }, a.messages.push(i);
496
+ }, a.messages.push(m);
492
497
  else
493
498
  return;
494
- const { content: d, sequence: m } = t;
495
- e === U.Partial ? r[m] = d : r.answer = d;
496
- const l = _t(r);
497
- (i.content !== l || e === U.Answer) && (i.content = l, i.parts = re(l), c == null || c([...a.messages], e));
499
+ const { content: l, sequence: w } = t;
500
+ if (e === z.Partial)
501
+ r[w] = l;
502
+ else {
503
+ const y = Te(r);
504
+ !!(l && l.length < y.length) && (m.interrupted = !0), r.answer = l;
505
+ }
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));
498
508
  }
499
- function xt(e, t, r, a, c) {
500
- let s = {};
501
- const o = () => s = {};
502
- let n = "answer";
509
+ function Lt(e, t, r, a, c) {
510
+ const s = {}, o = () => {
511
+ for (const d of Object.keys(s))
512
+ delete s[d];
513
+ };
514
+ let n = null;
503
515
  const i = (d, m) => {
504
516
  var l, w;
505
- m === "user" && o(), n = m, (w = (l = r.callbacks).onNewMessage) == null || w.call(l, d, m);
517
+ m === "user" && o(), (w = (l = r.callbacks).onNewMessage) == null || w.call(l, d, m);
506
518
  };
507
519
  return {
508
520
  clearQueue: o,
509
521
  onMessage: (d, m) => {
510
522
  var l, w;
511
523
  if ("content" in m) {
512
- const v = d === P.ChatAnswer ? U.Answer : d === P.ChatAudioTranscribed ? U.Transcribe : d;
513
- At(v, m, s, t, i, o), v === U.Answer && e.track("agent-message-received", {
524
+ const p = d === P.ChatAnswer ? z.Answer : d === P.ChatAudioTranscribed ? z.Transcribe : d;
525
+ xt(
526
+ p,
527
+ m,
528
+ s,
529
+ t,
530
+ i,
531
+ o,
532
+ n
533
+ ), p === z.Partial ? n = "partial" : p === z.Answer && (n = "answer", o()), p === z.Answer && e.track("agent-message-received", {
514
534
  content: m.content,
515
535
  messages: t.messages.length,
516
536
  mode: t.chatMode
517
537
  });
518
538
  } else {
519
- const v = P, k = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], B = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], M = St(m, a, { mode: t.chatMode });
520
- if (d = d, d === v.StreamVideoCreated && (e.linkTrack("agent-video", M, v.StreamVideoCreated, ["start"]), m.sentiment)) {
521
- const D = t.messages[t.messages.length - 1];
522
- if ((D == null ? void 0 : D.role) === "assistant") {
523
- const $ = { ...D, sentiment: m.sentiment };
524
- t.messages[t.messages.length - 1] = $, i == null || i([...t.messages], n);
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 };
544
+ t.messages[t.messages.length - 1] = $, i == null || i([...t.messages], n ?? "answer");
525
545
  }
526
546
  }
527
- if (k.includes(d)) {
528
- const D = d.split("/")[1];
529
- 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"]);
530
550
  }
531
- B.includes(d) && ((w = (l = r.callbacks).onError) == null || w.call(l, new Error(`Stream failed with event ${d}`), { data: m })), m.event === v.StreamDone && c();
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();
532
552
  }
533
553
  }
534
554
  };
535
555
  }
536
- function Lt(e, t, r, a) {
537
- const c = Fe(e, `${t}/agents/${r}`, a);
556
+ function Pt(e, t, r, a) {
557
+ const c = Ve(e, `${t}/agents/${r}`, a);
538
558
  return {
539
559
  createStream(s, o) {
540
560
  return c.post("/streams", s, { signal: o });
@@ -570,8 +590,8 @@ function Lt(e, t, r, a) {
570
590
  }
571
591
  };
572
592
  }
573
- const Pt = (e, t) => (r, a) => e && console.log(`[${t}] ${r}`, a ?? "");
574
- function jt(e, t, r) {
593
+ const jt = (e, t) => (r, a) => e && console.log(`[${t}] ${r}`, a ?? "");
594
+ function Bt(e, t, r) {
575
595
  const a = (t.timestamp - e.timestamp) / 1e3;
576
596
  return {
577
597
  duration: a,
@@ -591,7 +611,7 @@ function jt(e, t, r) {
591
611
  lowFpsCount: r
592
612
  };
593
613
  }
594
- function Bt(e) {
614
+ function $t(e) {
595
615
  return e.filter(
596
616
  (t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
597
617
  ).map((t) => {
@@ -602,7 +622,7 @@ function Bt(e) {
602
622
  };
603
623
  });
604
624
  }
605
- function $t(e) {
625
+ function zt(e) {
606
626
  var o;
607
627
  let t = "", r = 0, a = null;
608
628
  const c = /* @__PURE__ */ new Map();
@@ -637,7 +657,7 @@ function $t(e) {
637
657
  freezeDuration: s.totalFreezesDuration
638
658
  };
639
659
  }
640
- function _e(e, t, r) {
660
+ function Ae(e, t, r) {
641
661
  const a = e.map((i, d) => d === 0 ? r ? {
642
662
  timestamp: i.timestamp,
643
663
  duration: 0,
@@ -689,14 +709,14 @@ function _e(e, t, r) {
689
709
  framesPerSecond: i.framesPerSecond,
690
710
  freezeCount: i.freezeCount - e[d - 1].freezeCount,
691
711
  freezeDuration: i.freezeDuration - e[d - 1].freezeDuration
692
- }), 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);
693
713
  return {
694
714
  webRTCStats: {
695
715
  anomalies: c,
696
716
  minRtt: Math.min(...n),
697
717
  avgRtt: Me(n),
698
718
  maxRtt: Math.max(...n),
699
- aggregateReport: jt(e[0], e[e.length - 1], s),
719
+ aggregateReport: Bt(e[0], e[e.length - 1], s),
700
720
  minJitterDelayInInterval: Math.min(...o),
701
721
  maxJitterDelayInInterval: Math.max(...o),
702
722
  avgJitterDelayInInterval: Me(o)
@@ -705,14 +725,14 @@ function _e(e, t, r) {
705
725
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
706
726
  };
707
727
  }
708
- function Ke(e, t) {
728
+ function We(e, t) {
709
729
  for (const r of e.values())
710
730
  if ((r == null ? void 0 : r.type) === "inbound-rtp" && r.kind === t)
711
731
  return r;
712
732
  return null;
713
733
  }
714
734
  const ee = 10;
715
- function cr(e, t) {
735
+ function dr(e, t) {
716
736
  let r = !1, a = !1, c = null, s = 0, o = 0, n = {};
717
737
  async function i() {
718
738
  if (r) {
@@ -722,7 +742,7 @@ function cr(e, t) {
722
742
  c = setTimeout(i, ee);
723
743
  return;
724
744
  }
725
- const m = Ke(d, "audio");
745
+ const m = We(d, "audio");
726
746
  if (!m) {
727
747
  c = setTimeout(i, ee);
728
748
  return;
@@ -732,8 +752,8 @@ function cr(e, t) {
732
752
  s = l, o = w, a = !0, c = setTimeout(i, ee);
733
753
  return;
734
754
  }
735
- const v = l - s, k = w - o;
736
- if (s = l, o = w, k > 0 && v > 0) {
755
+ const p = l - s, y = w - o;
756
+ if (s = l, o = w, y > 0 && p > 0) {
737
757
  r = !1, t(n);
738
758
  return;
739
759
  }
@@ -751,11 +771,11 @@ function cr(e, t) {
751
771
  }
752
772
  };
753
773
  }
754
- const oe = 100, zt = Math.max(Math.ceil(400 / oe), 1), Ft = 0.25, Nt = 0.28;
755
- function Vt() {
774
+ const oe = 100, Ft = Math.max(Math.ceil(400 / oe), 1), Nt = 0.25, Vt = 0.28;
775
+ function Kt() {
756
776
  let e = 0, t, r, a = 0;
757
777
  return (c) => {
758
- const s = Ke(c, "video");
778
+ const s = We(c, "video");
759
779
  if (!s)
760
780
  return { isReceiving: !1, avgJitterDelayInInterval: a };
761
781
  const o = s.jitterBufferDelay, n = s.jitterBufferEmittedCount;
@@ -768,19 +788,19 @@ function Vt() {
768
788
  return e = i, { isReceiving: d, avgJitterDelayInInterval: a, freezeCount: s.freezeCount };
769
789
  };
770
790
  }
771
- function Kt(e, t, r, a, c) {
772
- let s = null, o = [], n, i = 0, d = !1, m = te.Unknown, l = te.Unknown, w = 0, v = 0;
773
- const k = 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();
774
794
  async function B() {
775
795
  const M = await e();
776
796
  if (!M)
777
797
  return;
778
- const { isReceiving: D, avgJitterDelayInInterval: $, freezeCount: _ } = k(M), q = $t(M);
779
- if (D)
780
- i = 0, w = _ - v, l = $ < Ft ? te.Strong : $ > Nt && w > 1 ? te.Weak : m, l !== m && (c == null || c(l), m = l, v += w, w = 0), d || (a == null || a(S.Start), n = o[o.length - 1], o = [], d = !0), o.push(q);
781
- else if (d && (i++, i >= zt)) {
782
- const J = _e(o, oe, n);
783
- a == null || a(S.Stop, J), t() || r(), v = _, 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;
784
804
  }
785
805
  }
786
806
  return {
@@ -790,10 +810,10 @@ function Kt(e, t, r, a, c) {
790
810
  stop: () => {
791
811
  s && (clearInterval(s), s = null);
792
812
  },
793
- getReport: () => _e(o, oe, n)
813
+ getReport: () => Ae(o, oe, n)
794
814
  };
795
815
  }
796
- const Ut = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
816
+ const Wt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
797
817
  function be(e) {
798
818
  switch (e) {
799
819
  case "connected":
@@ -814,7 +834,7 @@ function be(e) {
814
834
  return L.New;
815
835
  }
816
836
  }
817
- const Wt = (e) => (t) => {
837
+ const Jt = (e) => (t) => {
818
838
  const [r, a = ""] = t.split(/:(.+)/);
819
839
  try {
820
840
  const c = JSON.parse(a);
@@ -823,16 +843,16 @@ const Wt = (e) => (t) => {
823
843
  return e("Failed to parse data channel message, returning data as string", { subject: r, rawData: a, error: c }), { subject: r, data: a };
824
844
  }
825
845
  };
826
- function Jt({
846
+ function Ot({
827
847
  statsSignal: e,
828
848
  dataChannelSignal: t,
829
849
  onVideoStateChange: r,
830
850
  report: a,
831
851
  log: c
832
852
  }) {
833
- e === S.Start && t === S.Start ? (c("CALLBACK: onVideoStateChange(Start)"), r == null || r(S.Start)) : e === S.Stop && t === S.Stop && (c("CALLBACK: onVideoStateChange(Stop)"), r == null || r(S.Stop, a));
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));
834
854
  }
835
- function Ot({
855
+ function Ht({
836
856
  statsSignal: e,
837
857
  dataChannelSignal: t,
838
858
  onVideoStateChange: r,
@@ -840,9 +860,9 @@ function Ot({
840
860
  report: c,
841
861
  log: s
842
862
  }) {
843
- e === S.Start ? (s("CALLBACK: onVideoStateChange(Start)"), r == null || r(S.Start)) : e === S.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), r == null || r(S.Stop, c)), t === S.Start ? a == null || a(ne.Talking) : t === S.Stop && (a == null || a(ne.Idle));
863
+ e === k.Start ? (s("CALLBACK: onVideoStateChange(Start)"), r == null || r(k.Start)) : e === k.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), r == null || r(k.Stop, c)), t === k.Start ? a == null || a(ne.Talking) : t === k.Stop && (a == null || a(ne.Idle));
844
864
  }
845
- function Ae({
865
+ function xe({
846
866
  statsSignal: e,
847
867
  dataChannelSignal: t,
848
868
  onVideoStateChange: r,
@@ -851,7 +871,7 @@ function Ae({
851
871
  report: s,
852
872
  log: o
853
873
  }) {
854
- 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({
855
875
  statsSignal: e,
856
876
  dataChannelSignal: t,
857
877
  onVideoStateChange: r,
@@ -860,45 +880,45 @@ function Ae({
860
880
  log: o
861
881
  });
862
882
  }
863
- 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) {
864
884
  var E;
865
- const i = Pt(r, "WebRTCStreamingManager"), d = Wt(i);
866
- let m = !1, l = !1, w = S.Stop, v = S.Stop;
867
- const { startConnection: k, 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(
868
888
  c,
869
889
  s,
870
890
  e,
871
891
  a.onError
872
892
  ), {
873
- id: _,
893
+ id: T,
874
894
  offer: q,
875
895
  ice_servers: J,
876
- session_id: N,
896
+ session_id: V,
877
897
  fluent: X,
878
898
  interrupt_enabled: O
879
- } = await D(t, n);
880
- (E = a.onStreamCreated) == null || E.call(a, { stream_id: _, session_id: N, agent_id: e });
881
- const I = new Ut({ iceServers: J }), Y = I.createDataChannel("JanusDataChannel");
882
- if (!N)
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");
902
+ if (!V)
883
903
  throw new Error("Could not create session_id");
884
- const V = X ? W.Fluent : W.Legacy;
904
+ const K = X ? W.Fluent : W.Legacy;
885
905
  o.enrich({
886
- "stream-type": V
906
+ "stream-type": K
887
907
  });
888
908
  const ae = t.stream_warmup && !X, ie = () => m, u = () => {
889
909
  var f;
890
910
  m = !0, l && (i("CALLBACK: onConnectionStateChange(Connected)"), (f = a.onConnectionStateChange) == null || f.call(a, L.Connected));
891
- }, g = Kt(
892
- () => I.getStats(),
911
+ }, g = Ut(
912
+ () => D.getStats(),
893
913
  ie,
894
914
  u,
895
- (f, h) => Ae({
896
- statsSignal: v = f,
897
- dataChannelSignal: V === W.Legacy ? w : void 0,
915
+ (f, h) => xe({
916
+ statsSignal: p = f,
917
+ dataChannelSignal: K === W.Legacy ? w : void 0,
898
918
  onVideoStateChange: a.onVideoStateChange,
899
919
  onAgentActivityStateChange: a.onAgentActivityStateChange,
900
920
  report: h,
901
- streamType: V,
921
+ streamType: K,
902
922
  log: i
903
923
  }),
904
924
  (f) => {
@@ -906,82 +926,82 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
906
926
  return (h = a.onConnectivityStateChange) == null ? void 0 : h.call(a, f);
907
927
  }
908
928
  );
909
- g.start(), I.onicecandidate = (f) => {
929
+ g.start(), D.onicecandidate = (f) => {
910
930
  var h;
911
931
  i("peerConnection.onicecandidate", f);
912
932
  try {
913
933
  f.candidate && f.candidate.sdpMid && f.candidate.sdpMLineIndex !== null ? $(
914
- _,
934
+ T,
915
935
  {
916
936
  candidate: f.candidate.candidate,
917
937
  sdpMid: f.candidate.sdpMid,
918
938
  sdpMLineIndex: f.candidate.sdpMLineIndex
919
939
  },
920
- N,
940
+ V,
921
941
  n
922
- ) : $(_, { candidate: null }, N, n);
923
- } catch (b) {
924
- (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 });
925
945
  }
926
946
  }, Y.onopen = () => {
927
947
  l = !0, (!ae || m) && u();
928
948
  };
929
- let p = null;
930
- const y = (f) => {
949
+ let v = null;
950
+ const C = (f) => {
931
951
  var h;
932
- p = f, (h = a.onVideoIdChange) == null || h.call(a, f);
952
+ v = f, (h = a.onVideoIdChange) == null || h.call(a, f);
933
953
  };
934
- function C(f, h) {
954
+ function S(f, h) {
935
955
  if (f === P.StreamStarted && typeof h == "object" && "metadata" in h) {
936
- const b = h.metadata;
937
- y(b.videoId);
956
+ const A = h.metadata;
957
+ C(A.videoId);
938
958
  }
939
- f === P.StreamDone && y(null), w = f === P.StreamStarted ? S.Start : S.Stop, Ae({
940
- statsSignal: V === W.Legacy ? v : void 0,
959
+ f === P.StreamDone && C(null), w = f === P.StreamStarted ? k.Start : k.Stop, xe({
960
+ statsSignal: K === W.Legacy ? p : void 0,
941
961
  dataChannelSignal: w,
942
962
  onVideoStateChange: a.onVideoStateChange,
943
963
  onAgentActivityStateChange: a.onAgentActivityStateChange,
944
- streamType: V,
964
+ streamType: K,
945
965
  log: i
946
966
  });
947
967
  }
948
968
  function R(f, h) {
949
- var T;
950
- const b = typeof h == "string" ? h : h == null ? void 0 : h.metadata;
951
- 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);
952
972
  }
953
973
  const j = {
954
- [P.StreamStarted]: C,
955
- [P.StreamDone]: C,
974
+ [P.StreamStarted]: S,
975
+ [P.StreamDone]: S,
956
976
  [P.StreamReady]: R
957
977
  };
958
978
  Y.onmessage = (f) => {
959
- var T;
960
- const { subject: h, data: b } = d(f.data);
961
- (T = j[h]) == null || T.call(j, h, b);
962
- }, I.oniceconnectionstatechange = () => {
979
+ var _;
980
+ const { subject: h, data: A } = d(f.data);
981
+ (_ = j[h]) == null || _.call(j, h, A);
982
+ }, D.oniceconnectionstatechange = () => {
963
983
  var h;
964
- i("peerConnection.oniceconnectionstatechange => " + I.iceConnectionState);
965
- const f = be(I.iceConnectionState);
984
+ i("peerConnection.oniceconnectionstatechange => " + D.iceConnectionState);
985
+ const f = be(D.iceConnectionState);
966
986
  f !== L.Connected && ((h = a.onConnectionStateChange) == null || h.call(a, f));
967
- }, I.ontrack = (f) => {
987
+ }, D.ontrack = (f) => {
968
988
  var h;
969
989
  i("peerConnection.ontrack", f), i("CALLBACK: onSrcObjectReady"), (h = a.onSrcObjectReady) == null || h.call(a, f.streams[0]);
970
- }, await I.setRemoteDescription(q), i("set remote description OK");
971
- const z = await I.createAnswer();
972
- i("create answer OK"), await I.setLocalDescription(z), i("set local description OK"), await k(_, z, N, n), i("start connection OK");
973
- function F(f) {
974
- 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;
975
995
  if (!m || Y.readyState !== "open") {
976
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"), {
977
- streamId: _
997
+ streamId: T
978
998
  });
979
999
  return;
980
1000
  }
981
1001
  try {
982
1002
  Y.send(f);
983
- } catch (T) {
984
- 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 });
985
1005
  }
986
1006
  }
987
1007
  return {
@@ -990,72 +1010,72 @@ async function Ht(e, t, { debug: r = !1, callbacks: a, auth: c, baseURL: s = de,
990
1010
  * @param payload
991
1011
  */
992
1012
  speak(f) {
993
- return B(_, N, f);
1013
+ return B(T, V, f);
994
1014
  },
995
1015
  /**
996
1016
  * Method to close RTC connection
997
1017
  */
998
1018
  async disconnect() {
999
1019
  var f;
1000
- if (_) {
1001
- const h = be(I.iceConnectionState);
1002
- if (I) {
1020
+ if (T) {
1021
+ const h = be(D.iceConnectionState);
1022
+ if (D) {
1003
1023
  if (h === L.New) {
1004
1024
  g.stop();
1005
1025
  return;
1006
1026
  }
1007
- 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;
1008
1028
  }
1009
1029
  try {
1010
- h === L.Connected && await M(_, N).catch((b) => {
1030
+ h === L.Connected && await M(T, V).catch((A) => {
1011
1031
  });
1012
- } catch (b) {
1013
- i("Error on close stream connection", b);
1032
+ } catch (A) {
1033
+ i("Error on close stream connection", A);
1014
1034
  }
1015
1035
  (f = a.onAgentActivityStateChange) == null || f.call(a, ne.Idle), g.stop();
1016
1036
  }
1017
1037
  },
1018
- sendDataChannelMessage: F,
1038
+ sendDataChannelMessage: N,
1019
1039
  /**
1020
1040
  * Session identifier information, should be returned in the body of all streaming requests
1021
1041
  */
1022
- sessionId: N,
1042
+ sessionId: V,
1023
1043
  /**
1024
1044
  * Id of current RTC stream
1025
1045
  */
1026
- streamId: _,
1027
- streamType: V,
1046
+ streamId: T,
1047
+ streamType: K,
1028
1048
  interruptAvailable: O ?? !1,
1029
1049
  isInterruptible: !0,
1030
1050
  interrupt(f) {
1031
1051
  if (!O)
1032
1052
  throw new Error("Interrupt is not enabled for this stream");
1033
- if (V !== W.Fluent)
1053
+ if (K !== W.Fluent)
1034
1054
  throw new Error("Interrupt only available for Fluent streams");
1035
- if (!p)
1055
+ if (!v)
1036
1056
  throw new Error("No active video to interrupt");
1037
1057
  const h = {
1038
1058
  type: P.StreamInterrupt,
1039
- videoId: p,
1059
+ videoId: v,
1040
1060
  timestamp: Date.now()
1041
1061
  };
1042
- F(JSON.stringify(h));
1062
+ N(JSON.stringify(h));
1043
1063
  }
1044
1064
  };
1045
1065
  }
1046
1066
  var ge = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(ge || {});
1047
- async function qt(e, t, r, a) {
1067
+ async function Xt(e, t, r, a) {
1048
1068
  const c = e.id;
1049
1069
  switch (t.version) {
1050
1070
  case "v1": {
1051
1071
  const { version: s, ...o } = t;
1052
- return Ht(c, o, r, a);
1072
+ return qt(c, o, r, a);
1053
1073
  }
1054
1074
  case "v2": {
1055
1075
  const { version: s, ...o } = t;
1056
1076
  switch (o.transport.provider) {
1057
- case he.Livekit:
1058
- const { createLiveKitStreamingManager: n } = await import("./livekit-manager-BtTtY9lx.js");
1077
+ case pe.Livekit:
1078
+ const { createLiveKitStreamingManager: n } = await import("./livekit-manager-vNfdN45F.js");
1059
1079
  return n(c, o, r);
1060
1080
  default:
1061
1081
  throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
@@ -1065,15 +1085,15 @@ async function qt(e, t, r, a) {
1065
1085
  throw new Error(`Invalid stream version: ${t.version}`);
1066
1086
  }
1067
1087
  }
1068
- const Xt = "cht";
1069
- function Yt() {
1088
+ const Yt = "cht";
1089
+ function Gt() {
1070
1090
  return {
1071
1091
  transport: {
1072
- provider: he.Livekit
1092
+ provider: pe.Livekit
1073
1093
  }
1074
1094
  };
1075
1095
  }
1076
- function Gt(e) {
1096
+ function Qt(e) {
1077
1097
  var c, s;
1078
1098
  const { streamOptions: t } = e ?? {}, r = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
1079
1099
  plan: (s = e.mixpanelAdditionalProperties) == null ? void 0 : s.plan
@@ -1086,17 +1106,17 @@ function Gt(e) {
1086
1106
  fluent: t == null ? void 0 : t.fluent
1087
1107
  }, ...r && { end_user_data: r } };
1088
1108
  }
1089
- function Qt(e, t) {
1090
- return pe(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) };
1091
1111
  }
1092
- function Zt(e, t, r) {
1112
+ function er(e, t, r) {
1093
1113
  r.track("agent-connection-state-change", { state: e, ...t && { reason: t } });
1094
1114
  }
1095
- function er(e, t, r, a, c) {
1096
- c === W.Fluent ? tr(e, t, r, a, c) : rr(e, t, r, a, c);
1097
- }
1098
1115
  function tr(e, t, r, a, c) {
1099
- e === S.Start ? a.track("stream-session", { event: "start", "stream-type": c }) : e === S.Stop && a.track("stream-session", {
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) {
1119
+ e === k.Start ? a.track("stream-session", { event: "start", "stream-type": c }) : e === k.Stop && a.track("stream-session", {
1100
1120
  event: "stop",
1101
1121
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1102
1122
  background: t.presenter.type === "clip" && t.presenter.background,
@@ -1104,10 +1124,10 @@ function tr(e, t, r, a, c) {
1104
1124
  ...r
1105
1125
  });
1106
1126
  }
1107
- function xe(e, t, r, a, c) {
1108
- e === S.Start ? r.linkTrack("agent-video", { event: "start", ...c, "stream-type": a }, "start", [
1127
+ function Le(e, t, r, a, c) {
1128
+ e === k.Start ? r.linkTrack("agent-video", { event: "start", ...c, "stream-type": a }, "start", [
1109
1129
  P.StreamVideoCreated
1110
- ]) : e === S.Stop && r.linkTrack(
1130
+ ]) : e === k.Stop && r.linkTrack(
1111
1131
  "agent-video",
1112
1132
  {
1113
1133
  event: "stop",
@@ -1119,13 +1139,13 @@ function xe(e, t, r, a, c) {
1119
1139
  [P.StreamVideoDone]
1120
1140
  );
1121
1141
  }
1122
- function rr(e, t, r, a, c) {
1123
- e === S.Start ? a.linkTrack(
1142
+ function nr(e, t, r, a, c) {
1143
+ e === k.Start ? a.linkTrack(
1124
1144
  "agent-video",
1125
1145
  { event: "start", latency: H.get(!0), "stream-type": c },
1126
1146
  "start",
1127
1147
  [P.StreamVideoCreated]
1128
- ) : e === S.Stop && a.linkTrack(
1148
+ ) : e === k.Stop && a.linkTrack(
1129
1149
  "agent-video",
1130
1150
  {
1131
1151
  event: "stop",
@@ -1138,7 +1158,7 @@ function rr(e, t, r, a, c) {
1138
1158
  [P.StreamVideoDone]
1139
1159
  );
1140
1160
  }
1141
- function nr(e, t, r) {
1161
+ function ar(e, t, r) {
1142
1162
  const a = {
1143
1163
  call_id: t.call_id,
1144
1164
  name: t.name
@@ -1155,17 +1175,17 @@ function nr(e, t, r) {
1155
1175
  extra_keys: c.extra ? Object.keys(c.extra).length : 0
1156
1176
  });
1157
1177
  }
1158
- function Le(e, t, r, a) {
1159
- return H.reset(), Te.update(), new Promise(async (c, s) => {
1178
+ function Pe(e, t, r, a) {
1179
+ return H.reset(), _e.update(), new Promise(async (c, s) => {
1160
1180
  try {
1161
1181
  let o, n = !1;
1162
- const i = Qt(e, t);
1182
+ const i = Zt(e, t);
1163
1183
  r.enrich({
1164
1184
  "stream-version": i.version.toString()
1165
1185
  });
1166
1186
  let d = null;
1167
1187
  const m = e.presenter.type === "expressive";
1168
- o = await qt(
1188
+ o = await Xt(
1169
1189
  e,
1170
1190
  i,
1171
1191
  {
@@ -1174,12 +1194,12 @@ function Le(e, t, r, a) {
1174
1194
  callbacks: {
1175
1195
  ...t.callbacks,
1176
1196
  onConnectionStateChange: (l, w) => {
1177
- var v, k;
1178
- (k = (v = t.callbacks).onConnectionStateChange) == null || k.call(v, l), Zt(l, w, r), l === L.Connected && (o ? c(o) : n = !0);
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);
1179
1199
  },
1180
1200
  onVideoStateChange: (l, w) => {
1181
- var v, k;
1182
- (k = (v = t.callbacks).onVideoStateChange) == null || k.call(v, l), er(
1201
+ var p, y;
1202
+ (y = (p = t.callbacks).onVideoStateChange) == null || y.call(p, l), tr(
1183
1203
  l,
1184
1204
  e,
1185
1205
  w,
@@ -1188,17 +1208,17 @@ function Le(e, t, r, a) {
1188
1208
  );
1189
1209
  },
1190
1210
  onAgentActivityStateChange: (l) => {
1191
- var w, v;
1192
- (v = (w = t.callbacks).onAgentActivityStateChange) == null || v.call(w, l), l === ne.Talking ? (fe.update(), d = (k) => {
1193
- xe(
1194
- S.Start,
1211
+ var w, p;
1212
+ (p = (w = t.callbacks).onAgentActivityStateChange) == null || p.call(w, l), l === ne.Talking ? (fe.update(), d = (y) => {
1213
+ Le(
1214
+ k.Start,
1195
1215
  e,
1196
1216
  r,
1197
1217
  o.streamType,
1198
- k
1218
+ y
1199
1219
  ), d = null;
1200
- }, m || d({ latency: H.get(!0) })) : (fe.reset(), d = null, xe(
1201
- S.Stop,
1220
+ }, m || d({ latency: H.get(!0) })) : (fe.reset(), d = null, Le(
1221
+ k.Stop,
1202
1222
  e,
1203
1223
  r,
1204
1224
  o.streamType
@@ -1208,13 +1228,13 @@ function Le(e, t, r, a) {
1208
1228
  d == null || d(l);
1209
1229
  },
1210
1230
  onStreamReady: () => {
1211
- const l = Te.get(!0);
1231
+ const l = _e.get(!0);
1212
1232
  r.track("agent-chat", { event: "ready", latency: l });
1213
1233
  },
1214
- onToolEvent: (l, w) => {
1215
- var v, k;
1216
- (k = (v = t.callbacks).onToolEvent) == null || k.call(v, l, w), nr(l, w, r);
1217
- }
1234
+ onToolEvent: ((l, w) => {
1235
+ var p, y;
1236
+ (y = (p = t.callbacks).onToolEvent) == null || y.call(p, l, w), ar(l, w, r);
1237
+ })
1218
1238
  }
1219
1239
  },
1220
1240
  a
@@ -1224,11 +1244,11 @@ function Le(e, t, r, a) {
1224
1244
  }
1225
1245
  });
1226
1246
  }
1227
- async function ar(e, t, r, a, c) {
1228
- var m, l, w, v;
1247
+ async function ir(e, t, r, a, c) {
1248
+ var m, l, w, p;
1229
1249
  const s = async () => {
1230
- if (pe(e.presenter.type)) {
1231
- const k = await Le(e, t, a), B = `${Xt}_${k.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
1250
+ if (he(e.presenter.type)) {
1251
+ const y = await Pe(e, t, a), B = `${Yt}_${y.sessionId}`, M = (/* @__PURE__ */ new Date()).toISOString();
1232
1252
  return { chatResult: {
1233
1253
  chatMode: x.Functional,
1234
1254
  chat: {
@@ -1242,35 +1262,35 @@ async function ar(e, t, r, a, c) {
1242
1262
  chat_mode: x.Functional,
1243
1263
  messages: []
1244
1264
  }
1245
- }, streamingManager: k };
1265
+ }, streamingManager: y };
1246
1266
  } else {
1247
- const k = new AbortController(), B = k.signal;
1267
+ const y = new AbortController(), B = y.signal;
1248
1268
  let M;
1249
1269
  try {
1250
- const D = Ve(
1270
+ const I = Ue(
1251
1271
  e,
1252
1272
  r,
1253
1273
  a,
1254
1274
  t.mode,
1255
1275
  t.persistentChat,
1256
1276
  c
1257
- ), $ = Le(e, t, a, B).then((J) => (M = J, J)), [_, q] = await Promise.all([D, $]);
1258
- return { chatResult: _, streamingManager: q };
1259
- } catch (D) {
1260
- throw k.abort(), M && await M.disconnect().catch(() => {
1261
- }), 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;
1262
1282
  }
1263
1283
  }
1264
1284
  }, { chatResult: o, streamingManager: n } = await s(), { chat: i, chatMode: d } = o;
1265
- return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (l = (m = t.callbacks).onModeChange) == null || l.call(m, d), d !== x.Functional) ? ((v = (w = t.callbacks).onError) == null || v.call(w, new He(d)), n == null || n.disconnect(), { chat: i }) : { chat: i, streamingManager: n };
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 };
1266
1286
  }
1267
- async function dr(e, t) {
1268
- var Y, V, ae, ie;
1287
+ async function lr(e, t) {
1288
+ var Y, K, ae, ie;
1269
1289
  let r = !0;
1270
- const a = t.mixpanelKey || ot, c = t.wsURL || st, 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 = {
1271
1291
  messages: [],
1272
1292
  chatMode: o
1273
- }, i = Rt({
1293
+ }, i = Dt({
1274
1294
  token: a,
1275
1295
  agentId: e,
1276
1296
  isEnabled: t.enableAnalitics,
@@ -1280,67 +1300,67 @@ async function dr(e, t) {
1280
1300
  Ee(() => {
1281
1301
  i.track("agent-sdk", { event: "init" }, d);
1282
1302
  });
1283
- const m = wt(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);
1284
1304
  t.debug = t.debug || ((Y = l == null ? void 0 : l.advanced_settings) == null ? void 0 : Y.ui_debug_mode);
1285
- const w = pe(l.presenter.type);
1286
- i.enrich(yt(l));
1287
- const { onMessage: v, clearQueue: k } = xt(i, n, t, l, () => {
1288
- var u, g, p;
1289
- (u = n.socketManager) == null || u.disconnect(), (p = (g = t.callbacks).onConnectionStateChange) == null || p.call(g, L.Disconnected);
1305
+ const w = he(l.presenter.type);
1306
+ i.enrich(St(l));
1307
+ const { onMessage: p, clearQueue: y } = Lt(i, n, t, l, () => {
1308
+ var u, g, v;
1309
+ (u = n.socketManager) == null || u.disconnect(), (v = (g = t.callbacks).onConnectionStateChange) == null || v.call(g, L.Disconnected);
1290
1310
  });
1291
- n.messages = It(t.initialMessages), (ae = (V = t.callbacks).onNewMessage) == null || ae.call(V, [...n.messages], "answer");
1311
+ n.messages = Et(t.initialMessages), (ae = (K = t.callbacks).onNewMessage) == null || ae.call(K, [...n.messages], "answer");
1292
1312
  const B = (u) => {
1293
1313
  }, M = ({ type: u }) => {
1294
- var p, y, C, R;
1295
- if (!((p = n.streamingManager) != null && p.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;
1296
1316
  const g = n.messages[n.messages.length - 1];
1297
1317
  i.track("agent-video-interrupt", {
1298
1318
  type: u || "click",
1299
1319
  video_duration_to_interrupt: fe.get(!0),
1300
1320
  message_duration_to_interrupt: H.get(!0)
1301
- }), g.interrupted = !0, (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "answer"), n.streamingManager.interrupt(u);
1302
- }, D = /* @__PURE__ */ new Map();
1321
+ }), g.interrupted = !0, (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...n.messages], "answer"), n.streamingManager.interrupt(u);
1322
+ }, I = /* @__PURE__ */ new Map();
1303
1323
  function $(u) {
1304
1324
  return async (g) => {
1305
- const p = D.get(u);
1306
- if (!p)
1325
+ const v = I.get(u);
1326
+ if (!v)
1307
1327
  throw new Error(`No handler registered for client tool: ${u}`);
1308
1328
  try {
1309
- const y = JSON.parse(g.payload);
1310
- return await p(y);
1311
- } catch (y) {
1312
- 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}`);
1313
1333
  }
1314
1334
  };
1315
1335
  }
1316
- function _() {
1317
- var u, g, p, y;
1318
- for (const [C] of D)
1319
- (g = (u = n.streamingManager) == null ? void 0 : u.unregisterRpcMethod) == null || g.call(u, C), (y = (p = n.streamingManager) == null ? void 0 : p.registerRpcMethod) == null || y.call(p, C, $(C));
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));
1320
1340
  }
1321
1341
  function q(u, g) {
1322
- var y, C;
1323
- const p = !D.has(u);
1324
- D.set(u, g), p && ((C = (y = n.streamingManager) == null ? void 0 : y.registerRpcMethod) == null || C.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)));
1325
1345
  }
1326
1346
  function J(u) {
1327
- var g, p;
1328
- D.delete(u), (p = (g = n.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || p.call(g, u);
1347
+ var g, v;
1348
+ I.delete(u), (v = (g = n.streamingManager) == null ? void 0 : g.unregisterRpcMethod) == null || v.call(g, u);
1329
1349
  }
1330
- const N = Date.now();
1350
+ const V = Date.now();
1331
1351
  Ee(() => {
1332
- i.track("agent-sdk", { event: "loaded", ...vt(l) }, N);
1352
+ i.track("agent-sdk", { event: "loaded", ...Ct(l) }, V);
1333
1353
  });
1334
1354
  async function X(u) {
1335
- var j, z, F, E, f, h, b;
1336
- (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"));
1337
- const g = o === x.DirectPlayback || w ? Promise.resolve(void 0) : Tt(
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(
1338
1358
  t.auth,
1339
1359
  c,
1340
- { onMessage: v, onError: t.callbacks.onError },
1360
+ { onMessage: p, onError: t.callbacks.onError },
1341
1361
  t.externalId
1342
- ), p = ue(
1343
- () => ar(
1362
+ ), v = me(
1363
+ () => ir(
1344
1364
  l,
1345
1365
  {
1346
1366
  ...t,
@@ -1348,7 +1368,7 @@ async function dr(e, t) {
1348
1368
  callbacks: {
1349
1369
  ...t.callbacks,
1350
1370
  onVideoIdChange: B,
1351
- onMessage: v
1371
+ onMessage: p
1352
1372
  }
1353
1373
  },
1354
1374
  m,
@@ -1357,28 +1377,28 @@ async function dr(e, t) {
1357
1377
  ),
1358
1378
  {
1359
1379
  limit: 3,
1360
- timeout: at,
1380
+ timeout: ot,
1361
1381
  timeoutErrorMessage: "Timeout initializing the stream",
1362
- 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",
1363
1383
  delayMs: 1e3
1364
1384
  }
1365
- ).catch((T) => {
1366
- var A, K;
1367
- throw I(x.Maintenance), (K = (A = t.callbacks).onConnectionStateChange) == null || K.call(A, L.Fail), T;
1368
- }), [y, { streamingManager: C, chat: R }] = await Promise.all([g, p]);
1369
- R && R.id !== ((f = n.chat) == null ? void 0 : f.id) && ((b = (h = t.callbacks).onNewChat) == null || b.call(h, R.id)), n.streamingManager = C, n.socketManager = y, n.chat = R, _(), r = !1, i.enrich({
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({
1370
1390
  chatId: R == null ? void 0 : R.id,
1371
- streamId: C == null ? void 0 : C.streamId,
1391
+ streamId: S == null ? void 0 : S.streamId,
1372
1392
  mode: n.chatMode
1373
- }), I((R == null ? void 0 : R.chat_mode) ?? o);
1393
+ }), D((R == null ? void 0 : R.chat_mode) ?? o);
1374
1394
  }
1375
1395
  async function O() {
1376
- var u, g, p, y;
1377
- (u = n.socketManager) == null || u.disconnect(), await ((g = n.streamingManager) == null ? void 0 : g.disconnect()), delete n.streamingManager, delete n.socketManager, (y = (p = t.callbacks).onConnectionStateChange) == null || y.call(p, L.Disconnected);
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);
1378
1398
  }
1379
- async function I(u) {
1380
- var g, p;
1381
- u !== n.chatMode && (i.track("agent-mode-change", { mode: u }), n.chatMode = u, n.chatMode !== x.Functional && await O(), (p = (g = t.callbacks).onModeChange) == null || p.call(g, u));
1399
+ async function D(u) {
1400
+ var g, v;
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));
1382
1402
  }
1383
1403
  return {
1384
1404
  agent: l,
@@ -1392,7 +1412,7 @@ async function dr(e, t) {
1392
1412
  },
1393
1413
  starterMessages: ((ie = l.knowledge) == null ? void 0 : ie.starter_message) || [],
1394
1414
  getSTTToken: () => m.getSTTToken(l.id),
1395
- changeMode: I,
1415
+ changeMode: D,
1396
1416
  enrichAnalytics: i.enrich,
1397
1417
  async connect() {
1398
1418
  await X(!0), i.track("agent-chat", {
@@ -1445,26 +1465,26 @@ async function dr(e, t) {
1445
1465
  return (u = n.streamingManager) != null && u.unpublishCameraStream ? n.streamingManager.unpublishCameraStream() : Promise.resolve();
1446
1466
  },
1447
1467
  async chat(u) {
1448
- var C, R, j, z, F;
1468
+ var S, R, j, F, N;
1449
1469
  const g = () => {
1450
- if ($e(o))
1451
- throw new G(`${o} is enabled, chat is disabled`);
1470
+ if (Ne(o))
1471
+ throw new Q(`${o} is enabled, chat is disabled`);
1452
1472
  if (u.length >= 800)
1453
- throw new G("Message cannot be more than 800 characters");
1473
+ throw new Q("Message cannot be more than 800 characters");
1454
1474
  if (u.length === 0)
1455
- throw new G("Message cannot be empty");
1475
+ throw new Q("Message cannot be empty");
1456
1476
  if (n.chatMode === x.Maintenance)
1457
- throw new G("Chat is in maintenance mode");
1477
+ throw new Q("Chat is in maintenance mode");
1458
1478
  if (![x.TextOnly, x.Playground].includes(n.chatMode)) {
1459
1479
  if (!n.streamingManager)
1460
- throw new G("Streaming manager is not initialized");
1480
+ throw new Q("Streaming manager is not initialized");
1461
1481
  if (!n.chat)
1462
- throw new G("Chat is not initialized");
1482
+ throw new Q("Chat is not initialized");
1463
1483
  }
1464
- }, p = async () => {
1484
+ }, v = async () => {
1465
1485
  var E, f;
1466
1486
  if (!n.chat) {
1467
- const h = await Ve(
1487
+ const h = await Ue(
1468
1488
  l,
1469
1489
  m,
1470
1490
  i,
@@ -1472,37 +1492,37 @@ async function dr(e, t) {
1472
1492
  t.persistentChat
1473
1493
  );
1474
1494
  if (!h.chat)
1475
- throw new Oe(n.chatMode, !!t.persistentChat);
1495
+ throw new qe(n.chatMode, !!t.persistentChat);
1476
1496
  n.chat = h.chat, (f = (E = t.callbacks).onNewChat) == null || f.call(E, n.chat.id);
1477
1497
  }
1478
1498
  return n.chat.id;
1479
- }, y = async (E, f) => {
1499
+ }, C = async (E, f) => {
1480
1500
  const h = n.chatMode === x.Playground;
1481
- return ue(w && !h ? async () => {
1482
- var A, K;
1483
- return await ((K = (A = n.streamingManager) == null ? void 0 : A.sendTextMessage) == null ? void 0 : K.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({});
1484
1504
  } : async () => {
1485
- var A, K;
1505
+ var b, U;
1486
1506
  return m.chat(
1487
1507
  l.id,
1488
1508
  f,
1489
1509
  {
1490
1510
  chatMode: n.chatMode,
1491
- streamId: (A = n.streamingManager) == null ? void 0 : A.streamId,
1492
- sessionId: (K = n.streamingManager) == null ? void 0 : K.sessionId,
1493
- messages: E.map(({ matches: Ue, ...se }) => se)
1511
+ streamId: (b = n.streamingManager) == null ? void 0 : b.streamId,
1512
+ sessionId: (U = n.streamingManager) == null ? void 0 : U.sessionId,
1513
+ messages: E.map(({ matches: Je, ...se }) => se)
1494
1514
  },
1495
1515
  {
1496
- ...Ne(n.chatMode),
1516
+ ...Ke(n.chatMode),
1497
1517
  skipErrorHandler: !0
1498
1518
  }
1499
1519
  );
1500
1520
  }, {
1501
1521
  limit: 2,
1502
- shouldRetryFn: (A) => {
1522
+ shouldRetryFn: (b) => {
1503
1523
  var se, ve, ye, Ce;
1504
- const K = (se = A == null ? void 0 : A.message) == null ? void 0 : se.includes("missing or invalid session_id");
1505
- return !((ve = A == null ? void 0 : A.message) == null ? void 0 : ve.includes("Stream Error")) && !K ? ((Ce = (ye = t.callbacks).onError) == null || Ce.call(ye, A), !1) : !0;
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;
1506
1526
  },
1507
1527
  onRetry: async () => {
1508
1528
  await O(), await X(!1);
@@ -1510,59 +1530,59 @@ async function dr(e, t) {
1510
1530
  });
1511
1531
  };
1512
1532
  try {
1513
- k(), g(), n.messages.push({
1514
- id: Q(),
1533
+ y(), g(), n.messages.push({
1534
+ id: G(),
1515
1535
  role: "user",
1516
1536
  content: u,
1517
1537
  parts: re(u),
1518
1538
  created_at: new Date(H.update()).toISOString()
1519
- }), (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "user");
1520
- const E = await p(), f = await y([...n.messages], E);
1521
- return n.messages.push({
1522
- id: Q(),
1539
+ }), (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...n.messages], "user");
1540
+ const E = await v(), f = await C([...n.messages], E);
1541
+ return f.result && n.messages.push({
1542
+ id: G(),
1523
1543
  role: "assistant",
1524
- content: f.result || "",
1525
- parts: re(f.result || ""),
1544
+ content: f.result,
1545
+ parts: re(f.result),
1526
1546
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1527
1547
  context: f.context,
1528
1548
  matches: f.matches
1529
1549
  }), i.track("agent-message-send", {
1530
1550
  event: "success",
1531
1551
  messages: n.messages.length + 1
1532
- }), 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", {
1533
1553
  latency: H.get(!0),
1534
1554
  messages: n.messages.length
1535
1555
  })), f;
1536
1556
  } catch (E) {
1537
- 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", {
1538
1558
  event: "error",
1539
1559
  messages: n.messages.length
1540
1560
  }), E;
1541
1561
  }
1542
1562
  },
1543
- rate(u, g, p) {
1544
- var R, j, z, F;
1545
- const y = n.messages.find((E) => E.id === u);
1563
+ rate(u, g, v) {
1564
+ var R, j, F, N;
1565
+ const C = n.messages.find((E) => E.id === u);
1546
1566
  if (n.chat) {
1547
- if (!y)
1567
+ if (!C)
1548
1568
  throw new Error("Message not found");
1549
1569
  } else throw new Error("Chat is not initialized");
1550
- const C = ((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])) ?? [];
1551
1571
  return i.track("agent-rate", {
1552
- event: p ? "update" : "create",
1572
+ event: v ? "update" : "create",
1553
1573
  thumb: g === 1 ? "up" : "down",
1554
1574
  knowledge_id: ((j = l.knowledge) == null ? void 0 : j.id) ?? "",
1555
- matches: C,
1575
+ matches: S,
1556
1576
  score: g
1557
- }), p ? m.updateRating(l.id, n.chat.id, p, {
1558
- knowledge_id: ((z = l.knowledge) == null ? void 0 : z.id) ?? "",
1577
+ }), v ? m.updateRating(l.id, n.chat.id, v, {
1578
+ knowledge_id: ((F = l.knowledge) == null ? void 0 : F.id) ?? "",
1559
1579
  message_id: u,
1560
- matches: C,
1580
+ matches: S,
1561
1581
  score: g
1562
1582
  }) : m.createRating(l.id, n.chat.id, {
1563
- knowledge_id: ((F = l.knowledge) == null ? void 0 : F.id) ?? "",
1583
+ knowledge_id: ((N = l.knowledge) == null ? void 0 : N.id) ?? "",
1564
1584
  message_id: u,
1565
- matches: C,
1585
+ matches: S,
1566
1586
  score: g
1567
1587
  });
1568
1588
  },
@@ -1572,7 +1592,7 @@ async function dr(e, t) {
1572
1592
  return i.track("agent-rate-delete", { type: "text" }), m.deleteRating(l.id, n.chat.id, u);
1573
1593
  },
1574
1594
  async speak(u) {
1575
- var C, R, j;
1595
+ var S, R, j;
1576
1596
  function g() {
1577
1597
  if (typeof u == "string") {
1578
1598
  if (!l.presenter.voice)
@@ -1596,14 +1616,14 @@ async function dr(e, t) {
1596
1616
  }
1597
1617
  return u;
1598
1618
  }
1599
- const p = g();
1600
- if (i.track("agent-speak", p), H.update(), n.messages && p.type === "text" && (n.messages.push({
1601
- id: Q(),
1619
+ const v = g();
1620
+ if (i.track("agent-speak", v), H.update(), n.messages && v.type === "text" && (n.messages.push({
1621
+ id: G(),
1602
1622
  role: "assistant",
1603
- content: p.input,
1604
- parts: re(p.input),
1623
+ content: v.input,
1624
+ parts: re(v.input),
1605
1625
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1606
- }), (R = (C = t.callbacks).onNewMessage) == null || R.call(C, [...n.messages], "answer")), lt(n.chatMode))
1626
+ }), (R = (S = t.callbacks).onNewMessage) == null || R.call(S, [...n.messages], "answer")), ft(n.chatMode))
1607
1627
  return {
1608
1628
  duration: 0,
1609
1629
  video_id: "",
@@ -1612,7 +1632,7 @@ async function dr(e, t) {
1612
1632
  if (!n.streamingManager)
1613
1633
  throw new Error("Please connect to the agent first");
1614
1634
  return n.streamingManager.speak({
1615
- script: p,
1635
+ script: v,
1616
1636
  metadata: { chat_id: (j = n.chat) == null ? void 0 : j.id, agent_id: l.id }
1617
1637
  });
1618
1638
  },
@@ -1623,36 +1643,36 @@ async function dr(e, t) {
1623
1643
  }
1624
1644
  export {
1625
1645
  ne as A,
1626
- U as C,
1627
- tt as D,
1628
- et as K,
1629
- Ye as P,
1630
- Qe as R,
1646
+ z as C,
1647
+ nt as D,
1648
+ rt as K,
1649
+ Qe as P,
1650
+ et as R,
1631
1651
  P as S,
1632
- he as T,
1633
- Xe as U,
1634
- G as V,
1635
- qe as W,
1636
- Pt as a,
1652
+ pe as T,
1653
+ Ge as U,
1654
+ Q as V,
1655
+ Ye as W,
1656
+ jt as a,
1637
1657
  W as b,
1638
- Fe as c,
1658
+ Ve as c,
1639
1659
  de as d,
1640
1660
  L as e,
1641
1661
  te as f,
1642
- Kt as g,
1643
- cr as h,
1644
- S as i,
1645
- Oe as j,
1646
- He as k,
1662
+ Ut as g,
1663
+ dr as h,
1664
+ k as i,
1665
+ Ze as j,
1666
+ qe as k,
1647
1667
  H as l,
1648
- dr as m,
1649
- or as n,
1650
- Ge as o,
1651
- ft as p,
1652
- x as q,
1653
- Ze as r,
1654
- Pe as s,
1655
- sr as t,
1656
- rt as u,
1657
- nt as v
1668
+ x as m,
1669
+ cr as n,
1670
+ Xe as o,
1671
+ at as p,
1672
+ tt as q,
1673
+ je as r,
1674
+ it as s,
1675
+ lr as t,
1676
+ or as u,
1677
+ ht as v
1658
1678
  };