@d-id/client-sdk 1.1.30 → 1.1.31-staging.145

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.
package/dist/index.js CHANGED
@@ -1,20 +1,20 @@
1
1
  var Qe = Object.defineProperty;
2
- var Xe = (e, t, a) => t in e ? Qe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
3
- var fe = (e, t, a) => Xe(e, typeof t != "symbol" ? t + "" : t, a);
2
+ var Xe = (e, t, i) => t in e ? Qe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
+ var fe = (e, t, i) => Xe(e, typeof t != "symbol" ? t + "" : t, i);
4
4
  class we extends Error {
5
- constructor({ kind: a, description: n, error: c }) {
6
- super(JSON.stringify({ kind: a, description: n }));
5
+ constructor({ kind: i, description: n, error: s }) {
6
+ super(JSON.stringify({ kind: i, description: n }));
7
7
  fe(this, "kind");
8
8
  fe(this, "description");
9
9
  fe(this, "error");
10
- this.kind = a, this.description = n, this.error = c;
10
+ this.kind = i, this.description = n, this.error = s;
11
11
  }
12
12
  }
13
13
  class Ye extends we {
14
- constructor(t, a) {
14
+ constructor(t, i) {
15
15
  super({
16
16
  kind: "ChatCreationFailed",
17
- description: `Failed to create ${a ? "persistent" : ""} chat, mode: ${t}`
17
+ description: `Failed to create ${i ? "persistent" : ""} chat, mode: ${t}`
18
18
  });
19
19
  }
20
20
  }
@@ -23,9 +23,9 @@ class Ge extends we {
23
23
  super({ kind: "ChatModeDowngraded", description: `Chat mode downgraded to ${t}` });
24
24
  }
25
25
  }
26
- class ce extends we {
27
- constructor(a, n) {
28
- super({ kind: "ValidationError", description: a });
26
+ class ue extends we {
27
+ constructor(i, n) {
28
+ super({ kind: "ValidationError", description: i });
29
29
  fe(this, "key");
30
30
  this.key = n;
31
31
  }
@@ -35,7 +35,7 @@ class Ze extends we {
35
35
  super({ kind: "WSError", description: t });
36
36
  }
37
37
  }
38
- var et = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(et || {}), tt = /* @__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))(tt || {}), nt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(nt || {}), rt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(rt || {}), F = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(F || {}), Y = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(Y || {}), it = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(it || {}), at = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(at || {}), ot = /* @__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))(ot || {}), Ke = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Ke || {});
38
+ var et = /* @__PURE__ */ ((e) => (e.TRIAL = "trial", e.BASIC = "basic", e.ENTERPRISE = "enterprise", e.LITE = "lite", e.ADVANCED = "advanced", e))(et || {}), tt = /* @__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))(tt || {}), nt = /* @__PURE__ */ ((e) => (e.Created = "created", e.Started = "started", e.Done = "done", e.Error = "error", e.Rejected = "rejected", e.Ready = "ready", e))(nt || {}), rt = /* @__PURE__ */ ((e) => (e.Unrated = "Unrated", e.Positive = "Positive", e.Negative = "Negative", e))(rt || {}), F = /* @__PURE__ */ ((e) => (e.Functional = "Functional", e.TextOnly = "TextOnly", e.Maintenance = "Maintenance", e.Playground = "Playground", e.DirectPlayback = "DirectPlayback", e.Off = "Off", e))(F || {}), X = /* @__PURE__ */ ((e) => (e.Embed = "embed", e.Query = "query", e.Partial = "partial", e.Answer = "answer", e.Transcribe = "transcribe", e.Complete = "done", e))(X || {}), it = /* @__PURE__ */ ((e) => (e.KnowledgeProcessing = "knowledge/processing", e.KnowledgeIndexing = "knowledge/indexing", e.KnowledgeFailed = "knowledge/error", e.KnowledgeDone = "knowledge/done", e))(it || {}), at = /* @__PURE__ */ ((e) => (e.Knowledge = "knowledge", e.Document = "document", e.Record = "record", e))(at || {}), ot = /* @__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))(ot || {}), Ke = /* @__PURE__ */ ((e) => (e.Clip = "clip", e.Talk = "talk", e.Expressive = "expressive", e))(Ke || {});
39
39
  const mn = (e) => {
40
40
  switch (e) {
41
41
  case "clip":
@@ -48,22 +48,22 @@ const mn = (e) => {
48
48
  throw new Error(`Unknown video type: ${e}`);
49
49
  }
50
50
  };
51
- var C = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(C || {}), re = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(re || {}), U = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e))(U || {}), j = /* @__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))(j || {}), S = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(S || {}), ae = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ae || {}), ye = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(ye || {}), st = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(st || {}), ct = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(ct || {});
52
- const dt = 45 * 1e3, ut = "X-Playground-Chat", ge = "https://api.d-id.com", lt = "wss://notifications.d-id.com", ft = "79f81a83a67430be2bc0fd61042b8faa", Je = (e) => new Promise((t) => setTimeout(t, e)), de = (e = 16) => {
51
+ var S = /* @__PURE__ */ ((e) => (e.Start = "START", e.Stop = "STOP", e))(S || {}), ie = /* @__PURE__ */ ((e) => (e.Strong = "STRONG", e.Weak = "WEAK", e.Unknown = "UNKNOWN", e))(ie || {}), W = /* @__PURE__ */ ((e) => (e.Idle = "IDLE", e.Loading = "LOADING", e.Talking = "TALKING", e))(W || {}), j = /* @__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))(j || {}), R = /* @__PURE__ */ ((e) => (e.New = "new", e.Fail = "fail", e.Connected = "connected", e.Connecting = "connecting", e.Closed = "closed", e.Completed = "completed", e.Disconnected = "disconnected", e))(R || {}), ae = /* @__PURE__ */ ((e) => (e.Legacy = "legacy", e.Fluent = "fluent", e))(ae || {}), ye = /* @__PURE__ */ ((e) => (e.Livekit = "livekit", e))(ye || {}), st = /* @__PURE__ */ ((e) => (e.Amazon = "amazon", e.AzureOpenAi = "azure-openai", e.Microsoft = "microsoft", e.Afflorithmics = "afflorithmics", e.Elevenlabs = "elevenlabs", e))(st || {}), ct = /* @__PURE__ */ ((e) => (e.Public = "public", e.Premium = "premium", e.Private = "private", e))(ct || {});
52
+ const dt = 45 * 1e3, ut = "X-Playground-Chat", ge = "https://api.d-id.com", lt = "wss://notifications.d-id.com", ft = "79f81a83a67430be2bc0fd61042b8faa", Je = (e) => new Promise((t) => setTimeout(t, e)), le = (e = 16) => {
53
53
  const t = new Uint8Array(e);
54
- return window.crypto.getRandomValues(t), Array.from(t, (a) => a.toString(16).padStart(2, "0")).join("").slice(0, 13);
55
- }, Ue = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Ie = (e) => e === Ke.Expressive, mt = (e) => [F.TextOnly, F.Playground, F.Maintenance].includes(e), We = (e) => e && [F.DirectPlayback, F.Off].includes(e);
54
+ return window.crypto.getRandomValues(t), Array.from(t, (i) => i.toString(16).padStart(2, "0")).join("").slice(0, 13);
55
+ }, Ue = (e) => e.type === "clip" && e.presenter_id.startsWith("v2_") ? "clip_v2" : e.type, Ie = (e) => e === Ke.Expressive, mt = (e) => [F.TextOnly, F.Playground, F.Maintenance].includes(e), Ve = (e) => e && [F.DirectPlayback, F.Off].includes(e);
56
56
  function gt(e, t) {
57
- let a;
57
+ let i;
58
58
  return {
59
- promise: new Promise((c, o) => {
60
- a = setTimeout(() => o(new Error(t)), e);
59
+ promise: new Promise((s, o) => {
60
+ i = setTimeout(() => o(new Error(t)), e);
61
61
  }),
62
- clear: () => clearTimeout(a)
62
+ clear: () => clearTimeout(i)
63
63
  };
64
64
  }
65
- async function Ce(e, t) {
66
- const a = {
65
+ async function Se(e, t) {
66
+ const i = {
67
67
  limit: (t == null ? void 0 : t.limit) ?? 3,
68
68
  delayMs: (t == null ? void 0 : t.delayMs) ?? 0,
69
69
  timeout: (t == null ? void 0 : t.timeout) ?? 3e4,
@@ -73,16 +73,16 @@ async function Ce(e, t) {
73
73
  })
74
74
  };
75
75
  let n;
76
- for (let c = 1; c <= a.limit; c++)
76
+ for (let s = 1; s <= i.limit; s++)
77
77
  try {
78
- if (!a.timeout)
78
+ if (!i.timeout)
79
79
  return await e();
80
- const { promise: o, clear: s } = gt(a.timeout, a.timeoutErrorMessage), i = e().finally(s);
81
- return await Promise.race([i, o]);
80
+ const { promise: o, clear: c } = gt(i.timeout, i.timeoutErrorMessage), a = e().finally(c);
81
+ return await Promise.race([a, o]);
82
82
  } catch (o) {
83
- if (n = o, !a.shouldRetryFn(o) || c >= a.limit)
83
+ if (n = o, !i.shouldRetryFn(o) || s >= i.limit)
84
84
  throw o;
85
- await Je(a.delayMs), a.onRetry(o);
85
+ await Je(i.delayMs), i.onRetry(o);
86
86
  }
87
87
  throw n;
88
88
  }
@@ -91,13 +91,13 @@ function ke(e) {
91
91
  return window.localStorage.setItem("did_external_key_id", e), e;
92
92
  let t = window.localStorage.getItem("did_external_key_id");
93
93
  if (!t) {
94
- let a = de();
95
- window.localStorage.setItem("did_external_key_id", a), t = a;
94
+ let i = le();
95
+ window.localStorage.setItem("did_external_key_id", i), t = i;
96
96
  }
97
97
  return t;
98
98
  }
99
- let ht = de();
100
- function Oe(e, t) {
99
+ let ht = le();
100
+ function We(e, t) {
101
101
  if (e.type === "bearer")
102
102
  return `Bearer ${e.token}`;
103
103
  if (e.type === "basic")
@@ -106,105 +106,105 @@ function Oe(e, t) {
106
106
  return `Client-Key ${e.clientKey}.${ke(t)}_${ht}`;
107
107
  throw new Error(`Unknown auth type: ${e}`);
108
108
  }
109
- const pt = (e) => Ce(e, {
109
+ const pt = (e) => Se(e, {
110
110
  limit: 3,
111
111
  delayMs: 1e3,
112
112
  timeout: 0,
113
113
  shouldRetryFn: (t) => t.status === 429
114
114
  });
115
- function Te(e, t = ge, a, n) {
116
- const c = async (o, s) => {
117
- const { skipErrorHandler: i, ...r } = s || {}, d = await pt(
115
+ function Te(e, t = ge, i, n) {
116
+ const s = async (o, c) => {
117
+ const { skipErrorHandler: a, ...r } = c || {}, d = await pt(
118
118
  () => fetch(t + (o != null && o.startsWith("/") ? o : `/${o}`), {
119
119
  ...r,
120
120
  headers: {
121
121
  ...r.headers,
122
- Authorization: Oe(e, n),
122
+ Authorization: We(e, n),
123
123
  "Content-Type": "application/json"
124
124
  }
125
125
  })
126
126
  );
127
127
  if (!d.ok) {
128
- let g = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
129
- const w = new Error(g);
130
- throw a && !i && a(w, { url: o, options: r, headers: d.headers }), w;
128
+ let w = await d.text().catch(() => `Failed to fetch with status ${d.status}`);
129
+ const p = new Error(w);
130
+ throw i && !a && i(p, { url: o, options: r, headers: d.headers }), p;
131
131
  }
132
132
  return d.json();
133
133
  };
134
134
  return {
135
- get(o, s) {
136
- return c(o, { ...s, method: "GET" });
135
+ get(o, c) {
136
+ return s(o, { ...c, method: "GET" });
137
137
  },
138
- post(o, s, i) {
139
- return c(o, { ...i, body: JSON.stringify(s), method: "POST" });
138
+ post(o, c, a) {
139
+ return s(o, { ...a, body: JSON.stringify(c), method: "POST" });
140
140
  },
141
- delete(o, s, i) {
142
- return c(o, { ...i, body: JSON.stringify(s), method: "DELETE" });
141
+ delete(o, c, a) {
142
+ return s(o, { ...a, body: JSON.stringify(c), method: "DELETE" });
143
143
  },
144
- patch(o, s, i) {
145
- return c(o, { ...i, body: JSON.stringify(s), method: "PATCH" });
144
+ patch(o, c, a) {
145
+ return s(o, { ...a, body: JSON.stringify(c), method: "PATCH" });
146
146
  }
147
147
  };
148
148
  }
149
- function wt(e, t = ge, a, n) {
150
- const c = Te(e, `${t}/agents`, a, n);
149
+ function wt(e, t = ge, i, n) {
150
+ const s = Te(e, `${t}/agents`, i, n);
151
151
  return {
152
- create(o, s) {
153
- return c.post("/", o, s);
152
+ create(o, c) {
153
+ return s.post("/", o, c);
154
154
  },
155
- getAgents(o, s) {
156
- return c.get(`/${o ? `?tag=${o}` : ""}`, s).then((i) => i ?? []);
155
+ getAgents(o, c) {
156
+ return s.get(`/${o ? `?tag=${o}` : ""}`, c).then((a) => a ?? []);
157
157
  },
158
- getById(o, s) {
159
- return c.get(`/${o}`, s);
158
+ getById(o, c) {
159
+ return s.get(`/${o}`, c);
160
160
  },
161
- delete(o, s) {
162
- return c.delete(`/${o}`, void 0, s);
161
+ delete(o, c) {
162
+ return s.delete(`/${o}`, void 0, c);
163
163
  },
164
- update(o, s, i) {
165
- return c.patch(`/${o}`, s, i);
164
+ update(o, c, a) {
165
+ return s.patch(`/${o}`, c, a);
166
166
  },
167
- newChat(o, s, i) {
168
- return c.post(`/${o}/chat`, s, i);
167
+ newChat(o, c, a) {
168
+ return s.post(`/${o}/chat`, c, a);
169
169
  },
170
- chat(o, s, i, r) {
171
- return c.post(`/${o}/chat/${s}`, i, r);
170
+ chat(o, c, a, r) {
171
+ return s.post(`/${o}/chat/${c}`, a, r);
172
172
  },
173
- createRating(o, s, i, r) {
174
- return c.post(`/${o}/chat/${s}/ratings`, i, r);
173
+ createRating(o, c, a, r) {
174
+ return s.post(`/${o}/chat/${c}/ratings`, a, r);
175
175
  },
176
- updateRating(o, s, i, r, d) {
177
- return c.patch(`/${o}/chat/${s}/ratings/${i}`, r, d);
176
+ updateRating(o, c, a, r, d) {
177
+ return s.patch(`/${o}/chat/${c}/ratings/${a}`, r, d);
178
178
  },
179
- deleteRating(o, s, i, r) {
180
- return c.delete(`/${o}/chat/${s}/ratings/${i}`, r);
179
+ deleteRating(o, c, a, r) {
180
+ return s.delete(`/${o}/chat/${c}/ratings/${a}`, r);
181
181
  },
182
- getSTTToken(o, s) {
183
- return c.get(`/${o}/stt-token`, s);
182
+ getSTTToken(o, c) {
183
+ return s.get(`/${o}/stt-token`, c);
184
184
  }
185
185
  };
186
186
  }
187
187
  function yt(e) {
188
- var c, o, s, i;
189
- const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", a = () => {
188
+ var s, o, c, a;
189
+ const t = () => /Mobi|Android/i.test(navigator.userAgent) ? "Mobile" : "Desktop", i = () => {
190
190
  const r = navigator.platform;
191
191
  return r.toLowerCase().includes("win") ? "Windows" : r.toLowerCase().includes("mac") ? "Mac OS X" : r.toLowerCase().includes("linux") ? "Linux" : "Unknown";
192
192
  }, n = e.presenter;
193
193
  return {
194
- $os: `${a()}`,
194
+ $os: `${i()}`,
195
195
  isMobile: `${t() == "Mobile"}`,
196
196
  browser: navigator.userAgent,
197
197
  origin: window.location.origin,
198
198
  agentType: Ue(n),
199
199
  agentVoice: {
200
- voiceId: (o = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : o.voice_id,
201
- provider: (i = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : i.type
200
+ voiceId: (o = (s = e.presenter) == null ? void 0 : s.voice) == null ? void 0 : o.voice_id,
201
+ provider: (a = (c = e.presenter) == null ? void 0 : c.voice) == null ? void 0 : a.type
202
202
  }
203
203
  };
204
204
  }
205
205
  function vt(e) {
206
- var a, n, c, o, s, i;
207
- const t = (a = e.llm) == null ? void 0 : a.prompt_customization;
206
+ var i, n, s, o, c, a;
207
+ const t = (i = e.llm) == null ? void 0 : i.prompt_customization;
208
208
  return {
209
209
  agentType: Ue(e.presenter),
210
210
  owner_id: e.owner_id ?? "",
@@ -212,11 +212,11 @@ function vt(e) {
212
212
  behavior: {
213
213
  role: t == null ? void 0 : t.role,
214
214
  personality: t == null ? void 0 : t.personality,
215
- instructions: (c = e.llm) == null ? void 0 : c.instructions
215
+ instructions: (s = e.llm) == null ? void 0 : s.instructions
216
216
  },
217
217
  temperature: (o = e.llm) == null ? void 0 : o.temperature,
218
218
  knowledgeSource: t == null ? void 0 : t.knowledge_source,
219
- starterQuestionsCount: (i = (s = e.knowledge) == null ? void 0 : s.starter_message) == null ? void 0 : i.length,
219
+ starterQuestionsCount: (a = (c = e.knowledge) == null ? void 0 : c.starter_message) == null ? void 0 : a.length,
220
220
  topicsToAvoid: t == null ? void 0 : t.topics_to_avoid,
221
221
  maxResponseLength: t == null ? void 0 : t.max_response_length,
222
222
  agentId: e.id,
@@ -225,19 +225,19 @@ function vt(e) {
225
225
  ...e.access === "public" ? { from: "agent-template" } : {}
226
226
  };
227
227
  }
228
- const St = (e) => e.reduce((t, a) => t + a, 0), $e = (e) => St(e) / e.length;
229
- function Ct(e, t, a) {
230
- var r, d, g;
231
- const { event: n, ...c } = e, { template: o } = (t == null ? void 0 : t.llm) || {}, { language: s } = ((r = t == null ? void 0 : t.presenter) == null ? void 0 : r.voice) || {};
228
+ const Ct = (e) => e.reduce((t, i) => t + i, 0), $e = (e) => Ct(e) / e.length;
229
+ function St(e, t, i) {
230
+ var r, d, w;
231
+ const { event: n, ...s } = e, { template: o } = (t == null ? void 0 : t.llm) || {}, { language: c } = ((r = t == null ? void 0 : t.presenter) == null ? void 0 : r.voice) || {};
232
232
  return {
233
- ...c,
234
- llm: { ...c.llm, template: o },
235
- script: { ...c.script, provider: { ...(d = c == null ? void 0 : c.script) == null ? void 0 : d.provider, language: s } },
236
- stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (g = t == null ? void 0 : t.presenter) == null ? void 0 : g.stitch : void 0,
237
- ...a
233
+ ...s,
234
+ llm: { ...s.llm, template: o },
235
+ script: { ...s.script, provider: { ...(d = s == null ? void 0 : s.script) == null ? void 0 : d.provider, language: c } },
236
+ stitch: (t == null ? void 0 : t.presenter.type) === "talk" ? (w = t == null ? void 0 : t.presenter) == null ? void 0 : w.stitch : void 0,
237
+ ...i
238
238
  };
239
239
  }
240
- function xe(e) {
240
+ function Be(e) {
241
241
  "requestIdleCallback" in window ? requestIdleCallback(e, { timeout: 2e3 }) : setTimeout(e, 0);
242
242
  }
243
243
  let ve = {};
@@ -253,14 +253,14 @@ function Rt(e) {
253
253
  ...e.mixpanelAdditionalProperties || {}
254
254
  },
255
255
  isEnabled: e.isEnabled ?? !0,
256
- getRandom: de,
257
- enrich(a) {
258
- this.additionalProperties = { ...this.additionalProperties, ...a };
256
+ getRandom: le,
257
+ enrich(i) {
258
+ this.additionalProperties = { ...this.additionalProperties, ...i };
259
259
  },
260
- async track(a, n, c) {
260
+ async track(i, n, s) {
261
261
  if (!this.isEnabled)
262
262
  return Promise.resolve();
263
- const { audioPath: o, ...s } = n || {}, i = c || Date.now(), r = {
263
+ const { audioPath: o, ...c } = n || {}, a = s || Date.now(), r = {
264
264
  method: "POST",
265
265
  headers: {
266
266
  "Content-Type": "application/x-www-form-urlencoded"
@@ -268,14 +268,14 @@ function Rt(e) {
268
268
  body: new URLSearchParams({
269
269
  data: JSON.stringify([
270
270
  {
271
- event: a,
271
+ event: i,
272
272
  properties: {
273
273
  ...this.additionalProperties,
274
- ...s,
274
+ ...c,
275
275
  agentId: this.agentId,
276
276
  source: t,
277
277
  token: this.token,
278
- time: i,
278
+ time: a,
279
279
  $insert_id: this.getRandom(),
280
280
  origin: window.location.href,
281
281
  "Screen Height": window.screen.height || window.innerWidth,
@@ -291,17 +291,17 @@ function Rt(e) {
291
291
  keepalive: !0
292
292
  }).catch((d) => console.error("Analytics tracking error:", d)), Promise.resolve();
293
293
  },
294
- linkTrack(a, n, c, o) {
295
- ve[a] || (ve[a] = { events: {}, resolvedDependencies: [] }), o.includes(c) || o.push(c);
296
- const s = ve[a];
297
- if (s.events[c] = { props: n }, s.resolvedDependencies.push(c), o.every(
298
- (r) => s.resolvedDependencies.includes(r)
294
+ linkTrack(i, n, s, o) {
295
+ ve[i] || (ve[i] = { events: {}, resolvedDependencies: [] }), o.includes(s) || o.push(s);
296
+ const c = ve[i];
297
+ if (c.events[s] = { props: n }, c.resolvedDependencies.push(s), o.every(
298
+ (r) => c.resolvedDependencies.includes(r)
299
299
  )) {
300
- const r = o.reduce((d, g) => s.events[g] ? { ...d, ...s.events[g].props } : d, {});
301
- this.track(a, r), s.resolvedDependencies = s.resolvedDependencies.filter(
300
+ const r = o.reduce((d, w) => c.events[w] ? { ...d, ...c.events[w].props } : d, {});
301
+ this.track(i, r), c.resolvedDependencies = c.resolvedDependencies.filter(
302
302
  (d) => !o.includes(d)
303
303
  ), o.forEach((d) => {
304
- delete s.events[d];
304
+ delete c.events[d];
305
305
  });
306
306
  }
307
307
  }
@@ -315,19 +315,19 @@ function _e() {
315
315
  get: (t = !1) => t ? Date.now() - e : e
316
316
  };
317
317
  }
318
- const ie = _e(), Re = _e(), Be = _e();
319
- function Ve(e) {
318
+ const ee = _e(), Re = _e(), xe = _e();
319
+ function Oe(e) {
320
320
  return e === F.Playground ? { headers: { [ut]: "true" } } : {};
321
321
  }
322
- async function qe(e, t, a, n, c = !1, o) {
322
+ async function He(e, t, i, n, s = !1, o) {
323
323
  try {
324
- return !o && !We(n) && (o = await t.newChat(e.id, { persist: c }, Ve(n)), a.track("agent-chat", {
324
+ return !o && !Ve(n) && (o = await t.newChat(e.id, { persist: s }, Oe(n)), i.track("agent-chat", {
325
325
  event: "created",
326
326
  chatId: o.id,
327
327
  mode: n
328
328
  })), { chat: o, chatMode: (o == null ? void 0 : o.chat_mode) ?? n };
329
- } catch (s) {
330
- throw Dt(s) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
329
+ } catch (c) {
330
+ throw Dt(c) === "InsufficientCreditsError" ? new Error("InsufficientCreditsError") : new Error("Cannot create new chat");
331
331
  }
332
332
  }
333
333
  const Dt = (e) => {
@@ -341,16 +341,16 @@ const Dt = (e) => {
341
341
  function Mt(e) {
342
342
  return e && e.length > 0 ? e : [];
343
343
  }
344
- function Et(e, t, a, n) {
345
- const c = Te(e, `${t}/v2/agents/${a}`, n);
344
+ function Et(e, t, i, n) {
345
+ const s = Te(e, `${t}/v2/agents/${i}`, n);
346
346
  return {
347
347
  async createStream(o) {
348
- return c.post("/sessions", o);
348
+ return s.post("/sessions", o);
349
349
  }
350
350
  };
351
351
  }
352
- const He = (e, t) => (a, n) => e && console.log(`[${t}] ${a}`, n ?? "");
353
- async function Se() {
352
+ const qe = (e, t) => (i, n) => e && console.log(`[${t}] ${i}`, n ?? "");
353
+ async function Ce() {
354
354
  try {
355
355
  return await import("./livekit-client.esm-C1GRQdZY.js");
356
356
  } catch {
@@ -360,248 +360,241 @@ async function Se() {
360
360
  }
361
361
  }
362
362
  const It = {
363
- excellent: re.Strong,
364
- good: re.Strong,
365
- poor: re.Weak,
366
- lost: re.Unknown,
367
- unknown: re.Unknown
363
+ excellent: ie.Strong,
364
+ good: ie.Strong,
365
+ poor: ie.Weak,
366
+ lost: ie.Unknown,
367
+ unknown: ie.Unknown
368
368
  }, me = JSON.stringify({
369
369
  kind: "InternalServerError",
370
370
  description: "Stream Error"
371
371
  });
372
372
  var Ae = /* @__PURE__ */ ((e) => (e.Chat = "lk.chat", e.Speak = "did.speak", e.Interrupt = "did.interrupt", e))(Ae || {});
373
- function De(e, t, a, n) {
374
- var c, o;
375
- throw t("Failed to connect to LiveKit room:", e), n(), (c = a.onConnectionStateChange) == null || c.call(a, S.Fail), (o = a.onError) == null || o.call(a, e, { sessionId: "" }), e;
373
+ function De(e, t, i) {
374
+ var n, s;
375
+ throw t("Failed to connect to LiveKit room:", e), (n = i.onConnectionStateChange) == null || n.call(i, R.Fail), (s = i.onError) == null || s.call(i, e, { sessionId: "" }), e;
376
376
  }
377
- async function Tt(e, t, a) {
378
- var Pe, Le;
379
- const n = He(a.debug || !1, "LiveKitStreamingManager"), { Room: c, RoomEvent: o, ConnectionState: s } = await Se(), { callbacks: i, auth: r, baseURL: d, analytics: g, microphoneStream: w } = a;
380
- let u = null, M = !1;
377
+ async function Tt(e, t, i) {
378
+ var Pe;
379
+ const n = qe(i.debug || !1, "LiveKitStreamingManager"), { Room: s, RoomEvent: o, ConnectionState: c } = await Ce(), { callbacks: a, auth: r, baseURL: d, analytics: w, microphoneStream: p } = i;
380
+ let u = null, _ = !1;
381
381
  const $ = ae.Fluent;
382
- let V = !0, E = null, I = null;
383
- u = new c({
382
+ let A = null, C = null, B = !1;
383
+ u = new s({
384
384
  adaptiveStream: !1,
385
385
  // Must be false to use mediaStreamTrack directly
386
386
  dynacast: !0
387
387
  });
388
388
  let z = null;
389
- const A = 2e4;
390
- let W = U.Idle;
391
- const ee = Et(r, d || ge, e, i.onError);
392
- let T, G, Z;
389
+ const I = 2e4;
390
+ let U = W.Idle;
391
+ const te = Et(r, d || ge, e, a.onError);
392
+ let M, Y, Z;
393
393
  try {
394
- const l = await ee.createStream({
394
+ const l = await te.createStream({
395
395
  transport_provider: ye.Livekit,
396
396
  chat_persist: t.chat_persist ?? !0
397
- }), { id: h, session_token: v, session_url: R } = l;
398
- (Pe = i.onStreamCreated) == null || Pe.call(i, { session_id: h, stream_id: h, agent_id: e }), T = h, G = v, Z = R, await u.prepareConnection(Z, G);
397
+ }), { id: g, session_token: v, session_url: D } = l;
398
+ (Pe = a.onStreamCreated) == null || Pe.call(a, { session_id: g, stream_id: g, agent_id: e }), M = g, Y = v, Z = D, await u.prepareConnection(Z, Y);
399
399
  } catch (l) {
400
- De(l, n, i, () => {
401
- V = !1;
402
- });
400
+ De(l, n, a);
403
401
  }
404
- if (!Z || !G || !T)
402
+ if (!Z || !Y || !M)
405
403
  return Promise.reject(new Error("Failed to initialize LiveKit stream"));
406
- u.on(o.ConnectionStateChanged, y).on(o.ConnectionQualityChanged, k).on(o.ActiveSpeakersChanged, P).on(o.ParticipantConnected, L).on(o.ParticipantDisconnected, _).on(o.TrackSubscribed, J).on(o.TrackUnsubscribed, H).on(o.DataReceived, Q).on(o.MediaDevicesError, b).on(o.TranscriptionReceived, f).on(o.EncryptionError, N).on(o.TrackSubscriptionFailed, X), (Le = i.onConnectionStateChange) == null || Le.call(i, S.New);
407
- function f(l, h) {
404
+ u.on(o.ConnectionStateChanged, y).on(o.ConnectionQualityChanged, k).on(o.ActiveSpeakersChanged, T).on(o.ParticipantConnected, P).on(o.ParticipantDisconnected, E).on(o.TrackSubscribed, J).on(o.TrackUnsubscribed, O).on(o.DataReceived, H).on(o.MediaDevicesError, L).on(o.TranscriptionReceived, f).on(o.EncryptionError, N).on(o.TrackSubscriptionFailed, q);
405
+ function f(l, g) {
408
406
  var v;
409
- h != null && h.isLocal && W === U.Talking && ((v = i.onInterruptDetected) == null || v.call(i, { type: "audio" }), W = U.Idle);
407
+ g != null && g.isLocal && (ee.update(), U === W.Talking && ((v = a.onInterruptDetected) == null || v.call(a, { type: "audio" }), U = W.Idle));
410
408
  }
411
409
  try {
412
- await u.connect(Z, G), n("LiveKit room joined successfully"), z = setTimeout(() => {
410
+ await u.connect(Z, Y), n("LiveKit room joined successfully"), z = setTimeout(() => {
413
411
  var l;
414
- n("Track subscription timeout - no track subscribed within 30 seconds after connect"), z = null, g.track("connectivity-error", {
412
+ n("Track subscription timeout - no track subscribed within 30 seconds after connect"), z = null, w.track("connectivity-error", {
415
413
  error: "Track subscription timeout",
416
- sessionId: T
417
- }), (l = i.onError) == null || l.call(i, new Error("Track subscription timeout"), { sessionId: T }), se();
418
- }, A), V = !1;
414
+ sessionId: M
415
+ }), (l = a.onError) == null || l.call(a, new Error("Track subscription timeout"), { sessionId: M }), ce();
416
+ }, I);
419
417
  } catch (l) {
420
- De(l, n, i, () => {
421
- V = !1;
422
- });
418
+ De(l, n, a);
423
419
  }
424
- g.enrich({
420
+ w.enrich({
425
421
  "stream-type": $
426
422
  });
427
423
  function y(l) {
428
- var h, v, R, D, q;
424
+ var g, v, D, b;
429
425
  switch (n("Connection state changed:", l), l) {
430
- case s.Connecting:
431
- (h = i.onConnectionStateChange) == null || h.call(i, S.Connecting);
426
+ case c.Connecting:
427
+ n("CALLBACK: onConnectionStateChange(Connecting)"), (g = a.onConnectionStateChange) == null || g.call(a, R.Connecting);
432
428
  break;
433
- case s.Connected:
434
- n("LiveKit room connected successfully"), M = !0, V ? queueMicrotask(() => {
435
- var x;
436
- (x = i.onConnectionStateChange) == null || x.call(i, S.Connected);
437
- }) : (v = i.onConnectionStateChange) == null || v.call(i, S.Connected);
429
+ case c.Connected:
430
+ n("LiveKit room connected successfully"), _ = !0;
438
431
  break;
439
- case s.Disconnected:
440
- n("LiveKit room disconnected"), M = !1, (R = i.onConnectionStateChange) == null || R.call(i, S.Disconnected);
432
+ case c.Disconnected:
433
+ n("LiveKit room disconnected"), _ = !1, B = !1, (v = a.onConnectionStateChange) == null || v.call(a, R.Disconnected);
441
434
  break;
442
- case s.Reconnecting:
443
- n("LiveKit room reconnecting..."), (D = i.onConnectionStateChange) == null || D.call(i, S.Connecting);
435
+ case c.Reconnecting:
436
+ n("LiveKit room reconnecting..."), (D = a.onConnectionStateChange) == null || D.call(a, R.Connecting);
444
437
  break;
445
- case s.SignalReconnecting:
446
- n("LiveKit room signal reconnecting..."), (q = i.onConnectionStateChange) == null || q.call(i, S.Connecting);
438
+ case c.SignalReconnecting:
439
+ n("LiveKit room signal reconnecting..."), (b = a.onConnectionStateChange) == null || b.call(a, R.Connecting);
447
440
  break;
448
441
  }
449
442
  }
450
- function k(l, h) {
443
+ function k(l, g) {
451
444
  var v;
452
- n("Connection quality:", l), h != null && h.isLocal && ((v = i.onConnectivityStateChange) == null || v.call(i, It[l]));
445
+ n("Connection quality:", l), g != null && g.isLocal && ((v = a.onConnectivityStateChange) == null || v.call(a, It[l]));
453
446
  }
454
- function P(l) {
455
- var v, R;
456
- n("Active speakers changed:", l), l.find((D) => !D.isLocal) ? (W = U.Talking, (v = i.onAgentActivityStateChange) == null || v.call(i, U.Talking)) : ((R = i.onAgentActivityStateChange) == null || R.call(i, U.Idle), W = U.Idle);
447
+ function T(l) {
448
+ n("Active speakers changed:", l);
457
449
  }
458
- function L(l) {
450
+ function P(l) {
459
451
  n("Participant connected:", l.identity);
460
452
  }
461
- function _(l) {
462
- n("Participant disconnected:", l.identity), se();
453
+ function E(l) {
454
+ n("Participant disconnected:", l.identity), ce();
463
455
  }
464
- function J(l, h, v) {
465
- var D, q, x;
456
+ function J(l, g, v) {
457
+ var b, Q, G, se;
466
458
  n(`Track subscribed: ${l.kind} from ${v.identity}`), z && (clearTimeout(z), z = null, n("Track subscription timeout cleared"));
467
- const R = l.mediaStreamTrack;
468
- if (!R) {
459
+ const D = l.mediaStreamTrack;
460
+ if (!D) {
469
461
  n(`No mediaStreamTrack available for ${l.kind}`);
470
462
  return;
471
463
  }
472
- E ? (E.addTrack(R), n(`Added ${l.kind} track to shared MediaStream`)) : (E = new MediaStream([R]), n(`Created shared MediaStream with ${l.kind} track`)), l.kind === "video" && ((D = i.onStreamReady) == null || D.call(i), (q = i.onSrcObjectReady) == null || q.call(i, E), (x = i.onVideoStateChange) == null || x.call(i, C.Start));
464
+ A ? (A.addTrack(D), n(`Added ${l.kind} track to shared MediaStream`)) : (A = new MediaStream([D]), n(`Created shared MediaStream with ${l.kind} track`)), l.kind === "video" && ((b = a.onStreamReady) == null || b.call(a), n("CALLBACK: onSrcObjectReady"), (Q = a.onSrcObjectReady) == null || Q.call(a, A), B || (B = !0, n("CALLBACK: onConnectionStateChange(Connected)"), (G = a.onConnectionStateChange) == null || G.call(a, R.Connected)), n("CALLBACK: onVideoStateChange(Start)"), (se = a.onVideoStateChange) == null || se.call(a, S.Start));
473
465
  }
474
- function H(l, h, v) {
475
- var R;
476
- n(`Track unsubscribed: ${l.kind} from ${v.identity}`), l.kind === "video" && ((R = i.onVideoStateChange) == null || R.call(i, C.Stop));
466
+ function O(l, g, v) {
467
+ var D;
468
+ n(`Track unsubscribed: ${l.kind} from ${v.identity}`), l.kind === "video" && ((D = a.onVideoStateChange) == null || D.call(a, S.Stop));
477
469
  }
478
- function Q(l, h, v, R) {
479
- var q, x, ue, be;
480
- const D = new TextDecoder().decode(l);
481
- n("Data received:", D);
470
+ function H(l, g, v, D) {
471
+ var Q, G, se, Le, be;
472
+ const b = new TextDecoder().decode(l);
473
+ n("Data received:", b);
482
474
  try {
483
- const te = JSON.parse(D), le = R || te.subject;
484
- if (le === j.ChatAnswer) {
485
- const ne = Y.Answer;
486
- (q = i.onMessage) == null || q.call(i, ne, {
487
- event: ne,
488
- ...te
475
+ const ne = JSON.parse(b), de = D || ne.subject;
476
+ if (de === j.ChatAnswer) {
477
+ const re = X.Answer;
478
+ (Q = a.onMessage) == null || Q.call(a, re, {
479
+ event: re,
480
+ ...ne
489
481
  });
490
- } else if (le === j.ChatPartial) {
491
- const ne = Y.Partial;
492
- (x = i.onMessage) == null || x.call(i, ne, {
493
- event: ne,
494
- ...te
482
+ } else if (de === j.ChatPartial) {
483
+ const re = X.Partial;
484
+ (G = a.onMessage) == null || G.call(a, re, {
485
+ event: re,
486
+ ...ne
495
487
  });
496
- } else if ([j.StreamVideoCreated, j.StreamVideoDone].includes(le)) {
497
- const ne = (te == null ? void 0 : te.role) || (h == null ? void 0 : h.identity) || "datachannel";
498
- (ue = i.onMessage) == null || ue.call(i, le, {
499
- [ne]: te
488
+ } else if ([j.StreamVideoCreated, j.StreamVideoDone].includes(de)) {
489
+ U = de === j.StreamVideoCreated ? W.Talking : W.Idle, (se = a.onAgentActivityStateChange) == null || se.call(a, U);
490
+ const re = (ne == null ? void 0 : ne.role) || (g == null ? void 0 : g.identity) || "datachannel";
491
+ (Le = a.onMessage) == null || Le.call(a, de, {
492
+ [re]: ne
500
493
  });
501
- } else if (le === j.ChatAudioTranscribed) {
502
- const ne = Y.Transcribe;
503
- (be = i.onMessage) == null || be.call(i, ne, {
504
- event: ne,
505
- ...te
494
+ } else if (de === j.ChatAudioTranscribed) {
495
+ const re = X.Transcribe;
496
+ (be = a.onMessage) == null || be.call(a, re, {
497
+ event: re,
498
+ ...ne
506
499
  }), queueMicrotask(() => {
507
500
  var je;
508
- (je = i.onAgentActivityStateChange) == null || je.call(i, U.Loading);
501
+ (je = a.onAgentActivityStateChange) == null || je.call(a, W.Loading);
509
502
  });
510
503
  }
511
- } catch (te) {
512
- n("Failed to parse data channel message:", te);
504
+ } catch (ne) {
505
+ n("Failed to parse data channel message:", ne);
513
506
  }
514
507
  }
515
- function b(l) {
516
- var h;
517
- n("Media devices error:", l), (h = i.onError) == null || h.call(i, new Error(me), { sessionId: T });
508
+ function L(l) {
509
+ var g;
510
+ n("Media devices error:", l), (g = a.onError) == null || g.call(a, new Error(me), { sessionId: M });
518
511
  }
519
512
  function N(l) {
520
- var h;
521
- n("Encryption error:", l), (h = i.onError) == null || h.call(i, new Error(me), { sessionId: T });
513
+ var g;
514
+ n("Encryption error:", l), (g = a.onError) == null || g.call(a, new Error(me), { sessionId: M });
522
515
  }
523
- function X(l, h, v) {
524
- n("Track subscription failed:", { trackSid: l, participant: h, reason: v });
516
+ function q(l, g, v) {
517
+ n("Track subscription failed:", { trackSid: l, participant: g, reason: v });
525
518
  }
526
519
  async function oe(l) {
527
520
  if (!u) return null;
528
- const { Track: h } = await Se(), v = u.localParticipant.audioTrackPublications;
521
+ const { Track: g } = await Ce(), v = u.localParticipant.audioTrackPublications;
529
522
  if (v) {
530
- for (const [R, D] of v)
531
- if (D.source === h.Source.Microphone && D.track) {
532
- const x = D.track.mediaStreamTrack;
533
- if (x === l || x && x.id === l.id)
534
- return D;
523
+ for (const [D, b] of v)
524
+ if (b.source === g.Source.Microphone && b.track) {
525
+ const G = b.track.mediaStreamTrack;
526
+ if (G === l || G && G.id === l.id)
527
+ return b;
535
528
  }
536
529
  }
537
530
  return null;
538
531
  }
539
- function O(l) {
540
- if (!I || !I.track)
532
+ function V(l) {
533
+ if (!C || !C.track)
541
534
  return !1;
542
- const h = I.track.mediaStreamTrack;
543
- return h !== l && (h == null ? void 0 : h.id) !== l.id;
535
+ const g = C.track.mediaStreamTrack;
536
+ return g !== l && (g == null ? void 0 : g.id) !== l.id;
544
537
  }
545
538
  async function m(l) {
546
- var q, x;
547
- if (!M || !u)
539
+ var Q, G;
540
+ if (!_ || !u)
548
541
  throw n("Room is not connected, cannot publish microphone stream"), new Error("Room is not connected");
549
- const h = l.getAudioTracks();
550
- if (h.length === 0) {
542
+ const g = l.getAudioTracks();
543
+ if (g.length === 0) {
551
544
  n("No audio track found in the provided MediaStream");
552
545
  return;
553
546
  }
554
- const v = h[0], { Track: R } = await Se(), D = await oe(v);
555
- if (D) {
547
+ const v = g[0], { Track: D } = await Ce(), b = await oe(v);
548
+ if (b) {
556
549
  n("Microphone track is already published, skipping", {
557
550
  trackId: v.id,
558
- publishedTrackId: (x = (q = D.track) == null ? void 0 : q.mediaStreamTrack) == null ? void 0 : x.id
559
- }), I = D;
551
+ publishedTrackId: (G = (Q = b.track) == null ? void 0 : Q.mediaStreamTrack) == null ? void 0 : G.id
552
+ }), C = b;
560
553
  return;
561
554
  }
562
- O(v) && (n("Unpublishing existing microphone track before publishing new one"), await p()), n("Publishing microphone track from provided MediaStream", { trackId: v.id });
555
+ V(v) && (n("Unpublishing existing microphone track before publishing new one"), await h()), n("Publishing microphone track from provided MediaStream", { trackId: v.id });
563
556
  try {
564
- I = await u.localParticipant.publishTrack(v, {
565
- source: R.Source.Microphone
566
- }), n("Microphone track published successfully", { trackSid: I.trackSid });
567
- } catch (ue) {
568
- throw n("Failed to publish microphone track:", ue), ue;
557
+ C = await u.localParticipant.publishTrack(v, {
558
+ source: D.Source.Microphone
559
+ }), n("Microphone track published successfully", { trackSid: C.trackSid });
560
+ } catch (se) {
561
+ throw n("Failed to publish microphone track:", se), se;
569
562
  }
570
563
  }
571
- async function p() {
572
- if (!(!I || !I.track))
564
+ async function h() {
565
+ if (!(!C || !C.track))
573
566
  try {
574
- u && (await u.localParticipant.unpublishTrack(I.track), n("Microphone track unpublished"));
567
+ u && (await u.localParticipant.unpublishTrack(C.track), n("Microphone track unpublished"));
575
568
  } catch (l) {
576
569
  n("Error unpublishing microphone track:", l);
577
570
  } finally {
578
- I = null;
571
+ C = null;
579
572
  }
580
573
  }
581
- function B() {
582
- E && (E.getTracks().forEach((l) => l.stop()), E = null);
574
+ function x() {
575
+ A && (A.getTracks().forEach((l) => l.stop()), A = null);
583
576
  }
584
- async function K(l, h) {
585
- var v, R;
586
- if (!M || !u) {
587
- n("Room is not connected for sending messages"), (v = i.onError) == null || v.call(i, new Error(me), {
588
- sessionId: T
577
+ async function K(l, g) {
578
+ var v, D;
579
+ if (!_ || !u) {
580
+ n("Room is not connected for sending messages"), (v = a.onError) == null || v.call(a, new Error(me), {
581
+ sessionId: M
589
582
  });
590
583
  return;
591
584
  }
592
585
  try {
593
- await u.localParticipant.sendText(l, { topic: h }), n("Message sent successfully:", l);
594
- } catch (D) {
595
- n("Failed to send message:", D), (R = i.onError) == null || R.call(i, new Error(me), { sessionId: T });
586
+ await u.localParticipant.sendText(l, { topic: g }), n("Message sent successfully:", l);
587
+ } catch (b) {
588
+ n("Failed to send message:", b), (D = a.onError) == null || D.call(a, new Error(me), { sessionId: M });
596
589
  }
597
590
  }
598
591
  async function he(l) {
599
- var h;
592
+ var g;
600
593
  try {
601
- const R = JSON.parse(l).topic;
602
- return K("", R);
594
+ const D = JSON.parse(l).topic;
595
+ return K("", D);
603
596
  } catch (v) {
604
- n("Failed to send data channel message:", v), (h = i.onError) == null || h.call(i, new Error(me), { sessionId: T });
597
+ n("Failed to send data channel message:", v), (g = a.onError) == null || g.call(a, new Error(me), { sessionId: M });
605
598
  }
606
599
  }
607
600
  function pe(l) {
@@ -611,53 +604,52 @@ async function Tt(e, t, a) {
611
604
  /* Chat */
612
605
  );
613
606
  }
614
- async function se() {
615
- var l, h;
616
- z && (clearTimeout(z), z = null), u && (await p(), await u.disconnect()), B(), M = !1, (l = i.onConnectionStateChange) == null || l.call(i, S.Disconnected), (h = i.onAgentActivityStateChange) == null || h.call(i, U.Idle), W = U.Idle;
607
+ async function ce() {
608
+ var l, g;
609
+ z && (clearTimeout(z), z = null), u && (await h(), await u.disconnect()), x(), _ = !1, B = !1, (l = a.onConnectionStateChange) == null || l.call(a, R.Disconnected), (g = a.onAgentActivityStateChange) == null || g.call(a, W.Idle), U = W.Idle;
617
610
  }
618
611
  return {
619
612
  speak(l) {
620
- const h = typeof l == "string" ? l : JSON.stringify(l);
613
+ const g = typeof l == "string" ? l : JSON.stringify(l);
621
614
  return K(
622
- h,
615
+ g,
623
616
  "did.speak"
624
617
  /* Speak */
625
618
  );
626
619
  },
627
- disconnect: se,
620
+ disconnect: ce,
628
621
  async reconnect() {
629
- var l, h, v;
630
- if ((u == null ? void 0 : u.state) === s.Connected) {
622
+ var l, g;
623
+ if ((u == null ? void 0 : u.state) === c.Connected) {
631
624
  n("Room is already connected");
632
625
  return;
633
626
  }
634
- if (!u || !Z || !G)
627
+ if (!u || !Z || !Y)
635
628
  throw n("Cannot reconnect: missing room, URL or token"), new Error("Cannot reconnect: session not available");
636
- n("Reconnecting to LiveKit room, state:", u.state), (l = i.onConnectionStateChange) == null || l.call(i, S.Connecting);
629
+ n("Reconnecting to LiveKit room, state:", u.state), B = !1, (l = a.onConnectionStateChange) == null || l.call(a, R.Connecting);
637
630
  try {
638
- if (await u.connect(Z, G), n("Room reconnected"), M = !0, u.remoteParticipants.size === 0) {
631
+ if (await u.connect(Z, Y), n("Room reconnected"), _ = !0, u.remoteParticipants.size === 0) {
639
632
  if (n("Waiting for agent to join..."), !await new Promise((D) => {
640
- const q = setTimeout(() => {
641
- u == null || u.off(o.ParticipantConnected, x), D(!1);
642
- }, 5e3), x = () => {
643
- clearTimeout(q), u == null || u.off(o.ParticipantConnected, x), D(!0);
633
+ const b = setTimeout(() => {
634
+ u == null || u.off(o.ParticipantConnected, Q), D(!1);
635
+ }, 5e3), Q = () => {
636
+ clearTimeout(b), u == null || u.off(o.ParticipantConnected, Q), D(!0);
644
637
  };
645
- u == null || u.on(o.ParticipantConnected, x);
638
+ u == null || u.on(o.ParticipantConnected, Q);
646
639
  }))
647
640
  throw n("Agent did not join within timeout"), await u.disconnect(), new Error("Agent did not rejoin the room");
648
641
  n("Agent joined");
649
642
  }
650
- (h = i.onConnectionStateChange) == null || h.call(i, S.Connected);
651
- } catch (R) {
652
- throw n("Failed to reconnect:", R), (v = i.onConnectionStateChange) == null || v.call(i, S.Fail), R;
643
+ } catch (v) {
644
+ throw n("Failed to reconnect:", v), (g = a.onConnectionStateChange) == null || g.call(a, R.Fail), v;
653
645
  }
654
646
  },
655
647
  sendDataChannelMessage: he,
656
648
  sendTextMessage: pe,
657
649
  publishMicrophoneStream: m,
658
- unpublishMicrophoneStream: p,
659
- sessionId: T,
660
- streamId: T,
650
+ unpublishMicrophoneStream: h,
651
+ sessionId: M,
652
+ streamId: M,
661
653
  streamType: $,
662
654
  interruptAvailable: !0,
663
655
  triggersAvailable: !1
@@ -669,23 +661,23 @@ const _t = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
669
661
  createLiveKitStreamingManager: Tt,
670
662
  handleInitError: De
671
663
  }, Symbol.toStringTag, { value: "Module" }));
672
- function At(e, t, a) {
664
+ function At(e, t, i) {
673
665
  if (!e)
674
666
  throw new Error("Please connect to the agent first");
675
667
  if (!e.interruptAvailable)
676
668
  throw new Error("Interrupt is not enabled for this stream");
677
669
  if (t !== ae.Fluent)
678
670
  throw new Error("Interrupt only available for Fluent streams");
679
- if (!a)
671
+ if (!i)
680
672
  throw new Error("No active video to interrupt");
681
673
  }
682
674
  async function Pt(e, t) {
683
- const a = {
675
+ const i = {
684
676
  type: j.StreamInterrupt,
685
677
  videoId: t,
686
678
  timestamp: Date.now()
687
679
  };
688
- e.sendDataChannelMessage(JSON.stringify(a));
680
+ e.sendDataChannelMessage(JSON.stringify(i));
689
681
  }
690
682
  async function Lt(e) {
691
683
  const t = {
@@ -694,160 +686,164 @@ async function Lt(e) {
694
686
  e.sendDataChannelMessage(JSON.stringify(t));
695
687
  }
696
688
  function bt(e) {
697
- return new Promise((t, a) => {
698
- const { callbacks: n, host: c, auth: o, externalId: s } = e, { onMessage: i = null, onOpen: r = null, onClose: d = null, onError: g = null } = n || {}, w = new WebSocket(`${c}?authorization=${encodeURIComponent(Oe(o, s))}`);
699
- w.onmessage = i, w.onclose = d, w.onerror = (u) => {
700
- console.error(u), g == null || g("Websocket failed to connect", u), a(u);
701
- }, w.onopen = (u) => {
702
- r == null || r(u), t(w);
689
+ return new Promise((t, i) => {
690
+ const { callbacks: n, host: s, auth: o, externalId: c } = e, { onMessage: a = null, onOpen: r = null, onClose: d = null, onError: w = null } = n || {}, p = new WebSocket(`${s}?authorization=${encodeURIComponent(We(o, c))}`);
691
+ p.onmessage = a, p.onclose = d, p.onerror = (u) => {
692
+ console.error(u), w == null || w("Websocket failed to connect", u), i(u);
693
+ }, p.onopen = (u) => {
694
+ r == null || r(u), t(p);
703
695
  };
704
696
  });
705
697
  }
706
698
  async function jt(e) {
707
699
  const { retries: t = 1 } = e;
708
- let a = null;
709
- for (let n = 0; (a == null ? void 0 : a.readyState) !== WebSocket.OPEN; n++)
700
+ let i = null;
701
+ for (let n = 0; (i == null ? void 0 : i.readyState) !== WebSocket.OPEN; n++)
710
702
  try {
711
- a = await bt(e);
712
- } catch (c) {
703
+ i = await bt(e);
704
+ } catch (s) {
713
705
  if (n === t)
714
- throw c;
706
+ throw s;
715
707
  await Je(n * 500);
716
708
  }
717
- return a;
709
+ return i;
718
710
  }
719
- async function $t(e, t, a, n) {
720
- const c = a != null && a.onMessage ? [a.onMessage] : [], o = await jt({
711
+ async function $t(e, t, i, n) {
712
+ const s = i != null && i.onMessage ? [i.onMessage] : [], o = await jt({
721
713
  auth: e,
722
714
  host: t,
723
715
  externalId: n,
724
716
  callbacks: {
725
- onError: (s) => {
726
- var i;
727
- return (i = a.onError) == null ? void 0 : i.call(a, new Ze(s));
717
+ onError: (c) => {
718
+ var a;
719
+ return (a = i.onError) == null ? void 0 : a.call(i, new Ze(c));
728
720
  },
729
- onMessage(s) {
730
- const i = JSON.parse(s.data);
731
- c.forEach((r) => r(i.event, i));
721
+ onMessage(c) {
722
+ const a = JSON.parse(c.data);
723
+ s.forEach((r) => r(a.event, a));
732
724
  }
733
725
  }
734
726
  });
735
727
  return {
736
728
  socket: o,
737
729
  disconnect: () => o.close(),
738
- subscribeToEvents: (s) => c.push(s)
730
+ subscribeToEvents: (c) => s.push(c)
739
731
  };
740
732
  }
741
- function xt(e) {
733
+ function Bt(e) {
742
734
  if (e.answer !== void 0)
743
735
  return e.answer;
744
- let t = 0, a = "";
736
+ let t = 0, i = "";
745
737
  for (; t in e; )
746
- a += e[t++];
747
- return a;
738
+ i += e[t++];
739
+ return i;
748
740
  }
749
- function Bt(e, t, a) {
741
+ function xt(e, t, i) {
750
742
  if (!e.content)
751
743
  return;
752
744
  const n = t.messages[t.messages.length - 1];
753
745
  (n == null ? void 0 : n.role) === "assistant" && !n.interrupted && (n.interrupted = !0);
754
- const c = {
746
+ const s = {
755
747
  id: e.id || `user-${Date.now()}`,
756
748
  role: e.role,
757
749
  content: e.content,
758
750
  created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
759
751
  transcribed: !0
760
752
  };
761
- t.messages.push(c), a == null || a([...t.messages], "user");
753
+ t.messages.push(s), i == null || i([...t.messages], "user");
762
754
  }
763
- function Ft(e, t, a, n, c) {
764
- if (e === Y.Transcribe && t.content) {
765
- Bt(t, n, c);
755
+ function Ft(e, t, i, n, s) {
756
+ if (e === X.Transcribe && t.content) {
757
+ xt(t, n, s);
766
758
  return;
767
759
  }
768
- if (!(e === Y.Partial || e === Y.Answer))
760
+ if (!(e === X.Partial || e === X.Answer))
769
761
  return;
770
762
  const o = n.messages[n.messages.length - 1];
771
- let s;
763
+ let c;
772
764
  if (o != null && o.transcribed && o.role === "user")
773
- e === Y.Answer && t.content, s = {
765
+ e === X.Answer && t.content, c = {
774
766
  id: t.id || `assistant-${Date.now()}`,
775
767
  role: t.role || "assistant",
776
768
  content: t.content || "",
777
769
  created_at: t.created_at || (/* @__PURE__ */ new Date()).toISOString()
778
- }, n.messages.push(s);
770
+ }, n.messages.push(c);
779
771
  else if ((o == null ? void 0 : o.role) === "assistant")
780
- s = o;
772
+ c = o;
781
773
  else
782
774
  return;
783
- const { content: i, sequence: r } = t;
784
- e === Y.Partial ? a[r] = i : a.answer = i;
785
- const d = xt(a);
786
- (s.content !== d || e === Y.Answer) && (s.content = d, c == null || c([...n.messages], e));
775
+ const { content: a, sequence: r } = t;
776
+ e === X.Partial ? i[r] = a : i.answer = a;
777
+ const d = Bt(i);
778
+ (c.content !== d || e === X.Answer) && (c.content = d, s == null || s([...n.messages], e));
787
779
  }
788
- function zt(e, t, a, n, c) {
780
+ function zt(e, t, i, n, s) {
789
781
  let o = {};
782
+ const c = () => o = {}, a = (r, d) => {
783
+ var w, p;
784
+ d === "user" && c(), (p = (w = i.callbacks).onNewMessage) == null || p.call(w, r, d);
785
+ };
790
786
  return {
791
- clearQueue: () => o = {},
792
- onMessage: (s, i) => {
793
- var r, d;
794
- if ("content" in i) {
795
- const g = s === j.ChatAnswer ? Y.Answer : s === j.ChatAudioTranscribed ? Y.Transcribe : s;
796
- Ft(g, i, o, t, a.callbacks.onNewMessage), g === Y.Answer && e.track("agent-message-received", {
787
+ clearQueue: c,
788
+ onMessage: (r, d) => {
789
+ var w, p;
790
+ if ("content" in d) {
791
+ const u = r === j.ChatAnswer ? X.Answer : r === j.ChatAudioTranscribed ? X.Transcribe : r;
792
+ Ft(u, d, o, t, a), u === X.Answer && e.track("agent-message-received", {
797
793
  messages: t.messages.length,
798
794
  mode: t.chatMode
799
795
  });
800
796
  } else {
801
- const g = j, w = [g.StreamVideoDone, g.StreamVideoError, g.StreamVideoRejected], u = [g.StreamFailed, g.StreamVideoError, g.StreamVideoRejected], M = Ct(i, n, { mode: t.chatMode });
802
- if (s = s, s === g.StreamVideoCreated)
803
- e.linkTrack("agent-video", M, g.StreamVideoCreated, ["start"]);
804
- else if (w.includes(s)) {
805
- const $ = s.split("/")[1];
806
- u.includes(s) ? e.track("agent-video", { ...M, event: $ }) : e.linkTrack("agent-video", { ...M, event: $ }, s, ["done"]);
797
+ const u = j, _ = [u.StreamVideoDone, u.StreamVideoError, u.StreamVideoRejected], $ = [u.StreamFailed, u.StreamVideoError, u.StreamVideoRejected], A = St(d, n, { mode: t.chatMode });
798
+ if (r = r, r === u.StreamVideoCreated)
799
+ e.linkTrack("agent-video", A, u.StreamVideoCreated, ["start"]);
800
+ else if (_.includes(r)) {
801
+ const C = r.split("/")[1];
802
+ $.includes(r) ? e.track("agent-video", { ...A, event: C }) : e.linkTrack("agent-video", { ...A, event: C }, r, ["done"]);
807
803
  }
808
- u.includes(s) && ((d = (r = a.callbacks).onError) == null || d.call(r, new Error(`Stream failed with event ${s}`), { data: i })), i.event === g.StreamDone && c();
804
+ $.includes(r) && ((p = (w = i.callbacks).onError) == null || p.call(w, new Error(`Stream failed with event ${r}`), { data: d })), d.event === u.StreamDone && s();
809
805
  }
810
806
  }
811
807
  };
812
808
  }
813
- function Nt(e, t, a, n) {
814
- const c = Te(e, `${t}/agents/${a}`, n);
809
+ function Nt(e, t, i, n) {
810
+ const s = Te(e, `${t}/agents/${i}`, n);
815
811
  return {
816
- createStream(o, s) {
817
- return c.post("/streams", o, { signal: s });
812
+ createStream(o, c) {
813
+ return s.post("/streams", o, { signal: c });
818
814
  },
819
- startConnection(o, s, i, r) {
820
- return c.post(
815
+ startConnection(o, c, a, r) {
816
+ return s.post(
821
817
  `/streams/${o}/sdp`,
822
818
  {
823
- session_id: i,
824
- answer: s
819
+ session_id: a,
820
+ answer: c
825
821
  },
826
822
  { signal: r }
827
823
  );
828
824
  },
829
- addIceCandidate(o, s, i, r) {
830
- return c.post(
825
+ addIceCandidate(o, c, a, r) {
826
+ return s.post(
831
827
  `/streams/${o}/ice`,
832
828
  {
833
- session_id: i,
834
- ...s
829
+ session_id: a,
830
+ ...c
835
831
  },
836
832
  { signal: r }
837
833
  );
838
834
  },
839
- sendStreamRequest(o, s, i) {
840
- return c.post(`/streams/${o}`, {
841
- session_id: s,
842
- ...i
835
+ sendStreamRequest(o, c, a) {
836
+ return s.post(`/streams/${o}`, {
837
+ session_id: c,
838
+ ...a
843
839
  });
844
840
  },
845
- close(o, s) {
846
- return c.delete(`/streams/${o}`, { session_id: s });
841
+ close(o, c) {
842
+ return s.delete(`/streams/${o}`, { session_id: c });
847
843
  }
848
844
  };
849
845
  }
850
- function Kt(e, t, a) {
846
+ function Kt(e, t, i) {
851
847
  const n = (t.timestamp - e.timestamp) / 1e3;
852
848
  return {
853
849
  duration: n,
@@ -864,31 +860,31 @@ function Kt(e, t, a) {
864
860
  framesPerSecond: t.framesPerSecond,
865
861
  freezeCount: t.freezeCount - e.freezeCount,
866
862
  freezeDuration: t.freezeDuration - e.freezeDuration,
867
- lowFpsCount: a
863
+ lowFpsCount: i
868
864
  };
869
865
  }
870
866
  function Jt(e) {
871
867
  return e.filter(
872
868
  (t) => t.freezeCount > 0 || t.framesPerSecond < 21 || t.framesDropped > 0 || t.packetsLost > 0
873
869
  ).map((t) => {
874
- const { timestamp: a, ...n } = t, c = [];
875
- return t.freezeCount > 0 && c.push("freeze"), t.framesPerSecond < 21 && c.push("low fps"), t.framesDropped > 0 && c.push("frames dropped"), t.packetsLost > 0 && c.push("packet loss"), {
870
+ const { timestamp: i, ...n } = t, s = [];
871
+ return t.freezeCount > 0 && s.push("freeze"), t.framesPerSecond < 21 && s.push("low fps"), t.framesDropped > 0 && s.push("frames dropped"), t.packetsLost > 0 && s.push("packet loss"), {
876
872
  ...n,
877
- causes: c
873
+ causes: s
878
874
  };
879
875
  });
880
876
  }
881
877
  function Ut(e) {
882
- let t = "", a = 0;
878
+ let t = "", i = 0;
883
879
  for (const n of e.values()) {
884
880
  if (n && n.type === "codec" && n.mimeType.startsWith("video") && (t = n.mimeType.split("/")[1]), n && n.type === "candidate-pair") {
885
- const c = n.currentRoundTripTime, s = n.nominated === !0;
886
- c > 0 && (s || a === 0) && (a = c);
881
+ const s = n.currentRoundTripTime, c = n.nominated === !0;
882
+ s > 0 && (c || i === 0) && (i = s);
887
883
  }
888
884
  if (n && n.type === "inbound-rtp" && n.kind === "video")
889
885
  return {
890
886
  codec: t,
891
- rtt: a,
887
+ rtt: i,
892
888
  timestamp: n.timestamp,
893
889
  bytesReceived: n.bytesReceived,
894
890
  packetsReceived: n.packetsReceived,
@@ -908,24 +904,24 @@ function Ut(e) {
908
904
  }
909
905
  return {};
910
906
  }
911
- function Wt(e, t, a) {
912
- const n = e.map((r, d) => d === 0 ? a ? {
907
+ function Vt(e, t, i) {
908
+ const n = e.map((r, d) => d === 0 ? i ? {
913
909
  timestamp: r.timestamp,
914
910
  duration: 0,
915
911
  rtt: r.rtt,
916
- bytesReceived: r.bytesReceived - a.bytesReceived,
917
- bitrate: (r.bytesReceived - a.bytesReceived) * 8 / (t / 1e3),
918
- packetsReceived: r.packetsReceived - a.packetsReceived,
919
- packetsLost: r.packetsLost - a.packetsLost,
920
- framesDropped: r.framesDropped - a.framesDropped,
921
- framesDecoded: r.framesDecoded - a.framesDecoded,
912
+ bytesReceived: r.bytesReceived - i.bytesReceived,
913
+ bitrate: (r.bytesReceived - i.bytesReceived) * 8 / (t / 1e3),
914
+ packetsReceived: r.packetsReceived - i.packetsReceived,
915
+ packetsLost: r.packetsLost - i.packetsLost,
916
+ framesDropped: r.framesDropped - i.framesDropped,
917
+ framesDecoded: r.framesDecoded - i.framesDecoded,
922
918
  jitter: r.jitter,
923
- jitterBufferDelay: r.jitterBufferDelay - a.jitterBufferDelay,
924
- jitterBufferEmittedCount: r.jitterBufferEmittedCount - a.jitterBufferEmittedCount,
925
- avgJitterDelayInInterval: (r.jitterBufferDelay - a.jitterBufferDelay) / (r.jitterBufferEmittedCount - a.jitterBufferEmittedCount),
919
+ jitterBufferDelay: r.jitterBufferDelay - i.jitterBufferDelay,
920
+ jitterBufferEmittedCount: r.jitterBufferEmittedCount - i.jitterBufferEmittedCount,
921
+ avgJitterDelayInInterval: (r.jitterBufferDelay - i.jitterBufferDelay) / (r.jitterBufferEmittedCount - i.jitterBufferEmittedCount),
926
922
  framesPerSecond: r.framesPerSecond,
927
- freezeCount: r.freezeCount - a.freezeCount,
928
- freezeDuration: r.freezeDuration - a.freezeDuration
923
+ freezeCount: r.freezeCount - i.freezeCount,
924
+ freezeDuration: r.freezeDuration - i.freezeDuration
929
925
  } : {
930
926
  timestamp: r.timestamp,
931
927
  rtt: r.rtt,
@@ -960,50 +956,50 @@ function Wt(e, t, a) {
960
956
  framesPerSecond: r.framesPerSecond,
961
957
  freezeCount: r.freezeCount - e[d - 1].freezeCount,
962
958
  freezeDuration: r.freezeDuration - e[d - 1].freezeDuration
963
- }), c = Jt(n), o = c.reduce((r, d) => r + (d.causes.includes("low fps") ? 1 : 0), 0), s = n.filter((r) => !!r.avgJitterDelayInInterval).map((r) => r.avgJitterDelayInInterval), i = n.filter((r) => !!r.rtt).map((r) => r.rtt);
959
+ }), s = Jt(n), o = s.reduce((r, d) => r + (d.causes.includes("low fps") ? 1 : 0), 0), c = n.filter((r) => !!r.avgJitterDelayInInterval).map((r) => r.avgJitterDelayInInterval), a = n.filter((r) => !!r.rtt).map((r) => r.rtt);
964
960
  return {
965
961
  webRTCStats: {
966
- anomalies: c,
967
- minRtt: Math.min(...i),
968
- avgRtt: $e(i),
969
- maxRtt: Math.max(...i),
962
+ anomalies: s,
963
+ minRtt: Math.min(...a),
964
+ avgRtt: $e(a),
965
+ maxRtt: Math.max(...a),
970
966
  aggregateReport: Kt(e[0], e[e.length - 1], o),
971
- minJitterDelayInInterval: Math.min(...s),
972
- maxJitterDelayInInterval: Math.max(...s),
973
- avgJitterDelayInInterval: $e(s)
967
+ minJitterDelayInInterval: Math.min(...c),
968
+ maxJitterDelayInInterval: Math.max(...c),
969
+ avgJitterDelayInInterval: $e(c)
974
970
  },
975
971
  codec: e[0].codec,
976
972
  resolution: `${e[0].frameWidth}x${e[0].frameHeight}`
977
973
  };
978
974
  }
979
- const Me = 100, Ot = Math.max(Math.ceil(400 / Me), 1), Vt = 0.25, qt = 0.28;
980
- function Ht() {
981
- let e = 0, t, a, n = 0;
982
- return (c) => {
983
- for (const o of c.values())
975
+ const Me = 100, Wt = Math.max(Math.ceil(400 / Me), 1), Ot = 0.25, Ht = 0.28;
976
+ function qt() {
977
+ let e = 0, t, i, n = 0;
978
+ return (s) => {
979
+ for (const o of s.values())
984
980
  if (o && o.type === "inbound-rtp" && o.kind === "video") {
985
- const s = o.jitterBufferDelay, i = o.jitterBufferEmittedCount;
986
- if (a && i > a) {
987
- const g = s - t, w = i - a;
988
- n = g / w;
981
+ const c = o.jitterBufferDelay, a = o.jitterBufferEmittedCount;
982
+ if (i && a > i) {
983
+ const w = c - t, p = a - i;
984
+ n = w / p;
989
985
  }
990
- t = s, a = i;
986
+ t = c, i = a;
991
987
  const r = o.framesDecoded, d = r - e > 0;
992
988
  return e = r, { isReceiving: d, avgJitterDelayInInterval: n, freezeCount: o.freezeCount };
993
989
  }
994
990
  return { isReceiving: !1, avgJitterDelayInInterval: n };
995
991
  };
996
992
  }
997
- function Qt(e, t, a, n, c) {
998
- let o = [], s, i = 0, r = !1, d = re.Unknown, g = re.Unknown, w = 0, u = 0;
999
- const M = Ht();
993
+ function Qt(e, t, i, n, s) {
994
+ let o = [], c, a = 0, r = !1, d = ie.Unknown, w = ie.Unknown, p = 0, u = 0;
995
+ const _ = qt();
1000
996
  return setInterval(async () => {
1001
- const $ = await e.getStats(), { isReceiving: V, avgJitterDelayInInterval: E, freezeCount: I } = M($), z = Ut($);
1002
- if (V)
1003
- i = 0, w = I - u, g = E < Vt ? re.Strong : E > qt && w > 1 ? re.Weak : d, g !== d && (c == null || c(g), d = g, u += w, w = 0), r || (n == null || n(C.Start), s = o[o.length - 1], o = [], r = !0), o.push(z);
1004
- else if (r && (i++, i >= Ot)) {
1005
- const A = Wt(o, Me, s);
1006
- n == null || n(C.Stop, A), t() || a(), u = I, r = !1;
997
+ const $ = await e.getStats(), { isReceiving: A, avgJitterDelayInInterval: C, freezeCount: B } = _($), z = Ut($);
998
+ if (A)
999
+ a = 0, p = B - u, w = C < Ot ? ie.Strong : C > Ht && p > 1 ? ie.Weak : d, w !== d && (s == null || s(w), d = w, u += p, p = 0), r || (n == null || n(S.Start), c = o[o.length - 1], o = [], r = !0), o.push(z);
1000
+ else if (r && (a++, a >= Wt)) {
1001
+ const I = Vt(o, Me, c);
1002
+ n == null || n(S.Stop, I), t() || i(), u = B, r = !1;
1007
1003
  }
1008
1004
  }, Me);
1009
1005
  }
@@ -1011,249 +1007,255 @@ const Xt = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window
1011
1007
  function Fe(e) {
1012
1008
  switch (e) {
1013
1009
  case "connected":
1014
- return S.Connected;
1010
+ return R.Connected;
1015
1011
  case "checking":
1016
- return S.Connecting;
1012
+ return R.Connecting;
1017
1013
  case "failed":
1018
- return S.Fail;
1014
+ return R.Fail;
1019
1015
  case "new":
1020
- return S.New;
1016
+ return R.New;
1021
1017
  case "closed":
1022
- return S.Closed;
1018
+ return R.Closed;
1023
1019
  case "disconnected":
1024
- return S.Disconnected;
1020
+ return R.Disconnected;
1025
1021
  case "completed":
1026
- return S.Completed;
1022
+ return R.Completed;
1027
1023
  default:
1028
- return S.New;
1024
+ return R.New;
1029
1025
  }
1030
1026
  }
1031
1027
  const Yt = (e) => (t) => {
1032
- const [a, n = ""] = t.split(/:(.+)/);
1028
+ const [i, n = ""] = t.split(/:(.+)/);
1033
1029
  try {
1034
- const c = JSON.parse(n);
1035
- return e("parsed data channel message", { subject: a, data: c }), { subject: a, data: c };
1036
- } catch (c) {
1037
- return e("Failed to parse data channel message, returning data as string", { subject: a, rawData: n, error: c }), { subject: a, data: n };
1030
+ const s = JSON.parse(n);
1031
+ return e("parsed data channel message", { subject: i, data: s }), { subject: i, data: s };
1032
+ } catch (s) {
1033
+ return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: n, error: s }), { subject: i, data: n };
1038
1034
  }
1039
1035
  };
1040
1036
  function Gt({
1041
1037
  statsSignal: e,
1042
1038
  dataChannelSignal: t,
1043
- onVideoStateChange: a,
1044
- report: n
1039
+ onVideoStateChange: i,
1040
+ report: n,
1041
+ log: s
1045
1042
  }) {
1046
- e === C.Start && t === C.Start ? a == null || a(C.Start) : e === C.Stop && t === C.Stop && (a == null || a(C.Stop, n));
1043
+ e === S.Start && t === S.Start ? (s("CALLBACK: onVideoStateChange(Start)"), i == null || i(S.Start)) : e === S.Stop && t === S.Stop && (s("CALLBACK: onVideoStateChange(Stop)"), i == null || i(S.Stop, n));
1047
1044
  }
1048
1045
  function Zt({
1049
1046
  statsSignal: e,
1050
1047
  dataChannelSignal: t,
1051
- onVideoStateChange: a,
1048
+ onVideoStateChange: i,
1052
1049
  onAgentActivityStateChange: n,
1053
- report: c
1050
+ report: s,
1051
+ log: o
1054
1052
  }) {
1055
- e === C.Start ? a == null || a(C.Start) : e === C.Stop && (a == null || a(C.Stop, c)), t === C.Start ? n == null || n(U.Talking) : t === C.Stop && (n == null || n(U.Idle));
1053
+ e === S.Start ? (o("CALLBACK: onVideoStateChange(Start)"), i == null || i(S.Start)) : e === S.Stop && (o("CALLBACK: onVideoStateChange(Stop)"), i == null || i(S.Stop, s)), t === S.Start ? n == null || n(W.Talking) : t === S.Stop && (n == null || n(W.Idle));
1056
1054
  }
1057
1055
  function ze({
1058
1056
  statsSignal: e,
1059
1057
  dataChannelSignal: t,
1060
- onVideoStateChange: a,
1058
+ onVideoStateChange: i,
1061
1059
  onAgentActivityStateChange: n,
1062
- streamType: c,
1063
- report: o
1060
+ streamType: s,
1061
+ report: o,
1062
+ log: c
1064
1063
  }) {
1065
- c === ae.Legacy ? Gt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: a, report: o }) : c === ae.Fluent && Zt({
1064
+ s === ae.Legacy ? Gt({ statsSignal: e, dataChannelSignal: t, onVideoStateChange: i, report: o, log: c }) : s === ae.Fluent && Zt({
1066
1065
  statsSignal: e,
1067
1066
  dataChannelSignal: t,
1068
- onVideoStateChange: a,
1067
+ onVideoStateChange: i,
1069
1068
  onAgentActivityStateChange: n,
1070
- report: o
1069
+ report: o,
1070
+ log: c
1071
1071
  });
1072
1072
  }
1073
- async function en(e, t, { debug: a = !1, callbacks: n, auth: c, baseURL: o = ge, analytics: s }, i) {
1074
- var O;
1075
- const r = He(a, "WebRTCStreamingManager"), d = Yt(r);
1076
- let g = !1, w = !1, u = C.Stop, M = C.Stop;
1077
- const { startConnection: $, sendStreamRequest: V, close: E, createStream: I, addIceCandidate: z } = Nt(
1078
- c,
1073
+ async function en(e, t, { debug: i = !1, callbacks: n, auth: s, baseURL: o = ge, analytics: c }, a) {
1074
+ var V;
1075
+ const r = qe(i, "WebRTCStreamingManager"), d = Yt(r);
1076
+ let w = !1, p = !1, u = S.Stop, _ = S.Stop;
1077
+ const { startConnection: $, sendStreamRequest: A, close: C, createStream: B, addIceCandidate: z } = Nt(
1078
+ s,
1079
1079
  o,
1080
1080
  e,
1081
1081
  n.onError
1082
1082
  ), {
1083
- id: A,
1084
- offer: W,
1085
- ice_servers: ee,
1086
- session_id: T,
1087
- fluent: G,
1083
+ id: I,
1084
+ offer: U,
1085
+ ice_servers: te,
1086
+ session_id: M,
1087
+ fluent: Y,
1088
1088
  interrupt_enabled: Z,
1089
1089
  triggers_enabled: f
1090
- } = await I(t, i);
1091
- (O = n.onStreamCreated) == null || O.call(n, { stream_id: A, session_id: T, agent_id: e });
1092
- const y = new Xt({ iceServers: ee }), k = y.createDataChannel("JanusDataChannel");
1093
- if (!T)
1090
+ } = await B(t, a);
1091
+ (V = n.onStreamCreated) == null || V.call(n, { stream_id: I, session_id: M, agent_id: e });
1092
+ const y = new Xt({ iceServers: te }), k = y.createDataChannel("JanusDataChannel");
1093
+ if (!M)
1094
1094
  throw new Error("Could not create session_id");
1095
- const P = G ? ae.Fluent : ae.Legacy;
1096
- s.enrich({
1097
- "stream-type": P
1095
+ const T = Y ? ae.Fluent : ae.Legacy;
1096
+ c.enrich({
1097
+ "stream-type": T
1098
1098
  });
1099
- const L = t.stream_warmup && !G, _ = () => g, J = () => {
1099
+ const P = t.stream_warmup && !Y, E = () => w, J = () => {
1100
1100
  var m;
1101
- g = !0, w && ((m = n.onConnectionStateChange) == null || m.call(n, S.Connected));
1102
- }, H = Qt(
1101
+ w = !0, p && (r("CALLBACK: onConnectionStateChange(Connected)"), (m = n.onConnectionStateChange) == null || m.call(n, R.Connected));
1102
+ }, O = Qt(
1103
1103
  y,
1104
- _,
1104
+ E,
1105
1105
  J,
1106
- (m, p) => ze({
1107
- statsSignal: M = m,
1108
- dataChannelSignal: P === ae.Legacy ? u : void 0,
1106
+ (m, h) => ze({
1107
+ statsSignal: _ = m,
1108
+ dataChannelSignal: T === ae.Legacy ? u : void 0,
1109
1109
  onVideoStateChange: n.onVideoStateChange,
1110
1110
  onAgentActivityStateChange: n.onAgentActivityStateChange,
1111
- report: p,
1112
- streamType: P
1111
+ report: h,
1112
+ streamType: T,
1113
+ log: r
1113
1114
  }),
1114
1115
  (m) => {
1115
- var p;
1116
- return (p = n.onConnectivityStateChange) == null ? void 0 : p.call(n, m);
1116
+ var h;
1117
+ return (h = n.onConnectivityStateChange) == null ? void 0 : h.call(n, m);
1117
1118
  }
1118
1119
  );
1119
1120
  y.onicecandidate = (m) => {
1120
- var p;
1121
+ var h;
1121
1122
  r("peerConnection.onicecandidate", m);
1122
1123
  try {
1123
1124
  m.candidate && m.candidate.sdpMid && m.candidate.sdpMLineIndex !== null ? z(
1124
- A,
1125
+ I,
1125
1126
  {
1126
1127
  candidate: m.candidate.candidate,
1127
1128
  sdpMid: m.candidate.sdpMid,
1128
1129
  sdpMLineIndex: m.candidate.sdpMLineIndex
1129
1130
  },
1130
- T,
1131
- i
1132
- ) : z(A, { candidate: null }, T, i);
1133
- } catch (B) {
1134
- (p = n.onError) == null || p.call(n, B, { streamId: A });
1131
+ M,
1132
+ a
1133
+ ) : z(I, { candidate: null }, M, a);
1134
+ } catch (x) {
1135
+ (h = n.onError) == null || h.call(n, x, { streamId: I });
1135
1136
  }
1136
1137
  }, k.onopen = () => {
1137
- w = !0, (!L || g) && J();
1138
+ p = !0, (!P || w) && J();
1138
1139
  };
1139
- const Q = (m) => {
1140
- var p;
1141
- (p = n.onVideoIdChange) == null || p.call(n, m);
1140
+ const H = (m) => {
1141
+ var h;
1142
+ (h = n.onVideoIdChange) == null || h.call(n, m);
1142
1143
  };
1143
- function b(m, p) {
1144
- if (m === j.StreamStarted && typeof p == "object" && "metadata" in p) {
1145
- const B = p.metadata;
1146
- Q(B.videoId);
1144
+ function L(m, h) {
1145
+ if (m === j.StreamStarted && typeof h == "object" && "metadata" in h) {
1146
+ const x = h.metadata;
1147
+ H(x.videoId);
1147
1148
  }
1148
- m === j.StreamDone && Q(null), u = m === j.StreamStarted ? C.Start : C.Stop, ze({
1149
- statsSignal: P === ae.Legacy ? M : void 0,
1149
+ m === j.StreamDone && H(null), u = m === j.StreamStarted ? S.Start : S.Stop, ze({
1150
+ statsSignal: T === ae.Legacy ? _ : void 0,
1150
1151
  dataChannelSignal: u,
1151
1152
  onVideoStateChange: n.onVideoStateChange,
1152
1153
  onAgentActivityStateChange: n.onAgentActivityStateChange,
1153
- streamType: P
1154
+ streamType: T,
1155
+ log: r
1154
1156
  });
1155
1157
  }
1156
- function N(m, p) {
1158
+ function N(m, h) {
1157
1159
  var K;
1158
- const B = typeof p == "string" ? p : p == null ? void 0 : p.metadata;
1159
- B && s.enrich({ streamMetadata: B }), (K = n.onStreamReady) == null || K.call(n);
1160
+ const x = typeof h == "string" ? h : h == null ? void 0 : h.metadata;
1161
+ x && c.enrich({ streamMetadata: x }), (K = n.onStreamReady) == null || K.call(n);
1160
1162
  }
1161
- const X = {
1162
- [j.StreamStarted]: b,
1163
- [j.StreamDone]: b,
1163
+ const q = {
1164
+ [j.StreamStarted]: L,
1165
+ [j.StreamDone]: L,
1164
1166
  [j.StreamReady]: N
1165
1167
  };
1166
1168
  k.onmessage = (m) => {
1167
1169
  var K;
1168
- const { subject: p, data: B } = d(m.data);
1169
- (K = X[p]) == null || K.call(X, p, B);
1170
+ const { subject: h, data: x } = d(m.data);
1171
+ (K = q[h]) == null || K.call(q, h, x);
1170
1172
  }, y.oniceconnectionstatechange = () => {
1171
- var p;
1173
+ var h;
1172
1174
  r("peerConnection.oniceconnectionstatechange => " + y.iceConnectionState);
1173
1175
  const m = Fe(y.iceConnectionState);
1174
- m !== S.Connected && ((p = n.onConnectionStateChange) == null || p.call(n, m));
1176
+ m !== R.Connected && ((h = n.onConnectionStateChange) == null || h.call(n, m));
1175
1177
  }, y.ontrack = (m) => {
1176
- var p;
1177
- r("peerConnection.ontrack", m), (p = n.onSrcObjectReady) == null || p.call(n, m.streams[0]);
1178
- }, await y.setRemoteDescription(W), r("set remote description OK");
1178
+ var h;
1179
+ r("peerConnection.ontrack", m), r("CALLBACK: onSrcObjectReady"), (h = n.onSrcObjectReady) == null || h.call(n, m.streams[0]);
1180
+ }, await y.setRemoteDescription(U), r("set remote description OK");
1179
1181
  const oe = await y.createAnswer();
1180
- return r("create answer OK"), await y.setLocalDescription(oe), r("set local description OK"), await $(A, oe, T, i), r("start connection OK"), {
1182
+ return r("create answer OK"), await y.setLocalDescription(oe), r("set local description OK"), await $(I, oe, M, a), r("start connection OK"), {
1181
1183
  /**
1182
1184
  * Method to send request to server to get clip or talk depend on you payload
1183
1185
  * @param payload
1184
1186
  */
1185
1187
  speak(m) {
1186
- return V(A, T, m);
1188
+ return A(I, M, m);
1187
1189
  },
1188
1190
  /**
1189
1191
  * Method to close RTC connection
1190
1192
  */
1191
1193
  async disconnect() {
1192
1194
  var m;
1193
- if (A) {
1194
- const p = Fe(y.iceConnectionState);
1195
+ if (I) {
1196
+ const h = Fe(y.iceConnectionState);
1195
1197
  if (y) {
1196
- if (p === S.New) {
1197
- clearInterval(H);
1198
+ if (h === R.New) {
1199
+ clearInterval(O);
1198
1200
  return;
1199
1201
  }
1200
1202
  y.close(), y.oniceconnectionstatechange = null, y.onnegotiationneeded = null, y.onicecandidate = null, y.ontrack = null;
1201
1203
  }
1202
1204
  try {
1203
- p === S.Connected && await E(A, T).catch((B) => {
1205
+ h === R.Connected && await C(I, M).catch((x) => {
1204
1206
  });
1205
- } catch (B) {
1206
- r("Error on close stream connection", B);
1207
+ } catch (x) {
1208
+ r("Error on close stream connection", x);
1207
1209
  }
1208
- (m = n.onAgentActivityStateChange) == null || m.call(n, U.Idle), clearInterval(H);
1210
+ (m = n.onAgentActivityStateChange) == null || m.call(n, W.Idle), clearInterval(O);
1209
1211
  }
1210
1212
  },
1211
1213
  /**
1212
1214
  * Method to send data channel messages to the server
1213
1215
  */
1214
1216
  sendDataChannelMessage(m) {
1215
- var p, B;
1216
- if (!g || k.readyState !== "open") {
1217
- r("Data channel is not ready for sending messages"), (p = n.onError) == null || p.call(n, new Error("Data channel is not ready for sending messages"), {
1218
- streamId: A
1217
+ var h, x;
1218
+ if (!w || k.readyState !== "open") {
1219
+ r("Data channel is not ready for sending messages"), (h = n.onError) == null || h.call(n, new Error("Data channel is not ready for sending messages"), {
1220
+ streamId: I
1219
1221
  });
1220
1222
  return;
1221
1223
  }
1222
1224
  try {
1223
1225
  k.send(m);
1224
1226
  } catch (K) {
1225
- r("Error sending data channel message", K), (B = n.onError) == null || B.call(n, K, { streamId: A });
1227
+ r("Error sending data channel message", K), (x = n.onError) == null || x.call(n, K, { streamId: I });
1226
1228
  }
1227
1229
  },
1228
1230
  /**
1229
1231
  * Session identifier information, should be returned in the body of all streaming requests
1230
1232
  */
1231
- sessionId: T,
1233
+ sessionId: M,
1232
1234
  /**
1233
1235
  * Id of current RTC stream
1234
1236
  */
1235
- streamId: A,
1236
- streamType: P,
1237
+ streamId: I,
1238
+ streamType: T,
1237
1239
  interruptAvailable: Z ?? !1,
1238
1240
  triggersAvailable: f ?? !1
1239
1241
  };
1240
1242
  }
1241
1243
  var Ee = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Ee || {});
1242
- async function tn(e, t, a, n) {
1243
- const c = e.id;
1244
+ async function tn(e, t, i, n) {
1245
+ const s = e.id;
1244
1246
  switch (t.version) {
1245
1247
  case "v1": {
1246
- const { version: o, ...s } = t;
1247
- return en(c, s, a, n);
1248
+ const { version: o, ...c } = t;
1249
+ return en(s, c, i, n);
1248
1250
  }
1249
1251
  case "v2": {
1250
- const { version: o, ...s } = t;
1251
- switch (s.transport_provider) {
1252
+ const { version: o, ...c } = t;
1253
+ switch (c.transport_provider) {
1252
1254
  case ye.Livekit:
1253
- const { createLiveKitStreamingManager: i } = await Promise.resolve().then(() => _t);
1254
- return i(c, s, a);
1255
+ const { createLiveKitStreamingManager: a } = await Promise.resolve().then(() => _t);
1256
+ return a(s, c, i);
1255
1257
  default:
1256
- throw new Error(`Unsupported transport provider: ${s.transport_provider}`);
1258
+ throw new Error(`Unsupported transport provider: ${c.transport_provider}`);
1257
1259
  }
1258
1260
  }
1259
1261
  default:
@@ -1267,8 +1269,8 @@ function rn() {
1267
1269
  };
1268
1270
  }
1269
1271
  function an(e) {
1270
- var c, o;
1271
- const { streamOptions: t } = e ?? {}, a = ((c = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : c.plan) !== void 0 ? {
1272
+ var s, o;
1273
+ const { streamOptions: t } = e ?? {}, i = ((s = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : s.plan) !== void 0 ? {
1272
1274
  plan: (o = e.mixpanelAdditionalProperties) == null ? void 0 : o.plan
1273
1275
  } : void 0;
1274
1276
  return { ...{
@@ -1277,30 +1279,30 @@ function an(e) {
1277
1279
  stream_warmup: t == null ? void 0 : t.streamWarmup,
1278
1280
  compatibility_mode: t == null ? void 0 : t.compatibilityMode,
1279
1281
  fluent: t == null ? void 0 : t.fluent
1280
- }, ...a && { end_user_data: a } };
1282
+ }, ...i && { end_user_data: i } };
1281
1283
  }
1282
1284
  function on(e, t) {
1283
1285
  return Ie(e.presenter.type) ? { version: Ee.V2, ...rn() } : { version: Ee.V1, ...an(t) };
1284
1286
  }
1285
- function sn(e, t, a, n, c) {
1286
- c === ae.Fluent ? cn(e, t, a, n, c) : un(e, t, a, n, c);
1287
+ function sn(e, t, i, n, s) {
1288
+ s === ae.Fluent ? cn(e, t, i, n, s) : un(e, t, i, n, s);
1287
1289
  }
1288
- function cn(e, t, a, n, c) {
1289
- e === C.Start ? n.track("stream-session", { event: "start", "stream-type": c }) : e === C.Stop && n.track("stream-session", {
1290
+ function cn(e, t, i, n, s) {
1291
+ e === S.Start ? n.track("stream-session", { event: "start", "stream-type": s }) : e === S.Stop && n.track("stream-session", {
1290
1292
  event: "stop",
1291
1293
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1292
1294
  background: t.presenter.type === "clip" && t.presenter.background,
1293
- "stream-type": c,
1294
- ...a
1295
+ "stream-type": s,
1296
+ ...i
1295
1297
  });
1296
1298
  }
1297
- function dn(e, t, a, n) {
1298
- ie.get() <= 0 || (e === C.Start ? a.linkTrack(
1299
+ function dn(e, t, i, n) {
1300
+ ee.get() <= 0 || (e === S.Start ? i.linkTrack(
1299
1301
  "agent-video",
1300
- { event: "start", latency: ie.get(!0), "stream-type": n },
1302
+ { event: "start", latency: ee.get(!0), "stream-type": n },
1301
1303
  "start",
1302
1304
  [j.StreamVideoCreated]
1303
- ) : e === C.Stop && a.linkTrack(
1305
+ ) : e === S.Stop && i.linkTrack(
1304
1306
  "agent-video",
1305
1307
  {
1306
1308
  event: "stop",
@@ -1312,135 +1314,135 @@ function dn(e, t, a, n) {
1312
1314
  [j.StreamVideoDone]
1313
1315
  ));
1314
1316
  }
1315
- function un(e, t, a, n, c) {
1316
- ie.get() <= 0 || (e === C.Start ? n.linkTrack(
1317
+ function un(e, t, i, n, s) {
1318
+ ee.get() <= 0 || (e === S.Start ? n.linkTrack(
1317
1319
  "agent-video",
1318
- { event: "start", latency: ie.get(!0), "stream-type": c },
1320
+ { event: "start", latency: ee.get(!0), "stream-type": s },
1319
1321
  "start",
1320
1322
  [j.StreamVideoCreated]
1321
- ) : e === C.Stop && n.linkTrack(
1323
+ ) : e === S.Stop && n.linkTrack(
1322
1324
  "agent-video",
1323
1325
  {
1324
1326
  event: "stop",
1325
1327
  is_greenscreen: t.presenter.type === "clip" && t.presenter.is_greenscreen,
1326
1328
  background: t.presenter.type === "clip" && t.presenter.background,
1327
- "stream-type": c,
1328
- ...a
1329
+ "stream-type": s,
1330
+ ...i
1329
1331
  },
1330
1332
  "done",
1331
1333
  [j.StreamVideoDone]
1332
1334
  ));
1333
1335
  }
1334
- function Ne(e, t, a, n) {
1335
- return ie.reset(), Be.update(), new Promise(async (c, o) => {
1336
+ function Ne(e, t, i, n) {
1337
+ return ee.reset(), xe.update(), new Promise(async (s, o) => {
1336
1338
  try {
1337
- let s, i = !1;
1339
+ let c, a = !1;
1338
1340
  const r = on(e, t);
1339
- a.enrich({
1341
+ i.enrich({
1340
1342
  "stream-version": r.version.toString()
1341
- }), s = await tn(
1343
+ }), c = await tn(
1342
1344
  e,
1343
1345
  r,
1344
1346
  {
1345
1347
  ...t,
1346
- analytics: a,
1348
+ analytics: i,
1347
1349
  callbacks: {
1348
1350
  ...t.callbacks,
1349
1351
  onConnectionStateChange: (d) => {
1350
- var g, w;
1351
- (w = (g = t.callbacks).onConnectionStateChange) == null || w.call(g, d), d === S.Connected && (s ? c(s) : i = !0);
1352
+ var w, p;
1353
+ (p = (w = t.callbacks).onConnectionStateChange) == null || p.call(w, d), d === R.Connected && (c ? s(c) : a = !0);
1352
1354
  },
1353
- onVideoStateChange: (d, g) => {
1354
- var w, u;
1355
- (u = (w = t.callbacks).onVideoStateChange) == null || u.call(w, d), sn(
1355
+ onVideoStateChange: (d, w) => {
1356
+ var p, u;
1357
+ (u = (p = t.callbacks).onVideoStateChange) == null || u.call(p, d), sn(
1356
1358
  d,
1357
1359
  e,
1358
- g,
1359
- a,
1360
- s.streamType
1360
+ w,
1361
+ i,
1362
+ c.streamType
1361
1363
  );
1362
1364
  },
1363
1365
  onAgentActivityStateChange: (d) => {
1364
- var g, w;
1365
- (w = (g = t.callbacks).onAgentActivityStateChange) == null || w.call(g, d), d === U.Talking ? Re.update() : Re.reset(), dn(
1366
- d === U.Talking ? C.Start : C.Stop,
1366
+ var w, p;
1367
+ (p = (w = t.callbacks).onAgentActivityStateChange) == null || p.call(w, d), d === W.Talking ? Re.update() : Re.reset(), dn(
1368
+ d === W.Talking ? S.Start : S.Stop,
1367
1369
  e,
1368
- a,
1369
- s.streamType
1370
+ i,
1371
+ c.streamType
1370
1372
  );
1371
1373
  },
1372
1374
  onStreamReady: () => {
1373
- const d = Be.get(!0);
1374
- a.track("agent-chat", { event: "ready", latency: d });
1375
+ const d = xe.get(!0);
1376
+ i.track("agent-chat", { event: "ready", latency: d });
1375
1377
  }
1376
1378
  }
1377
1379
  },
1378
1380
  n
1379
- ), i && c(s);
1380
- } catch (s) {
1381
- o(s);
1381
+ ), a && s(c);
1382
+ } catch (c) {
1383
+ o(c);
1382
1384
  }
1383
1385
  });
1384
1386
  }
1385
- async function ln(e, t, a, n, c) {
1386
- var g, w, u, M;
1387
+ async function ln(e, t, i, n, s) {
1388
+ var w, p, u, _;
1387
1389
  const o = async () => {
1388
1390
  if (Ie(e.presenter.type)) {
1389
- const $ = await Ne(e, t, n), V = `${nn}_${$.sessionId}`, E = (/* @__PURE__ */ new Date()).toISOString();
1391
+ const $ = await Ne(e, t, n), A = `${nn}_${$.sessionId}`, C = (/* @__PURE__ */ new Date()).toISOString();
1390
1392
  return { chatResult: {
1391
1393
  chatMode: F.Functional,
1392
1394
  chat: {
1393
- id: V,
1395
+ id: A,
1394
1396
  agent_id: e.id,
1395
1397
  owner_id: e.owner_id ?? "",
1396
- created: E,
1397
- modified: E,
1398
- agent_id__created_at: E,
1399
- agent_id__modified_at: E,
1398
+ created: C,
1399
+ modified: C,
1400
+ agent_id__created_at: C,
1401
+ agent_id__modified_at: C,
1400
1402
  chat_mode: F.Functional,
1401
1403
  messages: []
1402
1404
  }
1403
1405
  }, streamingManager: $ };
1404
1406
  } else {
1405
- const $ = new AbortController(), V = $.signal;
1406
- let E;
1407
+ const $ = new AbortController(), A = $.signal;
1408
+ let C;
1407
1409
  try {
1408
- const I = qe(
1410
+ const B = He(
1409
1411
  e,
1410
- a,
1412
+ i,
1411
1413
  n,
1412
1414
  t.mode,
1413
1415
  t.persistentChat,
1414
- c
1415
- ), z = Ne(e, t, n, V).then((ee) => (E = ee, ee)), [A, W] = await Promise.all([I, z]);
1416
- return { chatResult: A, streamingManager: W };
1417
- } catch (I) {
1418
- throw $.abort(), E && await E.disconnect().catch(() => {
1419
- }), I;
1416
+ s
1417
+ ), z = Ne(e, t, n, A).then((te) => (C = te, te)), [I, U] = await Promise.all([B, z]);
1418
+ return { chatResult: I, streamingManager: U };
1419
+ } catch (B) {
1420
+ throw $.abort(), C && await C.disconnect().catch(() => {
1421
+ }), B;
1420
1422
  }
1421
1423
  }
1422
- }, { chatResult: s, streamingManager: i } = await o(), { chat: r, chatMode: d } = s;
1423
- return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (w = (g = t.callbacks).onModeChange) == null || w.call(g, d), d !== F.Functional) ? ((M = (u = t.callbacks).onError) == null || M.call(u, new Ge(d)), i == null || i.disconnect(), { chat: r }) : { chat: r, streamingManager: i };
1424
+ }, { chatResult: c, streamingManager: a } = await o(), { chat: r, chatMode: d } = c;
1425
+ return d && t.mode !== void 0 && d !== t.mode && (t.mode = d, (p = (w = t.callbacks).onModeChange) == null || p.call(w, d), d !== F.Functional) ? ((_ = (u = t.callbacks).onError) == null || _.call(u, new Ge(d)), a == null || a.disconnect(), { chat: r }) : { chat: r, streamingManager: a };
1424
1426
  }
1425
1427
  async function gn(e, t) {
1426
- var T, G, Z;
1427
- let a = !0, n = null;
1428
- const c = t.mixpanelKey || ft, o = t.wsURL || lt, s = t.baseURL || ge, i = t.mode || F.Functional, r = {
1428
+ var M, Y, Z;
1429
+ let i = !0, n = null;
1430
+ const s = t.mixpanelKey || ft, o = t.wsURL || lt, c = t.baseURL || ge, a = t.mode || F.Functional, r = {
1429
1431
  messages: [],
1430
- chatMode: i
1432
+ chatMode: a
1431
1433
  }, d = Rt({
1432
- token: c,
1434
+ token: s,
1433
1435
  agentId: e,
1434
1436
  isEnabled: t.enableAnalitics,
1435
1437
  externalId: t.externalId,
1436
1438
  mixpanelAdditionalProperties: t.mixpanelAdditionalProperties
1437
- }), g = Date.now();
1438
- xe(() => {
1439
- d.track("agent-sdk", { event: "init" }, g);
1439
+ }), w = Date.now();
1440
+ Be(() => {
1441
+ d.track("agent-sdk", { event: "init" }, w);
1440
1442
  });
1441
- const w = wt(t.auth, s, t.callbacks.onError, t.externalId), u = await w.getById(e), M = Ie(u.presenter.type);
1443
+ const p = wt(t.auth, c, t.callbacks.onError, t.externalId), u = await p.getById(e), _ = Ie(u.presenter.type);
1442
1444
  d.enrich(vt(u));
1443
- const { onMessage: $, clearQueue: V } = zt(
1445
+ const { onMessage: $, clearQueue: A } = zt(
1444
1446
  d,
1445
1447
  r,
1446
1448
  t,
@@ -1450,43 +1452,43 @@ async function gn(e, t) {
1450
1452
  return (f = r.socketManager) == null ? void 0 : f.disconnect();
1451
1453
  }
1452
1454
  );
1453
- r.messages = Mt(t.initialMessages), (G = (T = t.callbacks).onNewMessage) == null || G.call(T, [...r.messages], "answer");
1454
- const E = (f) => {
1455
+ r.messages = Mt(t.initialMessages), (Y = (M = t.callbacks).onNewMessage) == null || Y.call(M, [...r.messages], "answer");
1456
+ const C = (f) => {
1455
1457
  n = f;
1456
- }, I = ({ type: f }) => {
1457
- var k, P, L;
1458
+ }, B = ({ type: f }) => {
1459
+ var k, T, P;
1458
1460
  const y = r.messages[r.messages.length - 1];
1459
1461
  d.track("agent-video-interrupt", {
1460
1462
  type: f || "click",
1461
1463
  video_duration_to_interrupt: Re.get(!0),
1462
- message_duration_to_interrupt: ie.get(!0)
1463
- }), y.interrupted = !0, (P = (k = t.callbacks).onNewMessage) == null || P.call(k, [...r.messages], "answer"), M ? Lt(r.streamingManager) : (At(r.streamingManager, (L = r.streamingManager) == null ? void 0 : L.streamType, n), Pt(r.streamingManager, n));
1464
+ message_duration_to_interrupt: ee.get(!0)
1465
+ }), y.interrupted = !0, (T = (k = t.callbacks).onNewMessage) == null || T.call(k, [...r.messages], "answer"), _ ? Lt(r.streamingManager) : (At(r.streamingManager, (P = r.streamingManager) == null ? void 0 : P.streamType, n), Pt(r.streamingManager, n));
1464
1466
  }, z = Date.now();
1465
- xe(() => {
1467
+ Be(() => {
1466
1468
  d.track("agent-sdk", { event: "loaded", ...yt(u) }, z);
1467
1469
  });
1468
- async function A(f) {
1469
- var J, H, Q, b, N, X, oe;
1470
- (H = (J = t.callbacks).onConnectionStateChange) == null || H.call(J, S.Connecting), ie.reset(), f && !a && (delete r.chat, (b = (Q = t.callbacks).onNewMessage) == null || b.call(Q, [...r.messages], "answer"));
1471
- const y = i === F.DirectPlayback || M ? Promise.resolve(void 0) : $t(
1470
+ async function I(f) {
1471
+ var J, O, H, L, N, q, oe;
1472
+ (O = (J = t.callbacks).onConnectionStateChange) == null || O.call(J, R.Connecting), ee.reset(), f && !i && (delete r.chat, (L = (H = t.callbacks).onNewMessage) == null || L.call(H, [...r.messages], "answer"));
1473
+ const y = a === F.DirectPlayback || _ ? Promise.resolve(void 0) : $t(
1472
1474
  t.auth,
1473
1475
  o,
1474
1476
  { onMessage: $, onError: t.callbacks.onError },
1475
1477
  t.externalId
1476
- ), k = Ce(
1478
+ ), k = Se(
1477
1479
  () => ln(
1478
1480
  u,
1479
1481
  {
1480
1482
  ...t,
1481
- mode: i,
1483
+ mode: a,
1482
1484
  callbacks: {
1483
1485
  ...t.callbacks,
1484
- onVideoIdChange: E,
1486
+ onVideoIdChange: C,
1485
1487
  onMessage: $,
1486
- onInterruptDetected: I
1488
+ onInterruptDetected: B
1487
1489
  }
1488
1490
  },
1489
- w,
1491
+ p,
1490
1492
  d,
1491
1493
  r.chat
1492
1494
  ),
@@ -1494,26 +1496,26 @@ async function gn(e, t) {
1494
1496
  limit: 3,
1495
1497
  timeout: dt,
1496
1498
  timeoutErrorMessage: "Timeout initializing the stream",
1497
- shouldRetryFn: (O) => (O == null ? void 0 : O.message) !== "Could not connect" && O.status !== 429 && (O == null ? void 0 : O.message) !== "InsufficientCreditsError",
1499
+ shouldRetryFn: (V) => (V == null ? void 0 : V.message) !== "Could not connect" && V.status !== 429 && (V == null ? void 0 : V.message) !== "InsufficientCreditsError",
1498
1500
  delayMs: 1e3
1499
1501
  }
1500
- ).catch((O) => {
1501
- var m, p;
1502
- throw ee(F.Maintenance), (p = (m = t.callbacks).onConnectionStateChange) == null || p.call(m, S.Fail), O;
1503
- }), [P, { streamingManager: L, chat: _ }] = await Promise.all([y, k]);
1504
- _ && _.id !== ((N = r.chat) == null ? void 0 : N.id) && ((oe = (X = t.callbacks).onNewChat) == null || oe.call(X, _.id)), r.streamingManager = L, r.socketManager = P, r.chat = _, a = !1, d.enrich({
1505
- chatId: _ == null ? void 0 : _.id,
1506
- streamId: L == null ? void 0 : L.streamId,
1502
+ ).catch((V) => {
1503
+ var m, h;
1504
+ throw te(F.Maintenance), (h = (m = t.callbacks).onConnectionStateChange) == null || h.call(m, R.Fail), V;
1505
+ }), [T, { streamingManager: P, chat: E }] = await Promise.all([y, k]);
1506
+ E && E.id !== ((N = r.chat) == null ? void 0 : N.id) && ((oe = (q = t.callbacks).onNewChat) == null || oe.call(q, E.id)), r.streamingManager = P, r.socketManager = T, r.chat = E, i = !1, d.enrich({
1507
+ chatId: E == null ? void 0 : E.id,
1508
+ streamId: P == null ? void 0 : P.streamId,
1507
1509
  mode: r.chatMode
1508
- }), ee((_ == null ? void 0 : _.chat_mode) ?? i);
1510
+ }), te((E == null ? void 0 : E.chat_mode) ?? a);
1509
1511
  }
1510
- async function W() {
1511
- var f, y, k, P;
1512
- (f = r.socketManager) == null || f.disconnect(), await ((y = r.streamingManager) == null ? void 0 : y.disconnect()), delete r.streamingManager, delete r.socketManager, (P = (k = t.callbacks).onConnectionStateChange) == null || P.call(k, S.Disconnected);
1512
+ async function U() {
1513
+ var f, y, k, T;
1514
+ (f = r.socketManager) == null || f.disconnect(), await ((y = r.streamingManager) == null ? void 0 : y.disconnect()), delete r.streamingManager, delete r.socketManager, (T = (k = t.callbacks).onConnectionStateChange) == null || T.call(k, R.Disconnected);
1513
1515
  }
1514
- async function ee(f) {
1516
+ async function te(f) {
1515
1517
  var y, k;
1516
- f !== r.chatMode && (d.track("agent-mode-change", { mode: f }), r.chatMode = f, r.chatMode !== F.Functional && await W(), (k = (y = t.callbacks).onModeChange) == null || k.call(y, f));
1518
+ f !== r.chatMode && (d.track("agent-mode-change", { mode: f }), r.chatMode = f, r.chatMode !== F.Functional && await U(), (k = (y = t.callbacks).onModeChange) == null || k.call(y, f));
1517
1519
  }
1518
1520
  return {
1519
1521
  agent: u,
@@ -1530,35 +1532,35 @@ async function gn(e, t) {
1530
1532
  return ((f = r.streamingManager) == null ? void 0 : f.triggersAvailable) ?? !1;
1531
1533
  },
1532
1534
  starterMessages: ((Z = u.knowledge) == null ? void 0 : Z.starter_message) || [],
1533
- getSTTToken: () => w.getSTTToken(u.id),
1534
- changeMode: ee,
1535
+ getSTTToken: () => p.getSTTToken(u.id),
1536
+ changeMode: te,
1535
1537
  enrichAnalytics: d.enrich,
1536
1538
  async connect() {
1537
- await A(!0), d.track("agent-chat", {
1539
+ await I(!0), d.track("agent-chat", {
1538
1540
  event: "connect",
1539
1541
  mode: r.chatMode
1540
1542
  });
1541
1543
  },
1542
1544
  async reconnect() {
1543
1545
  const f = r.streamingManager;
1544
- if (M && (f != null && f.reconnect)) {
1546
+ if (_ && (f != null && f.reconnect)) {
1545
1547
  try {
1546
1548
  await f.reconnect(), d.track("agent-chat", {
1547
1549
  event: "reconnect",
1548
1550
  mode: r.chatMode
1549
1551
  });
1550
1552
  } catch {
1551
- await W(), await A(!1);
1553
+ await U(), await I(!1);
1552
1554
  }
1553
1555
  return;
1554
1556
  }
1555
- await W(), await A(!1), d.track("agent-chat", {
1557
+ await U(), await I(!1), d.track("agent-chat", {
1556
1558
  event: "reconnect",
1557
1559
  mode: r.chatMode
1558
1560
  });
1559
1561
  },
1560
1562
  async disconnect() {
1561
- await W(), d.track("agent-chat", {
1563
+ await U(), d.track("agent-chat", {
1562
1564
  event: "disconnect",
1563
1565
  mode: r.chatMode
1564
1566
  });
@@ -1576,80 +1578,80 @@ async function gn(e, t) {
1576
1578
  return r.streamingManager.unpublishMicrophoneStream();
1577
1579
  },
1578
1580
  async chat(f) {
1579
- var L, _, J, H, Q;
1581
+ var P, E, J, O, H;
1580
1582
  const y = () => {
1581
- if (We(i))
1582
- throw new ce(`${i} is enabled, chat is disabled`);
1583
+ if (Ve(a))
1584
+ throw new ue(`${a} is enabled, chat is disabled`);
1583
1585
  if (f.length >= 800)
1584
- throw new ce("Message cannot be more than 800 characters");
1586
+ throw new ue("Message cannot be more than 800 characters");
1585
1587
  if (f.length === 0)
1586
- throw new ce("Message cannot be empty");
1588
+ throw new ue("Message cannot be empty");
1587
1589
  if (r.chatMode === F.Maintenance)
1588
- throw new ce("Chat is in maintenance mode");
1590
+ throw new ue("Chat is in maintenance mode");
1589
1591
  if (![F.TextOnly, F.Playground].includes(r.chatMode)) {
1590
1592
  if (!r.streamingManager)
1591
- throw new ce("Streaming manager is not initialized");
1593
+ throw new ue("Streaming manager is not initialized");
1592
1594
  if (!r.chat)
1593
- throw new ce("Chat is not initialized");
1595
+ throw new ue("Chat is not initialized");
1594
1596
  }
1595
1597
  }, k = async () => {
1596
- var b, N;
1598
+ var L, N;
1597
1599
  if (!r.chat) {
1598
- const X = await qe(
1600
+ const q = await He(
1599
1601
  u,
1600
- w,
1602
+ p,
1601
1603
  d,
1602
1604
  r.chatMode,
1603
1605
  t.persistentChat
1604
1606
  );
1605
- if (!X.chat)
1607
+ if (!q.chat)
1606
1608
  throw new Ye(r.chatMode, !!t.persistentChat);
1607
- r.chat = X.chat, (N = (b = t.callbacks).onNewChat) == null || N.call(b, r.chat.id);
1609
+ r.chat = q.chat, (N = (L = t.callbacks).onNewChat) == null || N.call(L, r.chat.id);
1608
1610
  }
1609
1611
  return r.chat.id;
1610
- }, P = async (b, N) => {
1611
- const X = r.chatMode === F.Playground;
1612
- return Ce(M && !X ? async () => {
1613
- var m, p;
1614
- return await ((p = (m = r.streamingManager) == null ? void 0 : m.sendTextMessage) == null ? void 0 : p.call(m, f)), Promise.resolve({});
1612
+ }, T = async (L, N) => {
1613
+ const q = r.chatMode === F.Playground;
1614
+ return Se(_ && !q ? async () => {
1615
+ var m, h;
1616
+ return await ((h = (m = r.streamingManager) == null ? void 0 : m.sendTextMessage) == null ? void 0 : h.call(m, f)), Promise.resolve({});
1615
1617
  } : async () => {
1616
- var m, p;
1617
- return w.chat(
1618
+ var m, h;
1619
+ return p.chat(
1618
1620
  u.id,
1619
1621
  N,
1620
1622
  {
1621
1623
  chatMode: r.chatMode,
1622
1624
  streamId: (m = r.streamingManager) == null ? void 0 : m.streamId,
1623
- sessionId: (p = r.streamingManager) == null ? void 0 : p.sessionId,
1624
- messages: b.map(({ matches: B, ...K }) => K)
1625
+ sessionId: (h = r.streamingManager) == null ? void 0 : h.sessionId,
1626
+ messages: L.map(({ matches: x, ...K }) => K)
1625
1627
  },
1626
1628
  {
1627
- ...Ve(r.chatMode),
1629
+ ...Oe(r.chatMode),
1628
1630
  skipErrorHandler: !0
1629
1631
  }
1630
1632
  );
1631
1633
  }, {
1632
1634
  limit: 2,
1633
1635
  shouldRetryFn: (m) => {
1634
- var K, he, pe, se;
1635
- const p = (K = m == null ? void 0 : m.message) == null ? void 0 : K.includes("missing or invalid session_id");
1636
- return !((he = m == null ? void 0 : m.message) == null ? void 0 : he.includes("Stream Error")) && !p ? ((se = (pe = t.callbacks).onError) == null || se.call(pe, m), !1) : !0;
1636
+ var K, he, pe, ce;
1637
+ const h = (K = m == null ? void 0 : m.message) == null ? void 0 : K.includes("missing or invalid session_id");
1638
+ return !((he = m == null ? void 0 : m.message) == null ? void 0 : he.includes("Stream Error")) && !h ? ((ce = (pe = t.callbacks).onError) == null || ce.call(pe, m), !1) : !0;
1637
1639
  },
1638
1640
  onRetry: async () => {
1639
- await W(), await A(!1);
1641
+ await U(), await I(!1);
1640
1642
  }
1641
1643
  });
1642
1644
  };
1643
1645
  try {
1644
- V(), y(), r.messages.push({
1645
- id: de(),
1646
+ A(), y(), r.messages.push({
1647
+ id: le(),
1646
1648
  role: "user",
1647
1649
  content: f,
1648
- created_at: new Date(ie.update()).toISOString()
1649
- }), (_ = (L = t.callbacks).onNewMessage) == null || _.call(L, [...r.messages], "user");
1650
- const b = await k(), N = await P([...r.messages], b);
1650
+ created_at: new Date(ee.update()).toISOString()
1651
+ }), (E = (P = t.callbacks).onNewMessage) == null || E.call(P, [...r.messages], "user");
1652
+ const L = await k(), N = await T([...r.messages], L);
1651
1653
  return r.messages.push({
1652
- id: de(),
1654
+ id: le(),
1653
1655
  role: "assistant",
1654
1656
  content: N.result || "",
1655
1657
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
@@ -1658,50 +1660,50 @@ async function gn(e, t) {
1658
1660
  }), d.track("agent-message-send", {
1659
1661
  event: "success",
1660
1662
  messages: r.messages.length + 1
1661
- }), N.result && ((H = (J = t.callbacks).onNewMessage) == null || H.call(J, [...r.messages], "answer"), d.track("agent-message-received", {
1662
- latency: ie.get(!0),
1663
+ }), N.result && ((O = (J = t.callbacks).onNewMessage) == null || O.call(J, [...r.messages], "answer"), d.track("agent-message-received", {
1664
+ latency: ee.get(!0),
1663
1665
  messages: r.messages.length
1664
1666
  })), N;
1665
- } catch (b) {
1666
- throw ((Q = r.messages[r.messages.length - 1]) == null ? void 0 : Q.role) === "assistant" && r.messages.pop(), d.track("agent-message-send", {
1667
+ } catch (L) {
1668
+ throw ((H = r.messages[r.messages.length - 1]) == null ? void 0 : H.role) === "assistant" && r.messages.pop(), d.track("agent-message-send", {
1667
1669
  event: "error",
1668
1670
  messages: r.messages.length
1669
- }), b;
1671
+ }), L;
1670
1672
  }
1671
1673
  },
1672
1674
  rate(f, y, k) {
1673
- var _, J, H, Q;
1674
- const P = r.messages.find((b) => b.id === f);
1675
+ var E, J, O, H;
1676
+ const T = r.messages.find((L) => L.id === f);
1675
1677
  if (r.chat) {
1676
- if (!P)
1678
+ if (!T)
1677
1679
  throw new Error("Message not found");
1678
1680
  } else throw new Error("Chat is not initialized");
1679
- const L = ((_ = P.matches) == null ? void 0 : _.map((b) => [b.document_id, b.id])) ?? [];
1681
+ const P = ((E = T.matches) == null ? void 0 : E.map((L) => [L.document_id, L.id])) ?? [];
1680
1682
  return d.track("agent-rate", {
1681
1683
  event: k ? "update" : "create",
1682
1684
  thumb: y === 1 ? "up" : "down",
1683
1685
  knowledge_id: ((J = u.knowledge) == null ? void 0 : J.id) ?? "",
1684
- matches: L,
1686
+ matches: P,
1685
1687
  score: y
1686
- }), k ? w.updateRating(u.id, r.chat.id, k, {
1687
- knowledge_id: ((H = u.knowledge) == null ? void 0 : H.id) ?? "",
1688
+ }), k ? p.updateRating(u.id, r.chat.id, k, {
1689
+ knowledge_id: ((O = u.knowledge) == null ? void 0 : O.id) ?? "",
1688
1690
  message_id: f,
1689
- matches: L,
1691
+ matches: P,
1690
1692
  score: y
1691
- }) : w.createRating(u.id, r.chat.id, {
1692
- knowledge_id: ((Q = u.knowledge) == null ? void 0 : Q.id) ?? "",
1693
+ }) : p.createRating(u.id, r.chat.id, {
1694
+ knowledge_id: ((H = u.knowledge) == null ? void 0 : H.id) ?? "",
1693
1695
  message_id: f,
1694
- matches: L,
1696
+ matches: P,
1695
1697
  score: y
1696
1698
  });
1697
1699
  },
1698
1700
  deleteRate(f) {
1699
1701
  if (!r.chat)
1700
1702
  throw new Error("Chat is not initialized");
1701
- return d.track("agent-rate-delete", { type: "text" }), w.deleteRating(u.id, r.chat.id, f);
1703
+ return d.track("agent-rate-delete", { type: "text" }), p.deleteRating(u.id, r.chat.id, f);
1702
1704
  },
1703
1705
  async speak(f) {
1704
- var L, _, J;
1706
+ var P, E, J;
1705
1707
  function y() {
1706
1708
  if (typeof f == "string") {
1707
1709
  if (!u.presenter.voice)
@@ -1726,12 +1728,12 @@ async function gn(e, t) {
1726
1728
  return f;
1727
1729
  }
1728
1730
  const k = y();
1729
- if (d.track("agent-speak", k), ie.update(), r.messages && k.type === "text" && (r.messages.push({
1730
- id: de(),
1731
+ if (d.track("agent-speak", k), ee.update(), r.messages && k.type === "text" && (r.messages.push({
1732
+ id: le(),
1731
1733
  role: "assistant",
1732
1734
  content: k.input,
1733
1735
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1734
- }), (_ = (L = t.callbacks).onNewMessage) == null || _.call(L, [...r.messages], "answer")), mt(r.chatMode))
1736
+ }), (E = (P = t.callbacks).onNewMessage) == null || E.call(P, [...r.messages], "answer")), mt(r.chatMode))
1735
1737
  return {
1736
1738
  duration: 0,
1737
1739
  video_id: "",
@@ -1744,18 +1746,18 @@ async function gn(e, t) {
1744
1746
  metadata: { chat_id: (J = r.chat) == null ? void 0 : J.id, agent_id: u.id }
1745
1747
  });
1746
1748
  },
1747
- interrupt: I
1749
+ interrupt: B
1748
1750
  };
1749
1751
  }
1750
1752
  export {
1751
- U as AgentActivityState,
1753
+ W as AgentActivityState,
1752
1754
  nt as AgentStatus,
1753
1755
  Ye as ChatCreationFailed,
1754
1756
  F as ChatMode,
1755
1757
  Ge as ChatModeDowngraded,
1756
- Y as ChatProgress,
1757
- S as ConnectionState,
1758
- re as ConnectivityState,
1758
+ X as ChatProgress,
1759
+ R as ConnectionState,
1760
+ ie as ConnectivityState,
1759
1761
  ot as DocumentType,
1760
1762
  at as KnowledgeType,
1761
1763
  tt as PlanGroup,
@@ -1763,11 +1765,11 @@ export {
1763
1765
  rt as RateState,
1764
1766
  j as StreamEvents,
1765
1767
  ae as StreamType,
1766
- C as StreamingState,
1768
+ S as StreamingState,
1767
1769
  it as Subject,
1768
1770
  ye as TransportProvider,
1769
1771
  et as UserPlan,
1770
- ce as ValidationError,
1772
+ ue as ValidationError,
1771
1773
  Ke as VideoType,
1772
1774
  ct as VoiceAccess,
1773
1775
  Ze as WsError,