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

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,220 @@ 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 || "",
1079
1121
  created_at: n.created_at || (/* @__PURE__ */ new Date()).toISOString()
1080
- }, r.messages.push(s);
1122
+ }, r.messages.push(o);
1081
1123
  else
1082
1124
  return;
1083
1125
  const { content: d, sequence: t } = n;
1084
1126
  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));
1127
+ const c = Mn(i);
1128
+ (o.content !== c || e === X.Answer) && (o.content = c, o.parts = Te(c), s == null || s([...r.messages], e));
1087
1129
  }
1088
- function Sn(e, n, i, r, o) {
1130
+ function _n(e, n, i, r, s) {
1089
1131
  let a = {};
1090
- const s = () => a = {};
1132
+ const o = () => a = {};
1091
1133
  let d = "answer";
1092
1134
  const t = (c, h) => {
1093
1135
  var g, l;
1094
- h === "user" && s(), d = h, (l = (g = i.callbacks).onNewMessage) == null || l.call(g, c, h);
1136
+ h === "user" && o(), d = h, (l = (g = i.callbacks).onNewMessage) == null || l.call(g, c, h);
1095
1137
  };
1096
1138
  return {
1097
- clearQueue: s,
1139
+ clearQueue: o,
1098
1140
  onMessage: (c, h) => {
1099
1141
  var g, l;
1100
1142
  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", {
1143
+ const v = c === I.ChatAnswer ? X.Answer : c === I.ChatAudioTranscribed ? X.Transcribe : c;
1144
+ Dn(v, h, a, n, t), v === X.Answer && e.track("agent-message-received", {
1103
1145
  content: h.content,
1104
1146
  messages: n.messages.length,
1105
1147
  mode: n.chatMode
1106
1148
  });
1107
1149
  } 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)) {
1150
+ const v = I, L = [v.StreamVideoDone, v.StreamVideoError, v.StreamVideoRejected], K = [v.StreamFailed, v.StreamVideoError, v.StreamVideoRejected], B = en(h, r, { mode: n.chatMode });
1151
+ if (c = c, c === v.StreamVideoCreated && (e.linkTrack("agent-video", B, v.StreamVideoCreated, ["start"]), h.sentiment)) {
1110
1152
  const F = n.messages[n.messages.length - 1];
1111
1153
  if ((F == null ? void 0 : F.role) === "assistant") {
1112
1154
  const M = { ...F, sentiment: h.sentiment };
1113
1155
  n.messages[n.messages.length - 1] = M, t == null || t([...n.messages], d);
1114
1156
  }
1115
1157
  }
1116
- if (P.includes(c)) {
1158
+ if (L.includes(c)) {
1117
1159
  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"]);
1160
+ K.includes(c) ? e.track("agent-video", { ...B, event: F }) : e.linkTrack("agent-video", { ...B, event: F }, c, ["done"]);
1119
1161
  }
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();
1162
+ 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
1163
  }
1122
1164
  }
1123
1165
  };
1124
1166
  }
1125
- function Rn(e, n, i, r) {
1126
- const o = ze(e, `${n}/agents/${i}`, r);
1167
+ function An(e, n, i, r) {
1168
+ const s = ze(e, `${n}/agents/${i}`, r);
1127
1169
  return {
1128
- createStream(a, s) {
1129
- return o.post("/streams", a, { signal: s });
1170
+ createStream(a, o) {
1171
+ return s.post("/streams", a, { signal: o });
1130
1172
  },
1131
- startConnection(a, s, d, t) {
1132
- return o.post(
1173
+ startConnection(a, o, d, t) {
1174
+ return s.post(
1133
1175
  `/streams/${a}/sdp`,
1134
1176
  {
1135
1177
  session_id: d,
1136
- answer: s
1178
+ answer: o
1137
1179
  },
1138
1180
  { signal: t }
1139
1181
  );
1140
1182
  },
1141
- addIceCandidate(a, s, d, t) {
1142
- return o.post(
1183
+ addIceCandidate(a, o, d, t) {
1184
+ return s.post(
1143
1185
  `/streams/${a}/ice`,
1144
1186
  {
1145
1187
  session_id: d,
1146
- ...s
1188
+ ...o
1147
1189
  },
1148
1190
  { signal: t }
1149
1191
  );
1150
1192
  },
1151
- sendStreamRequest(a, s, d) {
1152
- return o.post(`/streams/${a}`, {
1153
- session_id: s,
1193
+ sendStreamRequest(a, o, d) {
1194
+ return s.post(`/streams/${a}`, {
1195
+ session_id: o,
1154
1196
  ...d
1155
1197
  });
1156
1198
  },
1157
- close(a, s) {
1158
- return o.delete(`/streams/${a}`, { session_id: s });
1199
+ close(a, o) {
1200
+ return s.delete(`/streams/${a}`, { session_id: o });
1159
1201
  }
1160
1202
  };
1161
1203
  }
1162
- const Tn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
1163
- function Ge(e) {
1204
+ const bn = (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection).bind(window);
1205
+ function at(e) {
1164
1206
  switch (e) {
1165
1207
  case "connected":
1166
- return L.Connected;
1208
+ return P.Connected;
1167
1209
  case "checking":
1168
- return L.Connecting;
1210
+ return P.Connecting;
1169
1211
  case "failed":
1170
- return L.Fail;
1212
+ return P.Fail;
1171
1213
  case "new":
1172
- return L.New;
1214
+ return P.New;
1173
1215
  case "closed":
1174
- return L.Closed;
1216
+ return P.Closed;
1175
1217
  case "disconnected":
1176
- return L.Disconnected;
1218
+ return P.Disconnected;
1177
1219
  case "completed":
1178
- return L.Completed;
1220
+ return P.Completed;
1179
1221
  default:
1180
- return L.New;
1222
+ return P.New;
1181
1223
  }
1182
1224
  }
1183
- const kn = (e) => (n) => {
1225
+ const Ln = (e) => (n) => {
1184
1226
  const [i, r = ""] = n.split(/:(.+)/);
1185
1227
  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 };
1228
+ const s = JSON.parse(r);
1229
+ return e("parsed data channel message", { subject: i, data: s }), { subject: i, data: s };
1230
+ } catch (s) {
1231
+ return e("Failed to parse data channel message, returning data as string", { subject: i, rawData: r, error: s }), { subject: i, data: r };
1190
1232
  }
1191
1233
  };
1192
- function En({
1234
+ function Pn({
1193
1235
  statsSignal: e,
1194
1236
  dataChannelSignal: n,
1195
1237
  onVideoStateChange: i,
1196
1238
  report: r,
1197
- log: o
1239
+ log: s
1198
1240
  }) {
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));
1241
+ 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
1242
  }
1201
- function Mn({
1243
+ function xn({
1202
1244
  statsSignal: e,
1203
1245
  dataChannelSignal: n,
1204
1246
  onVideoStateChange: i,
1205
1247
  onAgentActivityStateChange: r,
1206
- report: o,
1248
+ report: s,
1207
1249
  log: a
1208
1250
  }) {
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));
1251
+ 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
1252
  }
1211
- function Ze({
1253
+ function ot({
1212
1254
  statsSignal: e,
1213
1255
  dataChannelSignal: n,
1214
1256
  onVideoStateChange: i,
1215
1257
  onAgentActivityStateChange: r,
1216
- streamType: o,
1258
+ streamType: s,
1217
1259
  report: a,
1218
- log: s
1260
+ log: o
1219
1261
  }) {
1220
- o === se.Legacy ? En({ statsSignal: e, dataChannelSignal: n, onVideoStateChange: i, report: a, log: s }) : o === se.Fluent && Mn({
1262
+ s === se.Legacy ? Pn({ statsSignal: e, dataChannelSignal: n, onVideoStateChange: i, report: a, log: o }) : s === se.Fluent && xn({
1221
1263
  statsSignal: e,
1222
1264
  dataChannelSignal: n,
1223
1265
  onVideoStateChange: i,
1224
1266
  onAgentActivityStateChange: r,
1225
1267
  report: a,
1226
- log: s
1268
+ log: o
1227
1269
  });
1228
1270
  }
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);
1271
+ async function $n(e, n, { debug: i = !1, callbacks: r, auth: s, baseURL: a = Ee, analytics: o }, d) {
1272
+ var J;
1273
+ const t = pt(i, "WebRTCStreamingManager"), c = Ln(t);
1232
1274
  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,
1275
+ const { startConnection: L, sendStreamRequest: K, close: B, createStream: F, addIceCandidate: M } = An(
1276
+ s,
1235
1277
  a,
1236
1278
  e,
1237
1279
  r.onError
1238
1280
  ), {
1239
- id: E,
1281
+ id: k,
1240
1282
  offer: Y,
1241
1283
  ice_servers: Q,
1242
- session_id: J,
1284
+ session_id: U,
1243
1285
  fluent: te,
1244
1286
  interrupt_enabled: ne
1245
1287
  } = 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)
1288
+ (J = r.onStreamCreated) == null || J.call(r, { stream_id: k, session_id: U, agent_id: e });
1289
+ const x = new bn({ iceServers: Q }), N = x.createDataChannel("JanusDataChannel");
1290
+ if (!U)
1249
1291
  throw new Error("Could not create session_id");
1250
1292
  const H = te ? se.Fluent : se.Legacy;
1251
- s.enrich({
1293
+ o.enrich({
1252
1294
  "stream-type": H
1253
1295
  });
1254
1296
  const re = n.stream_warmup && !te, de = () => h, ue = () => {
1255
1297
  var w;
1256
- h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (w = r.onConnectionStateChange) == null || w.call(r, L.Connected));
1257
- }, f = lt(
1258
- () => $.getStats(),
1298
+ h = !0, g && (t("CALLBACK: onConnectionStateChange(Connected)"), (w = r.onConnectionStateChange) == null || w.call(r, P.Connected));
1299
+ }, f = yt(
1300
+ () => x.getStats(),
1259
1301
  de,
1260
1302
  ue,
1261
- (w, y) => Ze({
1303
+ (w, y) => ot({
1262
1304
  statsSignal: v = w,
1263
1305
  dataChannelSignal: H === se.Legacy ? l : void 0,
1264
1306
  onVideoStateChange: r.onVideoStateChange,
@@ -1272,24 +1314,24 @@ async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = Te,
1272
1314
  return (y = r.onConnectivityStateChange) == null ? void 0 : y.call(r, w);
1273
1315
  }
1274
1316
  );
1275
- f.start(), $.onicecandidate = (w) => {
1317
+ f.start(), x.onicecandidate = (w) => {
1276
1318
  var y;
1277
1319
  t("peerConnection.onicecandidate", w);
1278
1320
  try {
1279
1321
  w.candidate && w.candidate.sdpMid && w.candidate.sdpMLineIndex !== null ? M(
1280
- E,
1322
+ k,
1281
1323
  {
1282
1324
  candidate: w.candidate.candidate,
1283
1325
  sdpMid: w.candidate.sdpMid,
1284
1326
  sdpMLineIndex: w.candidate.sdpMLineIndex
1285
1327
  },
1286
- J,
1328
+ U,
1287
1329
  d
1288
- ) : M(E, { candidate: null }, J, d);
1289
- } catch (k) {
1290
- (y = r.onError) == null || y.call(r, k, { streamId: E });
1330
+ ) : M(k, { candidate: null }, U, d);
1331
+ } catch (E) {
1332
+ (y = r.onError) == null || y.call(r, E, { streamId: k });
1291
1333
  }
1292
- }, K.onopen = () => {
1334
+ }, N.onopen = () => {
1293
1335
  g = !0, (!re || h) && ue();
1294
1336
  };
1295
1337
  const C = (w) => {
@@ -1297,11 +1339,11 @@ async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = Te,
1297
1339
  (y = r.onVideoIdChange) == null || y.call(r, w);
1298
1340
  };
1299
1341
  function R(w, y) {
1300
- if (w === D.StreamStarted && typeof y == "object" && "metadata" in y) {
1301
- const k = y.metadata;
1302
- C(k.videoId);
1342
+ if (w === I.StreamStarted && typeof y == "object" && "metadata" in y) {
1343
+ const E = y.metadata;
1344
+ C(E.videoId);
1303
1345
  }
1304
- w === D.StreamDone && C(null), l = w === D.StreamStarted ? T.Start : T.Stop, Ze({
1346
+ w === I.StreamDone && C(null), l = w === I.StreamStarted ? T.Start : T.Stop, ot({
1305
1347
  statsSignal: H === se.Legacy ? v : void 0,
1306
1348
  dataChannelSignal: l,
1307
1349
  onVideoStateChange: r.onVideoStateChange,
@@ -1310,57 +1352,57 @@ async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = Te,
1310
1352
  log: t
1311
1353
  });
1312
1354
  }
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);
1355
+ function _(w, y) {
1356
+ var $;
1357
+ const E = typeof y == "string" ? y : y == null ? void 0 : y.metadata;
1358
+ E && o.enrich({ streamMetadata: E }), ($ = r.onStreamReady) == null || $.call(r);
1317
1359
  }
1318
- const I = {
1319
- [D.StreamStarted]: R,
1320
- [D.StreamDone]: R,
1321
- [D.StreamReady]: A
1360
+ const D = {
1361
+ [I.StreamStarted]: R,
1362
+ [I.StreamDone]: R,
1363
+ [I.StreamReady]: _
1322
1364
  };
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 = () => {
1365
+ N.onmessage = (w) => {
1366
+ var $;
1367
+ const { subject: y, data: E } = c(w.data);
1368
+ ($ = D[y]) == null || $.call(D, y, E);
1369
+ }, x.oniceconnectionstatechange = () => {
1328
1370
  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) => {
1371
+ t("peerConnection.oniceconnectionstatechange => " + x.iceConnectionState);
1372
+ const w = at(x.iceConnectionState);
1373
+ w !== P.Connected && ((y = r.onConnectionStateChange) == null || y.call(r, w));
1374
+ }, x.ontrack = (w) => {
1333
1375
  var y;
1334
1376
  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"), {
1377
+ }, await x.setRemoteDescription(Y), t("set remote description OK");
1378
+ const b = await x.createAnswer();
1379
+ 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
1380
  /**
1339
1381
  * Method to send request to server to get clip or talk depend on you payload
1340
1382
  * @param payload
1341
1383
  */
1342
1384
  speak(w) {
1343
- return z(E, J, w);
1385
+ return K(k, U, w);
1344
1386
  },
1345
1387
  /**
1346
1388
  * Method to close RTC connection
1347
1389
  */
1348
1390
  async disconnect() {
1349
1391
  var w;
1350
- if (E) {
1351
- const y = Ge($.iceConnectionState);
1352
- if ($) {
1353
- if (y === L.New) {
1392
+ if (k) {
1393
+ const y = at(x.iceConnectionState);
1394
+ if (x) {
1395
+ if (y === P.New) {
1354
1396
  f.stop();
1355
1397
  return;
1356
1398
  }
1357
- $.close(), $.oniceconnectionstatechange = null, $.onnegotiationneeded = null, $.onicecandidate = null, $.ontrack = null;
1399
+ x.close(), x.oniceconnectionstatechange = null, x.onnegotiationneeded = null, x.onicecandidate = null, x.ontrack = null;
1358
1400
  }
1359
1401
  try {
1360
- y === L.Connected && await x(E, J).catch((k) => {
1402
+ y === P.Connected && await B(k, U).catch((E) => {
1361
1403
  });
1362
- } catch (k) {
1363
- t("Error on close stream connection", k);
1404
+ } catch (E) {
1405
+ t("Error on close stream connection", E);
1364
1406
  }
1365
1407
  (w = r.onAgentActivityStateChange) == null || w.call(r, W.Idle), f.stop();
1366
1408
  }
@@ -1369,65 +1411,65 @@ async function Dn(e, n, { debug: i = !1, callbacks: r, auth: o, baseURL: a = Te,
1369
1411
  * Method to send data channel messages to the server
1370
1412
  */
1371
1413
  sendDataChannelMessage(w) {
1372
- var y, k;
1373
- if (!h || K.readyState !== "open") {
1414
+ var y, E;
1415
+ if (!h || N.readyState !== "open") {
1374
1416
  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
1417
+ streamId: k
1376
1418
  });
1377
1419
  return;
1378
1420
  }
1379
1421
  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 });
1422
+ N.send(w);
1423
+ } catch ($) {
1424
+ t("Error sending data channel message", $), (E = r.onError) == null || E.call(r, $, { streamId: k });
1383
1425
  }
1384
1426
  },
1385
1427
  /**
1386
1428
  * Session identifier information, should be returned in the body of all streaming requests
1387
1429
  */
1388
- sessionId: J,
1430
+ sessionId: U,
1389
1431
  /**
1390
1432
  * Id of current RTC stream
1391
1433
  */
1392
- streamId: E,
1434
+ streamId: k,
1393
1435
  streamType: H,
1394
1436
  interruptAvailable: ne ?? !1,
1395
1437
  isInterruptible: !0
1396
1438
  };
1397
1439
  }
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;
1440
+ var Fe = /* @__PURE__ */ ((e) => (e.V1 = "v1", e.V2 = "v2", e))(Fe || {});
1441
+ async function jn(e, n, i, r) {
1442
+ const s = e.id;
1401
1443
  switch (n.version) {
1402
1444
  case "v1": {
1403
- const { version: a, ...s } = n;
1404
- return Dn(o, s, i, r);
1445
+ const { version: a, ...o } = n;
1446
+ return $n(s, o, i, r);
1405
1447
  }
1406
1448
  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);
1449
+ const { version: a, ...o } = n;
1450
+ switch (o.transport.provider) {
1451
+ case Ke.Livekit:
1452
+ const { createLiveKitStreamingManager: d } = await Promise.resolve().then(() => vn);
1453
+ return d(s, o, i);
1412
1454
  default:
1413
- throw new Error(`Unsupported transport provider: ${s.transport.provider}`);
1455
+ throw new Error(`Unsupported transport provider: ${o.transport.provider}`);
1414
1456
  }
1415
1457
  }
1416
1458
  default:
1417
1459
  throw new Error(`Invalid stream version: ${n.version}`);
1418
1460
  }
1419
1461
  }
1420
- const An = "cht";
1421
- function _n() {
1462
+ const Bn = "cht";
1463
+ function Fn() {
1422
1464
  return {
1423
1465
  transport: {
1424
- provider: Be.Livekit
1466
+ provider: Ke.Livekit
1425
1467
  }
1426
1468
  };
1427
1469
  }
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 ? {
1470
+ function Kn(e) {
1471
+ var s, a;
1472
+ const { streamOptions: n } = e ?? {}, i = ((s = e == null ? void 0 : e.mixpanelAdditionalProperties) == null ? void 0 : s.plan) !== void 0 ? {
1431
1473
  plan: (a = e.mixpanelAdditionalProperties) == null ? void 0 : a.plan
1432
1474
  } : void 0;
1433
1475
  return { ...{
@@ -1438,27 +1480,27 @@ function bn(e) {
1438
1480
  fluent: n == null ? void 0 : n.fluent
1439
1481
  }, ...i && { end_user_data: i } };
1440
1482
  }
1441
- function Pn(e, n) {
1442
- return Fe(e.presenter.type) ? { version: xe.V2, ..._n() } : { version: xe.V1, ...bn(n) };
1483
+ function Nn(e, n) {
1484
+ return Ne(e.presenter.type) ? { version: Fe.V2, ...Fn() } : { version: Fe.V1, ...Kn(n) };
1443
1485
  }
1444
- function Ln(e, n, i) {
1486
+ function zn(e, n, i) {
1445
1487
  i.track("agent-connection-state-change", { state: e, ...n && { reason: n } });
1446
1488
  }
1447
- function $n(e, n, i, r, o) {
1448
- o === se.Fluent ? jn(e, n, i, r, o) : xn(e, n, i, r, o);
1489
+ function Vn(e, n, i, r, s) {
1490
+ s === se.Fluent ? Un(e, n, i, r, s) : Jn(e, n, i, r, s);
1449
1491
  }
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", {
1492
+ function Un(e, n, i, r, s) {
1493
+ e === T.Start ? r.track("stream-session", { event: "start", "stream-type": s }) : e === T.Stop && r.track("stream-session", {
1452
1494
  event: "stop",
1453
1495
  is_greenscreen: n.presenter.type === "clip" && n.presenter.is_greenscreen,
1454
1496
  background: n.presenter.type === "clip" && n.presenter.background,
1455
- "stream-type": o,
1497
+ "stream-type": s,
1456
1498
  ...i
1457
1499
  });
1458
1500
  }
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
1501
+ function st(e, n, i, r, s) {
1502
+ e === T.Start ? i.linkTrack("agent-video", { event: "start", ...s, "stream-type": r }, "start", [
1503
+ I.StreamVideoCreated
1462
1504
  ]) : e === T.Stop && i.linkTrack(
1463
1505
  "agent-video",
1464
1506
  {
@@ -1468,39 +1510,39 @@ function et(e, n, i, r, o) {
1468
1510
  "stream-type": r
1469
1511
  },
1470
1512
  "done",
1471
- [D.StreamVideoDone]
1513
+ [I.StreamVideoDone]
1472
1514
  );
1473
1515
  }
1474
- function xn(e, n, i, r, o) {
1516
+ function Jn(e, n, i, r, s) {
1475
1517
  e === T.Start ? r.linkTrack(
1476
1518
  "agent-video",
1477
- { event: "start", latency: oe.get(!0), "stream-type": o },
1519
+ { event: "start", latency: oe.get(!0), "stream-type": s },
1478
1520
  "start",
1479
- [D.StreamVideoCreated]
1521
+ [I.StreamVideoCreated]
1480
1522
  ) : e === T.Stop && r.linkTrack(
1481
1523
  "agent-video",
1482
1524
  {
1483
1525
  event: "stop",
1484
1526
  is_greenscreen: n.presenter.type === "clip" && n.presenter.is_greenscreen,
1485
1527
  background: n.presenter.type === "clip" && n.presenter.background,
1486
- "stream-type": o,
1528
+ "stream-type": s,
1487
1529
  ...i
1488
1530
  },
1489
1531
  "done",
1490
- [D.StreamVideoDone]
1532
+ [I.StreamVideoDone]
1491
1533
  );
1492
1534
  }
1493
- function tt(e, n, i, r) {
1494
- return oe.reset(), Qe.update(), new Promise(async (o, a) => {
1535
+ function ct(e, n, i, r) {
1536
+ return oe.reset(), nt.update(), new Promise(async (s, a) => {
1495
1537
  try {
1496
- let s, d = !1;
1497
- const t = Pn(e, n);
1538
+ let o, d = !1;
1539
+ const t = Nn(e, n);
1498
1540
  i.enrich({
1499
1541
  "stream-version": t.version.toString()
1500
1542
  });
1501
1543
  let c = null;
1502
1544
  const h = e.presenter.type === "expressive";
1503
- s = await In(
1545
+ o = await jn(
1504
1546
  e,
1505
1547
  t,
1506
1548
  {
@@ -1509,178 +1551,178 @@ function tt(e, n, i, r) {
1509
1551
  callbacks: {
1510
1552
  ...n.callbacks,
1511
1553
  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);
1554
+ var v, L;
1555
+ (L = (v = n.callbacks).onConnectionStateChange) == null || L.call(v, g), zn(g, l, i), g === P.Connected && (o ? s(o) : d = !0);
1514
1556
  },
1515
1557
  onVideoStateChange: (g, l) => {
1516
- var v, P;
1517
- (P = (v = n.callbacks).onVideoStateChange) == null || P.call(v, g), $n(
1558
+ var v, L;
1559
+ (L = (v = n.callbacks).onVideoStateChange) == null || L.call(v, g), Vn(
1518
1560
  g,
1519
1561
  e,
1520
1562
  l,
1521
1563
  i,
1522
- s.streamType
1564
+ o.streamType
1523
1565
  );
1524
1566
  },
1525
1567
  onAgentActivityStateChange: (g) => {
1526
1568
  var l, v;
1527
- (v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? ($e.update(), c = (P) => {
1528
- et(
1569
+ (v = (l = n.callbacks).onAgentActivityStateChange) == null || v.call(l, g), g === W.Talking ? (je.update(), c = (L) => {
1570
+ st(
1529
1571
  T.Start,
1530
1572
  e,
1531
1573
  i,
1532
- s.streamType,
1533
- P
1574
+ o.streamType,
1575
+ L
1534
1576
  ), c = null;
1535
- }, h || c({ latency: oe.get(!0) })) : ($e.reset(), c = null, et(
1577
+ }, h || c({ latency: oe.get(!0) })) : (je.reset(), c = null, st(
1536
1578
  T.Stop,
1537
1579
  e,
1538
1580
  i,
1539
- s.streamType
1581
+ o.streamType
1540
1582
  ));
1541
1583
  },
1542
1584
  onFirstAudioDetected: (g) => {
1543
1585
  c == null || c(g);
1544
1586
  },
1545
1587
  onStreamReady: () => {
1546
- const g = Qe.get(!0);
1588
+ const g = nt.get(!0);
1547
1589
  i.track("agent-chat", { event: "ready", latency: g });
1548
1590
  }
1549
1591
  }
1550
1592
  },
1551
1593
  r
1552
- ), d && o(s);
1553
- } catch (s) {
1554
- a(s);
1594
+ ), d && s(o);
1595
+ } catch (o) {
1596
+ a(o);
1555
1597
  }
1556
1598
  });
1557
1599
  }
1558
- async function Bn(e, n, i, r, o) {
1600
+ async function On(e, n, i, r, s) {
1559
1601
  var h, g, l, v;
1560
1602
  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();
1603
+ if (Ne(e.presenter.type)) {
1604
+ const L = await ct(e, n, r), K = `${Bn}_${L.sessionId}`, B = (/* @__PURE__ */ new Date()).toISOString();
1563
1605
  return { chatResult: {
1564
1606
  chatMode: O.Functional,
1565
1607
  chat: {
1566
- id: z,
1608
+ id: K,
1567
1609
  agent_id: e.id,
1568
1610
  owner_id: e.owner_id ?? "",
1569
- created: x,
1570
- modified: x,
1571
- agent_id__created_at: x,
1572
- agent_id__modified_at: x,
1611
+ created: B,
1612
+ modified: B,
1613
+ agent_id__created_at: B,
1614
+ agent_id__modified_at: B,
1573
1615
  chat_mode: O.Functional,
1574
1616
  messages: []
1575
1617
  }
1576
- }, streamingManager: P };
1618
+ }, streamingManager: L };
1577
1619
  } else {
1578
- const P = new AbortController(), z = P.signal;
1579
- let x;
1620
+ const L = new AbortController(), K = L.signal;
1621
+ let B;
1580
1622
  try {
1581
- const F = ct(
1623
+ const F = ht(
1582
1624
  e,
1583
1625
  i,
1584
1626
  r,
1585
1627
  n.mode,
1586
1628
  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 };
1629
+ s
1630
+ ), M = ct(e, n, r, K).then((Q) => (B = Q, Q)), [k, Y] = await Promise.all([F, M]);
1631
+ return { chatResult: k, streamingManager: Y };
1590
1632
  } catch (F) {
1591
- throw P.abort(), x && await x.disconnect().catch(() => {
1633
+ throw L.abort(), B && await B.disconnect().catch(() => {
1592
1634
  }), F;
1593
1635
  }
1594
1636
  }
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 };
1637
+ }, { chatResult: o, streamingManager: d } = await a(), { chat: t, chatMode: c } = o;
1638
+ 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
1639
  }
1598
- async function Kn(e, n) {
1640
+ async function qn(e, n) {
1599
1641
  var H, re, de, ue;
1600
1642
  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 = {
1643
+ const s = n.mixpanelKey || zt, a = n.wsURL || Nt, o = n.baseURL || Ee, d = n.mode || O.Functional, t = {
1602
1644
  messages: [],
1603
1645
  chatMode: d
1604
- }, c = qt({
1605
- token: o,
1646
+ }, c = nn({
1647
+ token: s,
1606
1648
  agentId: e,
1607
1649
  isEnabled: n.enableAnalitics,
1608
1650
  externalId: n.externalId,
1609
1651
  mixpanelAdditionalProperties: n.mixpanelAdditionalProperties
1610
1652
  }), h = Date.now();
1611
- qe(() => {
1653
+ tt(() => {
1612
1654
  c.track("agent-sdk", { event: "init" }, h);
1613
1655
  });
1614
- const g = Vt(n.auth, s, n.callbacks.onError, n.externalId), l = await g.getById(e);
1656
+ const g = Xt(n.auth, o, n.callbacks.onError, n.externalId), l = await g.getById(e);
1615
1657
  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, () => {
1658
+ const v = Ne(l.presenter.type);
1659
+ c.enrich(Gt(l));
1660
+ const { onMessage: L, clearQueue: K } = _n(c, t, n, l, () => {
1619
1661
  var f, C, R;
1620
- (f = t.socketManager) == null || f.disconnect(), (R = (C = n.callbacks).onConnectionStateChange) == null || R.call(C, L.Disconnected);
1662
+ (f = t.socketManager) == null || f.disconnect(), (R = (C = n.callbacks).onConnectionStateChange) == null || R.call(C, P.Disconnected);
1621
1663
  });
1622
- t.messages = Xt(n.initialMessages), (de = (re = n.callbacks).onNewMessage) == null || de.call(re, [...t.messages], "answer");
1623
- const x = (f) => {
1664
+ t.messages = an(n.initialMessages), (de = (re = n.callbacks).onNewMessage) == null || de.call(re, [...t.messages], "answer");
1665
+ const B = (f) => {
1624
1666
  r = f;
1625
1667
  }, 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;
1668
+ var R, _, D, b, J;
1669
+ if (!((R = t.streamingManager) != null && R.interruptAvailable) || !((_ = t.streamingManager) != null && _.isInterruptible)) return;
1628
1670
  const C = t.messages[t.messages.length - 1];
1629
1671
  c.track("agent-video-interrupt", {
1630
1672
  type: f || "click",
1631
- video_duration_to_interrupt: $e.get(!0),
1673
+ video_duration_to_interrupt: je.get(!0),
1632
1674
  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));
1675
+ }), 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
1676
  }, M = /* @__PURE__ */ new Map();
1635
- function E(f) {
1677
+ function k(f) {
1636
1678
  return async (C) => {
1637
1679
  const R = M.get(f);
1638
1680
  if (!R)
1639
1681
  throw new Error(`No handler registered for client tool: ${f}`);
1640
1682
  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}`);
1683
+ const _ = JSON.parse(C.payload);
1684
+ return await R(_);
1685
+ } catch (_) {
1686
+ throw new Error(`Client tool "${f}" failed: ${_.message}`);
1645
1687
  }
1646
1688
  };
1647
1689
  }
1648
1690
  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));
1691
+ var f, C, R, _;
1692
+ for (const [D] of M)
1693
+ (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
1694
  }
1653
1695
  function Q(f, C) {
1654
- var A, I;
1696
+ var _, D;
1655
1697
  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)));
1698
+ M.set(f, C), R && ((D = (_ = t.streamingManager) == null ? void 0 : _.registerRpcMethod) == null || D.call(_, f, k(f)));
1657
1699
  }
1658
- function J(f) {
1700
+ function U(f) {
1659
1701
  var C, R;
1660
1702
  M.delete(f), (R = (C = t.streamingManager) == null ? void 0 : C.unregisterRpcMethod) == null || R.call(C, f);
1661
1703
  }
1662
1704
  const te = Date.now();
1663
- qe(() => {
1664
- c.track("agent-sdk", { event: "loaded", ...Jt(l) }, te);
1705
+ tt(() => {
1706
+ c.track("agent-sdk", { event: "loaded", ...Yt(l) }, te);
1665
1707
  });
1666
1708
  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(
1709
+ var J, w, y, E, $, G, he;
1710
+ (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"));
1711
+ const C = d === O.DirectPlayback || v ? Promise.resolve(void 0) : kn(
1670
1712
  n.auth,
1671
1713
  a,
1672
- { onMessage: P, onError: n.callbacks.onError },
1714
+ { onMessage: L, onError: n.callbacks.onError },
1673
1715
  n.externalId
1674
- ), R = Pe(
1675
- () => Bn(
1716
+ ), R = xe(
1717
+ () => On(
1676
1718
  l,
1677
1719
  {
1678
1720
  ...n,
1679
1721
  mode: d,
1680
1722
  callbacks: {
1681
1723
  ...n.callbacks,
1682
- onVideoIdChange: x,
1683
- onMessage: P,
1724
+ onVideoIdChange: B,
1725
+ onMessage: L,
1684
1726
  onInterruptDetected: F
1685
1727
  }
1686
1728
  },
@@ -1690,28 +1732,28 @@ async function Kn(e, n) {
1690
1732
  ),
1691
1733
  {
1692
1734
  limit: 3,
1693
- timeout: bt,
1735
+ timeout: Ft,
1694
1736
  timeoutErrorMessage: "Timeout initializing the stream",
1695
1737
  shouldRetryFn: (Z) => (Z == null ? void 0 : Z.message) !== "Could not connect" && Z.status !== 429 && (Z == null ? void 0 : Z.message) !== "InsufficientCreditsError",
1696
1738
  delayMs: 1e3
1697
1739
  }
1698
1740
  ).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({
1741
+ var z, ee;
1742
+ throw N(O.Maintenance), (ee = (z = n.callbacks).onConnectionStateChange) == null || ee.call(z, P.Fail), Z;
1743
+ }), [_, { streamingManager: D, chat: b }] = await Promise.all([C, R]);
1744
+ 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
1745
  chatId: b == null ? void 0 : b.id,
1704
- streamId: I == null ? void 0 : I.streamId,
1746
+ streamId: D == null ? void 0 : D.streamId,
1705
1747
  mode: t.chatMode
1706
- }), K((b == null ? void 0 : b.chat_mode) ?? d);
1748
+ }), N((b == null ? void 0 : b.chat_mode) ?? d);
1707
1749
  }
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);
1750
+ async function x() {
1751
+ var f, C, R, _;
1752
+ (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
1753
  }
1712
- async function K(f) {
1754
+ async function N(f) {
1713
1755
  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));
1756
+ 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
1757
  }
1716
1758
  return {
1717
1759
  agent: l,
@@ -1725,7 +1767,7 @@ async function Kn(e, n) {
1725
1767
  },
1726
1768
  starterMessages: ((ue = l.knowledge) == null ? void 0 : ue.starter_message) || [],
1727
1769
  getSTTToken: () => g.getSTTToken(l.id),
1728
- changeMode: K,
1770
+ changeMode: N,
1729
1771
  enrichAnalytics: c.enrich,
1730
1772
  async connect() {
1731
1773
  await ne(!0), c.track("agent-chat", {
@@ -1742,17 +1784,17 @@ async function Kn(e, n) {
1742
1784
  mode: t.chatMode
1743
1785
  });
1744
1786
  } catch {
1745
- await $(), await ne(!1);
1787
+ await x(), await ne(!1);
1746
1788
  }
1747
1789
  return;
1748
1790
  }
1749
- await $(), await ne(!1), c.track("agent-chat", {
1791
+ await x(), await ne(!1), c.track("agent-chat", {
1750
1792
  event: "reconnect",
1751
1793
  mode: t.chatMode
1752
1794
  });
1753
1795
  },
1754
1796
  async disconnect() {
1755
- await $(), c.track("agent-chat", {
1797
+ await x(), c.track("agent-chat", {
1756
1798
  event: "disconnect",
1757
1799
  mode: t.chatMode
1758
1800
  });
@@ -1780,9 +1822,9 @@ async function Kn(e, n) {
1780
1822
  return t.streamingManager.unpublishCameraStream();
1781
1823
  },
1782
1824
  async chat(f) {
1783
- var I, b, U, w, y;
1825
+ var D, b, J, w, y;
1784
1826
  const C = () => {
1785
- if (at(d))
1827
+ if (ft(d))
1786
1828
  throw new me(`${d} is enabled, chat is disabled`);
1787
1829
  if (f.length >= 800)
1788
1830
  throw new me("Message cannot be more than 800 characters");
@@ -1797,9 +1839,9 @@ async function Kn(e, n) {
1797
1839
  throw new me("Chat is not initialized");
1798
1840
  }
1799
1841
  }, R = async () => {
1800
- var k, B;
1842
+ var E, $;
1801
1843
  if (!t.chat) {
1802
- const G = await ct(
1844
+ const G = await ht(
1803
1845
  l,
1804
1846
  g,
1805
1847
  c,
@@ -1807,95 +1849,97 @@ async function Kn(e, n) {
1807
1849
  n.persistentChat
1808
1850
  );
1809
1851
  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);
1852
+ throw new Mt(t.chatMode, !!n.persistentChat);
1853
+ t.chat = G.chat, ($ = (E = n.callbacks).onNewChat) == null || $.call(E, t.chat.id);
1812
1854
  }
1813
1855
  return t.chat.id;
1814
- }, A = async (k, B) => {
1856
+ }, _ = async (E, $) => {
1815
1857
  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({});
1858
+ return xe(v && !G ? async () => {
1859
+ var z, ee;
1860
+ return await ((ee = (z = t.streamingManager) == null ? void 0 : z.sendTextMessage) == null ? void 0 : ee.call(z, f)), Promise.resolve({});
1819
1861
  } : async () => {
1820
- var N, ee;
1862
+ var z, ee;
1821
1863
  return g.chat(
1822
1864
  l.id,
1823
- B,
1865
+ $,
1824
1866
  {
1825
1867
  chatMode: t.chatMode,
1826
- streamId: (N = t.streamingManager) == null ? void 0 : N.streamId,
1868
+ streamId: (z = t.streamingManager) == null ? void 0 : z.streamId,
1827
1869
  sessionId: (ee = t.streamingManager) == null ? void 0 : ee.sessionId,
1828
- messages: k.map(({ matches: De, ...le }) => le)
1870
+ messages: E.map(({ matches: De, ...le }) => le)
1829
1871
  },
1830
1872
  {
1831
- ...st(t.chatMode),
1873
+ ...gt(t.chatMode),
1832
1874
  skipErrorHandler: !0
1833
1875
  }
1834
1876
  );
1835
1877
  }, {
1836
1878
  limit: 2,
1837
- shouldRetryFn: (N) => {
1879
+ shouldRetryFn: (z) => {
1838
1880
  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;
1881
+ const ee = (le = z == null ? void 0 : z.message) == null ? void 0 : le.includes("missing or invalid session_id");
1882
+ 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
1883
  },
1842
1884
  onRetry: async () => {
1843
- await $(), await ne(!1);
1885
+ await x(), await ne(!1);
1844
1886
  }
1845
1887
  });
1846
1888
  };
1847
1889
  try {
1848
- z(), C(), t.messages.push({
1890
+ K(), C(), t.messages.push({
1849
1891
  id: ge(),
1850
1892
  role: "user",
1851
1893
  content: f,
1894
+ parts: Te(f),
1852
1895
  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);
1896
+ }), (b = (D = n.callbacks).onNewMessage) == null || b.call(D, [...t.messages], "user");
1897
+ const E = await R(), $ = await _([...t.messages], E);
1855
1898
  return t.messages.push({
1856
1899
  id: ge(),
1857
1900
  role: "assistant",
1858
- content: B.result || "",
1901
+ content: $.result || "",
1902
+ parts: Te($.result || ""),
1859
1903
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
1860
- context: B.context,
1861
- matches: B.matches
1904
+ context: $.context,
1905
+ matches: $.matches
1862
1906
  }), c.track("agent-message-send", {
1863
1907
  event: "success",
1864
1908
  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", {
1909
+ }), $.result && ((w = (J = n.callbacks).onNewMessage) == null || w.call(J, [...t.messages], "answer"), c.track("agent-message-received", {
1866
1910
  latency: oe.get(!0),
1867
1911
  messages: t.messages.length
1868
- })), B;
1869
- } catch (k) {
1912
+ })), $;
1913
+ } catch (E) {
1870
1914
  throw ((y = t.messages[t.messages.length - 1]) == null ? void 0 : y.role) === "assistant" && t.messages.pop(), c.track("agent-message-send", {
1871
1915
  event: "error",
1872
1916
  messages: t.messages.length
1873
- }), k;
1917
+ }), E;
1874
1918
  }
1875
1919
  },
1876
1920
  rate(f, C, R) {
1877
- var b, U, w, y;
1878
- const A = t.messages.find((k) => k.id === f);
1921
+ var b, J, w, y;
1922
+ const _ = t.messages.find((E) => E.id === f);
1879
1923
  if (t.chat) {
1880
- if (!A)
1924
+ if (!_)
1881
1925
  throw new Error("Message not found");
1882
1926
  } 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])) ?? [];
1927
+ const D = ((b = _.matches) == null ? void 0 : b.map((E) => [E.document_id, E.id])) ?? [];
1884
1928
  return c.track("agent-rate", {
1885
1929
  event: R ? "update" : "create",
1886
1930
  thumb: C === 1 ? "up" : "down",
1887
- knowledge_id: ((U = l.knowledge) == null ? void 0 : U.id) ?? "",
1888
- matches: I,
1931
+ knowledge_id: ((J = l.knowledge) == null ? void 0 : J.id) ?? "",
1932
+ matches: D,
1889
1933
  score: C
1890
1934
  }), R ? g.updateRating(l.id, t.chat.id, R, {
1891
1935
  knowledge_id: ((w = l.knowledge) == null ? void 0 : w.id) ?? "",
1892
1936
  message_id: f,
1893
- matches: I,
1937
+ matches: D,
1894
1938
  score: C
1895
1939
  }) : g.createRating(l.id, t.chat.id, {
1896
1940
  knowledge_id: ((y = l.knowledge) == null ? void 0 : y.id) ?? "",
1897
1941
  message_id: f,
1898
- matches: I,
1942
+ matches: D,
1899
1943
  score: C
1900
1944
  });
1901
1945
  },
@@ -1905,7 +1949,7 @@ async function Kn(e, n) {
1905
1949
  return c.track("agent-rate-delete", { type: "text" }), g.deleteRating(l.id, t.chat.id, f);
1906
1950
  },
1907
1951
  async speak(f) {
1908
- var I, b, U;
1952
+ var D, b, J;
1909
1953
  function C() {
1910
1954
  if (typeof f == "string") {
1911
1955
  if (!l.presenter.voice)
@@ -1934,8 +1978,9 @@ async function Kn(e, n) {
1934
1978
  id: ge(),
1935
1979
  role: "assistant",
1936
1980
  content: R.input,
1981
+ parts: Te(R.input),
1937
1982
  created_at: (/* @__PURE__ */ new Date()).toISOString()
1938
- }), (b = (I = n.callbacks).onNewMessage) == null || b.call(I, [...t.messages], "answer")), Ft(t.chatMode))
1983
+ }), (b = (D = n.callbacks).onNewMessage) == null || b.call(D, [...t.messages], "answer")), Ot(t.chatMode))
1939
1984
  return {
1940
1985
  duration: 0,
1941
1986
  video_id: "",
@@ -1945,38 +1990,39 @@ async function Kn(e, n) {
1945
1990
  throw new Error("Please connect to the agent first");
1946
1991
  return t.streamingManager.speak({
1947
1992
  script: R,
1948
- metadata: { chat_id: (U = t.chat) == null ? void 0 : U.id, agent_id: l.id }
1993
+ metadata: { chat_id: (J = t.chat) == null ? void 0 : J.id, agent_id: l.id }
1949
1994
  });
1950
1995
  },
1951
1996
  interrupt: F,
1952
1997
  registerClientTool: Q,
1953
- unregisterClientTool: J
1998
+ unregisterClientTool: U
1954
1999
  };
1955
2000
  }
1956
2001
  export {
1957
2002
  W as AgentActivityState,
1958
- kt as AgentStatus,
1959
- vt as ChatCreationFailed,
2003
+ bt as AgentStatus,
2004
+ Mt as ChatCreationFailed,
1960
2005
  O as ChatMode,
1961
- Ct as ChatModeDowngraded,
2006
+ It as ChatModeDowngraded,
1962
2007
  X as ChatProgress,
1963
- L as ConnectionState,
2008
+ P as ConnectionState,
1964
2009
  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,
2010
+ $t as DocumentType,
2011
+ xt as KnowledgeType,
2012
+ At as PlanGroup,
2013
+ jt as Providers,
2014
+ Lt as RateState,
2015
+ I as StreamEvents,
1971
2016
  se as StreamType,
1972
2017
  T as StreamingState,
1973
- Mt as Subject,
1974
- Be as TransportProvider,
1975
- Rt as UserPlan,
2018
+ Pt as Subject,
2019
+ Ke as TransportProvider,
2020
+ _t as UserPlan,
1976
2021
  me as ValidationError,
1977
- nt as VideoType,
1978
- _t as VoiceAccess,
1979
- St as WsError,
1980
- Kn as createAgentManager,
1981
- zn as mapVideoType
2022
+ dt as VideoType,
2023
+ Bt as VoiceAccess,
2024
+ Dt as WsError,
2025
+ qn as createAgentManager,
2026
+ Hn as mapVideoType,
2027
+ Wt as parseMessageParts
1982
2028
  };