@d-id/client-sdk 1.1.57-staging.267 → 1.1.57-staging.269

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